linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-unionfs@vger.kernel.org
Cc: Guillem Jover <guillem@debian.org>,
	Raphael Hertzog <hertzog@debian.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	<stable@vger.kernel.org>
Subject: [PATCH 1/3] ovl: check fs features
Date: Tue, 25 Oct 2016 09:34:45 +0200	[thread overview]
Message-ID: <1477380887-21333-2-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1477380887-21333-1-git-send-email-mszeredi@redhat.com>

To allow adding new, backward incompatible features to overlayfs, we need a
way to store the list of features in the overlay.  This is done via
"trusted.overlay.features" xattr on the root of the upper layer (or one of
the lower layers, that previously acted as an upper layer).  It's a comma
separated list of case sensitive strings.

If an overlay has an unknown feature, mount shall return an error.  So
mechanism should only be used for backward incompatible features.

This patch doesn't add any features.  If the "trusted.overlay.features"
xattr contains a non-empty list, then return EINVAL error for the mount.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: <stable@vger.kernel.org>
---
 Documentation/filesystems/overlayfs.txt | 12 ++++++++++
 fs/overlayfs/overlayfs.h                |  1 +
 fs/overlayfs/super.c                    | 41 +++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/Documentation/filesystems/overlayfs.txt b/Documentation/filesystems/overlayfs.txt
index 7aeb8e8d80cf..5108425157ac 100644
--- a/Documentation/filesystems/overlayfs.txt
+++ b/Documentation/filesystems/overlayfs.txt
@@ -175,6 +175,18 @@ The specified lower directories will be stacked beginning from the
 rightmost one and going left.  In the above example lower1 will be the
 top, lower2 the middle and lower3 the bottom layer.
 
+Filesystem features
+-------------------
+
+Features are enabled via "trusted.overlay.features" xattr on the root of the
+upper layer.  E.g. the following command can be used to enable features "foo"
+and "bar" on the overlay:
+
+  setfattr -n "trusted.overlay.features" -v "foo,bar" /upper
+  mount -t overlay overlay -olowerdir=/lower,upperdir=/upper,\
+workdir=/work /merged
+
+If an overlay has an unknown feature, mount shall return an error.
 
 Non-standard behavior
 ---------------------
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index f6e4d3539a25..d61d5b9d0d91 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -19,6 +19,7 @@ enum ovl_path_type {
 
 #define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
 #define OVL_XATTR_OPAQUE OVL_XATTR_PREFIX "opaque"
+#define OVL_XATTR_FEATURES OVL_XATTR_PREFIX "features"
 
 #define OVL_ISUPPER_MASK 1UL
 
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 30263a541fd5..d6dc8d905d00 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -397,6 +397,39 @@ static struct dentry *ovl_workdir_create(struct vfsmount *mnt,
 	goto out_unlock;
 }
 
+static int ovl_check_features(struct dentry *root)
+{
+	int res;
+	char *buf, *tmp, *p;
+
+	res = vfs_getxattr(root, OVL_XATTR_FEATURES, NULL, 0);
+	if (res <= 0) {
+		if (res == -EOPNOTSUPP || res == -ENODATA)
+			res = 0;
+		return res;
+	}
+
+	buf = kmalloc(res + 1, GFP_TEMPORARY);
+	if (!buf)
+		return -ENOMEM;
+
+	res = vfs_getxattr(root, OVL_XATTR_FEATURES, buf, res);
+	if (res <= 0)
+		goto out_free;
+
+	buf[res] = '\0';
+	res = 0;
+	tmp = buf;
+	while ((p = strsep(&tmp, ",")) != NULL) {
+		res = -EINVAL;
+		pr_err("overlayfs: feature '%s' not supported\n", p);
+	}
+out_free:
+	kfree(buf);
+
+	return res;
+}
+
 static void ovl_unescape(char *s)
 {
 	char *d = s;
@@ -471,6 +504,10 @@ static int ovl_lower_dir(const char *name, struct path *path, long *namelen,
 	if (err)
 		goto out;
 
+	err = ovl_check_features(path->dentry);
+	if (err)
+		goto out_put;
+
 	err = vfs_statfs(path, &statfs);
 	if (err) {
 		pr_err("overlayfs: statfs failed on '%s'\n", name);
@@ -693,6 +730,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 			goto out_put_upperpath;
 		}
 
+		err = ovl_check_features(upperpath.dentry);
+		if (err)
+			goto out_put_upperpath;
+
 		err = ovl_mount_dir(ufs->config.workdir, &workpath);
 		if (err)
 			goto out_put_upperpath;
-- 
2.5.5


  reply	other threads:[~2016-10-25  7:34 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-25  7:34 [PATCH 0/3] overlayfs: allow moving directory trees Miklos Szeredi
2016-10-25  7:34 ` Miklos Szeredi [this message]
2016-10-25 11:24   ` [PATCH 1/3] ovl: check fs features Amir Goldstein
2016-11-05 20:40     ` Amir Goldstein
2016-10-25  7:34 ` [PATCH 2/3] vfs: export vfs_path_lookup() Miklos Szeredi
2016-10-25  7:34 ` [PATCH 3/3] ovl: redirect on rename-dir Miklos Szeredi
2016-10-25 11:57   ` Raphael Hertzog
2016-10-26 11:12     ` Miklos Szeredi
2016-10-28 12:56       ` Raphael Hertzog
2016-10-28 12:59         ` Miklos Szeredi
2016-11-06 19:14       ` Konstantin Khlebnikov
2016-11-07  8:07         ` Miklos Szeredi
2016-11-07  9:58           ` Konstantin Khlebnikov
2016-11-07 10:04             ` Miklos Szeredi
2016-11-07 10:08               ` Konstantin Khlebnikov
2016-11-07 13:38                 ` Amir Goldstein
2016-11-10 22:56                   ` Amir Goldstein
2016-11-11  9:46                     ` Konstantin Khlebnikov
2016-11-11 10:06                       ` Miklos Szeredi
2016-11-11 12:42                         ` Amir Goldstein
2016-11-13  9:11                           ` Amir Goldstein
2016-11-07 11:03         ` Raphael Hertzog
2016-11-07 11:31           ` Konstantin Khlebnikov
2016-11-07 13:42             ` Raphael Hertzog
2016-11-10 22:39               ` Miklos Szeredi
2016-11-11  9:41                 ` Konstantin Khlebnikov
2016-11-13 10:00                 ` Amir Goldstein
2016-11-14 16:25                   ` Amir Goldstein
2016-11-16 22:00                     ` Miklos Szeredi
2016-11-18 15:37                       ` Amir Goldstein
2016-11-20 11:39                         ` Amir Goldstein
2016-11-21  9:54                         ` Miklos Szeredi
2016-11-21 10:13                           ` Amir Goldstein
2016-11-21 10:16                             ` Miklos Szeredi
2016-11-22 13:42                               ` Amir Goldstein
2016-10-25 12:49   ` Amir Goldstein
2016-10-26 11:26     ` Miklos Szeredi
2016-10-26 12:11       ` Amir Goldstein
2016-10-26 12:51         ` Miklos Szeredi
2016-10-26 19:56       ` Amir Goldstein
2016-10-30 22:00       ` Amir Goldstein
2016-10-31 14:59         ` Miklos Szeredi
2016-10-31 15:02           ` Amir Goldstein
2016-10-28 16:15   ` Al Viro
2016-11-03 15:50     ` Miklos Szeredi
2016-11-04  9:29       ` Amir Goldstein
2016-11-04 13:48         ` Miklos Szeredi
2016-10-25 20:25 ` [PATCH 0/3] overlayfs: allow moving directory trees Amir Goldstein
2016-10-26  9:37   ` Amir Goldstein
2016-10-26  9:34 ` [PATCH] ovl: check for emptiness of redirect dir Amir Goldstein
2016-10-26 10:45   ` Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1477380887-21333-2-git-send-email-mszeredi@redhat.com \
    --to=mszeredi@redhat.com \
    --cc=guillem@debian.org \
    --cc=hertzog@debian.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).