Skip to contentSkip to conversation

vfs: verify param type in vfs_parse_sb_flag()

PATCH In review Miklos Szeredi 4 participants 21 messages Jun 19, 2019 – Sep 6, 2019

Subsystems (11)
x86 VFS Driver core cgroup +7 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/13 vfs: verify param type in vfs_parse_sb_flag()

vfs_parse_sb_flag() accepted any kind of param with a matching key, not just a flag. This is wrong, only allow flag type and return -EINVAL otherwise.

---
 fs/fs_context.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
fs/fs_context.c +15 -16
index 103643c68e3f..e56310fd8c75 100644
@@ -81,30 +81,29 @@ static const char *const forbidden_sb_flag[] = {
 /*
  * Check for a common mount option that manipulates s_flags.
  */
-static int vfs_parse_sb_flag(struct fs_context *fc, const char *key)
+static int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
 {
-	unsigned int token;
+	const char *key = param->key;
+	unsigned int set, clear;
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(forbidden_sb_flag); i++)
 		if (strcmp(key, forbidden_sb_flag[i]) == 0)
 			return -EINVAL;
 
-	token = lookup_constant(common_set_sb_flag, key, 0);
-	if (token) {
-		fc->sb_flags |= token;
-		fc->sb_flags_mask |= token;
-		return 0;
-	}
+	set = lookup_constant(common_set_sb_flag, key, 0);
+	clear = lookup_constant(common_clear_sb_flag, key, 0);
+	if (!set && !clear)
+		return -ENOPARAM;
 
-	token = lookup_constant(common_clear_sb_flag, key, 0);
-	if (token) {
-		fc->sb_flags &= ~token;
-		fc->sb_flags_mask |= token;
-		return 0;
-	}
+	if (param->type != fs_value_is_flag)
+		return invalf(fc, "%s: Unexpected value for '%s'",
+			      fc->fs_type->name, param->key);
 
-	return -ENOPARAM;
+	fc->sb_flags |= set;
+	fc->sb_flags &= ~clear;
+	fc->sb_flags_mask |= set | clear;
+	return 0;
 }
 
 /**
@@ -130,7 +129,7 @@ int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param)
 	if (!param->key)
 		return invalf(fc, "Unnamed parameter\n");
 
-	ret = vfs_parse_sb_flag(fc, param->key);
+	ret = vfs_parse_sb_flag(fc, param);
 	if (ret != -ENOPARAM)
 		return ret;
 
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/13 vfs: move vfs_parse_sb_flag() calls into filesystems

Move parsing "standard" options into filesystems' ->parse_param(). This patch doesn't change behavior.

This is in preparation for allowing filesystems to reject options that they don't support.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  6 +++++-
 fs/afs/super.c                         |  6 +++++-
 fs/fs_context.c                        | 12 +++++++-----
 fs/fuse/control.c                      |  1 +
 fs/hugetlbfs/inode.c                   |  6 +++++-
 fs/proc/root.c                         |  6 +++++-
 fs/sysfs/mount.c                       |  1 +
 include/linux/fs_context.h             |  1 +
 ipc/mqueue.c                           |  1 +
 kernel/cgroup/cgroup-v1.c              |  6 +++++-
 kernel/cgroup/cgroup.c                 |  6 +++++-
 kernel/cgroup/cpuset.c                 |  1 +
 12 files changed, 42 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -1
index 2131b8bbaad7..83d3c358f95e 100644
@@ -2051,7 +2051,11 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 {
 	struct rdt_fs_context *ctx = rdt_fc2context(fc);
 	struct fs_parse_result result;
-	int opt;
+	int ret, opt;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	opt = fs_parse(fc, &rdt_fs_parameters, param, &result);
 	if (opt < 0)
fs/afs/super.c +5 -1
index f18911e8d770..7f032d08781b 100644
@@ -321,7 +321,11 @@ static int afs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 {
 	struct fs_parse_result result;
 	struct afs_fs_context *ctx = fc->fs_private;
-	int opt;
+	int ret, opt;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	opt = fs_parse(fc, &afs_fs_parameters, param, &result);
 	if (opt < 0)
fs/fs_context.c +7 -5
index e56310fd8c75..a9f314390b99 100644
@@ -81,7 +81,7 @@ static const char *const forbidden_sb_flag[] = {
 /*
  * Check for a common mount option that manipulates s_flags.
  */
-static int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
+int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
 {
 	const char *key = param->key;
 	unsigned int set, clear;
@@ -105,6 +105,7 @@ static int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
 	fc->sb_flags_mask |= set | clear;
 	return 0;
 }
+EXPORT_SYMBOL(vfs_parse_sb_flag);
 
 /**
  * vfs_parse_fs_param - Add a single parameter to a superblock config
@@ -129,10 +130,6 @@ int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param)
 	if (!param->key)
 		return invalf(fc, "Unnamed parameter\n");
 
-	ret = vfs_parse_sb_flag(fc, param);
-	if (ret != -ENOPARAM)
-		return ret;
-
 	ret = security_fs_context_parse_param(fc, param);
 	if (ret != -ENOPARAM)
 		/* Param belongs to the LSM or is disallowed by the LSM; so
@@ -561,6 +558,11 @@ static int legacy_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct legacy_fs_context *ctx = fc->fs_private;
 	unsigned int size = ctx->data_size;
 	size_t len = 0;
+	int ret;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	if (strcmp(param->key, "source") == 0) {
 		if (param->type != fs_value_is_string)
fs/fuse/control.c +1 -0
index 14ce1e47f980..c35013ed7f65 100644
@@ -351,6 +351,7 @@ static int fuse_ctl_get_tree(struct fs_context *fc)
 
 static const struct fs_context_operations fuse_ctl_context_ops = {
 	.get_tree	= fuse_ctl_get_tree,
+	.parse_param	= vfs_parse_fs_param,
 };
 
 static int fuse_ctl_init_fs_context(struct fs_context *fc)
fs/hugetlbfs/inode.c +5 -1
index 1dcc57189382..89125cc36d0e 100644
@@ -1149,7 +1149,11 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par
 	struct fs_parse_result result;
 	char *rest;
 	unsigned long ps;
-	int opt;
+	int ret, opt;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	opt = fs_parse(fc, &hugetlb_fs_parameters, param, &result);
 	if (opt < 0)
fs/proc/root.c +5 -1
index 8b145e7b9661..6ef1527ad975 100644
@@ -56,7 +56,11 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 {
 	struct proc_fs_context *ctx = fc->fs_private;
 	struct fs_parse_result result;
-	int opt;
+	int ret, opt;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	opt = fs_parse(fc, &proc_fs_parameters, param, &result);
 	if (opt < 0)
fs/sysfs/mount.c +1 -0
index 1b56686ab178..ba576a976e8c 100644
@@ -49,6 +49,7 @@ static void sysfs_fs_context_free(struct fs_context *fc)
 
 static const struct fs_context_operations sysfs_fs_context_ops = {
 	.free		= sysfs_fs_context_free,
+	.parse_param	= vfs_parse_sb_flag,
 	.get_tree	= sysfs_get_tree,
 };
 
include/linux/fs_context.h +1 -0
index d476ff0c10df..39f4d8b0a390 100644
@@ -127,6 +127,7 @@ extern struct fs_context *fs_context_for_submount(struct file_system_type *fs_ty
 						struct dentry *reference);
 
 extern struct fs_context *vfs_dup_fs_context(struct fs_context *fc);
+extern int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param);
 extern int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param);
 extern int vfs_parse_fs_string(struct fs_context *fc, const char *key,
 			       const char *value, size_t v_size);
ipc/mqueue.c +1 -0
index 216cad1ff0d0..557aa887996a 100644
@@ -1577,6 +1577,7 @@ static const struct super_operations mqueue_super_ops = {
 
 static const struct fs_context_operations mqueue_fs_context_ops = {
 	.free		= mqueue_fs_context_free,
+	.parse_param	= vfs_parse_sb_flag,
 	.get_tree	= mqueue_get_tree,
 };
 
kernel/cgroup/cgroup-v1.c +5 -1
index 88006be40ea3..f960e6149311 100644
@@ -927,7 +927,11 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
 	struct cgroup_subsys *ss;
 	struct fs_parse_result result;
-	int opt, i;
+	int ret, opt, i;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	opt = fs_parse(fc, &cgroup1_fs_parameters, param, &result);
 	if (opt == -ENOPARAM) {
kernel/cgroup/cgroup.c +5 -1
index bf9dbffd46b1..93890285b510 100644
@@ -1834,7 +1834,11 @@ static int cgroup2_parse_param(struct fs_context *fc, struct fs_parameter *param
 {
 	struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
 	struct fs_parse_result result;
-	int opt;
+	int ret, opt;
+
+	ret = vfs_parse_sb_flag(fc, param);
+	if (ret != -ENOPARAM)
+		return ret;
 
 	opt = fs_parse(fc, &cgroup2_fs_parameters, param, &result);
 	if (opt < 0)
kernel/cgroup/cpuset.c +1 -0
index 515525ff1cfd..025f6c6083a3 100644
@@ -394,6 +394,7 @@ static int cpuset_get_tree(struct fs_context *fc)
 }
 
 static const struct fs_context_operations cpuset_fs_context_ops = {
+	.parse_param	= vfs_parse_sb_flag,
 	.get_tree	= cpuset_get_tree,
 };
 
Signature · 1 line
2.21.0
#2 lore raw

PATCH 3/13 vfs: don't parse forbidden flags

In reply to Miklos Szeredi

Impossible to keep this blacklist properly synced with what mount(8) parses and what it doesn't. E.g. it has various forms of "*atime" options, but not "atime"...

Other than being impossible to maintain, it also makes little sense. So just get rid of it.

---
 fs/fs_context.c | 28 ----------------------------
 1 file changed, 28 deletions(-)
fs/fs_context.c +0 -28
index a9f314390b99..cbf89117a507 100644
@@ -55,29 +55,6 @@ static const struct constant_table common_clear_sb_flag[] = {
 	{ "silent",	SB_SILENT },
 };
 
-static const char *const forbidden_sb_flag[] = {
-	"bind",
-	"dev",
-	"exec",
-	"move",
-	"noatime",
-	"nodev",
-	"nodiratime",
-	"noexec",
-	"norelatime",
-	"nostrictatime",
-	"nosuid",
-	"private",
-	"rec",
-	"relatime",
-	"remount",
-	"shared",
-	"slave",
-	"strictatime",
-	"suid",
-	"unbindable",
-};
-
 /*
  * Check for a common mount option that manipulates s_flags.
  */
@@ -85,11 +62,6 @@ int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
 {
 	const char *key = param->key;
 	unsigned int set, clear;
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(forbidden_sb_flag); i++)
-		if (strcmp(key, forbidden_sb_flag[i]) == 0)
-			return -EINVAL;
 
 	set = lookup_constant(common_set_sb_flag, key, 0);
 	clear = lookup_constant(common_clear_sb_flag, key, 0);
Signature · 1 line
2.21.0
#3 lore raw

PATCH 4/13 vfs: don't parse "posixacl" option

In reply to Miklos Szeredi

Unlike the others, this is _not_ a standard option accepted by mount(8).

In fact SB_POSIXACL is an internal flag, and accepting MS_POSIXACL on the mount(2) interface is possibly a bug.

The only filesystem that apparently wants to handle the "posixacl" option is 9p, but it has special handling of that option besides setting SB_POSIXACL.

---
 fs/fs_context.c | 1 -
 1 file changed, 1 deletion(-)
fs/fs_context.c +0 -1
index cbf89117a507..49636e541293 100644
@@ -42,7 +42,6 @@ static const struct constant_table common_set_sb_flag[] = {
 	{ "dirsync",	SB_DIRSYNC },
 	{ "lazytime",	SB_LAZYTIME },
 	{ "mand",	SB_MANDLOCK },
-	{ "posixacl",	SB_POSIXACL },
 	{ "ro",		SB_RDONLY },
 	{ "sync",	SB_SYNCHRONOUS },
 };
Signature · 1 line
2.21.0
#4 lore raw

PATCH 5/13 vfs: don't parse "silent" option

In reply to Miklos Szeredi

While this is a standard option as documented in mount(8), it is ignored by most filesystems. So reject, unless filesystem explicitly wants to handle it.

The exception is unconverted filesystems, where it is unknown if the filesystem handles this or not.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 fs/fs_context.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fs_context.c +3 -1
index 49636e541293..c26b353aa858 100644
@@ -51,7 +51,6 @@ static const struct constant_table common_clear_sb_flag[] = {
 	{ "nolazytime",	SB_LAZYTIME },
 	{ "nomand",	SB_MANDLOCK },
 	{ "rw",		SB_RDONLY },
-	{ "silent",	SB_SILENT },
 };
 
 /*
@@ -535,6 +534,9 @@ static int legacy_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	if (ret != -ENOPARAM)
 		return ret;
 
+	if (strcmp(param->key, "silent") == 0)
+		fc->sb_flags |= SB_SILENT;
+
 	if (strcmp(param->key, "source") == 0) {
 		if (param->type != fs_value_is_string)
 			return invalf(fc, "VFS: Legacy: Non-string source");
Signature · 1 line
2.21.0
#5 lore raw

Re: [PATCH 05/13] vfs: don't parse "silent" option

Quoted 9 lines · Miklos Szeredi

While this is a standard option as documented in mount(8), it is ignored by most filesystems. So reject, unless filesystem explicitly wants to handle it.

The exception is unconverted filesystems, where it is unknown if the filesystem handles this or not.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

In theory this is fine but every time someone has attempted to change the handling of this in the past autofs has had problems so I'm a bit wary of the change.

It was originally meant to tell the file system to ignore invalid options such as could be found in automount maps that are used with multiple OS implementations that have differences in their options.

That was, IIRC, primarily NFS although NFS should handle most (if not all of those) cases these days.

Nevertheless I'm a bit nervous about it, ;)

Quoted 30 lines
---
 fs/fs_context.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fs_context.c +0 -1
index 49636e541293..c26b353aa858 100644
@@ -51,7 +51,6 @@ static const struct constant_table common_clear_sb_flag[] =
 {
 	{ "nolazytime",	SB_LAZYTIME },
 	{ "nomand",	SB_MANDLOCK },
 	{ "rw",		SB_RDONLY },
-	{ "silent",	SB_SILENT },
 };
 

/*

fs/fs_context.c +3 -0
@@ -535,6 +534,9 @@ static int legacy_parse_param(struct fs_context *fc,
 struct fs_parameter *param)
 	if (ret != -ENOPARAM)
 		return ret;
 
+	if (strcmp(param->key, "silent") == 0)
+		fc->sb_flags |= SB_SILENT;
+
 	if (strcmp(param->key, "source") == 0) {
 		if (param->type != fs_value_is_string)

return invalf(fc, "VFS: Legacy: Non-string source");

#6 lore raw

Re: [PATCH 05/13] vfs: don't parse "silent" option

Quoted 21 lines · Ian Kent
Quoted 9 lines · Miklos Szeredi

While this is a standard option as documented in mount(8), it is ignored by most filesystems. So reject, unless filesystem explicitly wants to handle it.

The exception is unconverted filesystems, where it is unknown if the filesystem handles this or not.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

In theory this is fine but every time someone has attempted to change the handling of this in the past autofs has had problems so I'm a bit wary of the change.

It was originally meant to tell the file system to ignore invalid options such as could be found in automount maps that are used with multiple OS implementations that have differences in their options.

Quoted 4 lines

That was, IIRC, primarily NFS although NFS should handle most (if not all of those) cases these days.

Nevertheless I'm a bit nervous about it, ;)

What I'm saying is that with a new interface the rules need not follow the rules of the old interface, because at the start no one is using the new interface, so no chance of breaking anything.

Yes, there's a chance of making the interface difficult to use, but I don't think this is one of those things.

For one, "silent" should not be needed on the new interface at all, because error messages relating to the setup of the filesystem can be redirected to a log buffer dedicated to the setup instance, effectively enabling silent operation by default.

Thanks.,
Miklos

maintainer
#7 lore raw

Re: [PATCH 05/13] vfs: don't parse "silent" option

Quoted 3 lines · Miklos Szeredi

What I'm saying is that with a new interface the rules need not follow the rules of the old interface, because at the start no one is using the new interface, so no chance of breaking anything.

Er. No. That's not true, since the old interface comes through the new one.

David

#8 lore raw

Re: [PATCH 05/13] vfs: don't parse "silent" option

Quoted 8 lines · David Howells
Quoted 3 lines · Miklos Szeredi

What I'm saying is that with a new interface the rules need not follow the rules of the old interface, because at the start no one is using the new interface, so no chance of breaking anything.

Er. No. That's not true, since the old interface comes through the new one.

No, old interface sets SB_* directly from arg 4 of mount(2) and not via parsing arg 5.

Thanks,
Miklos

#9 lore raw

Re: [PATCH 05/13] vfs: don't parse "silent" option

Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · David Howells

Miklos Szeredi <[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

What I'm saying is that with a new interface the rules need not follow the rules of the old interface, because at the start no one is using the new interface, so no chance of breaking anything.

Er. No. That's not true, since the old interface comes through the new one.

No, old interface sets SB_* directly from arg 4 of mount(2) and not via parsing arg 5.

See also 9p mess up of "posixacl" handling *on the old interface* due to exactly because the internal API doesn't differentiate between options coming from the old interface and ones coming from the new.

So you are right that there's breakage, but it's due to the fact that common code parses anything, and not because it doesn't.

Thanks,
Miklos

#10 lore raw

PATCH 6/13 vfs: new helper: vfs_parse_ro_rw()

In reply to Miklos Szeredi

This just parses the "ro" and "rw" options and sets sb_flags accordingly.

---
 fs/fs_context.c            | 18 ++++++++++++++++++
 include/linux/fs_context.h |  1 +
 2 files changed, 19 insertions(+)
fs/fs_context.c +18 -0
index c26b353aa858..5012ab7650ec 100644
@@ -77,6 +77,24 @@ int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
 }
 EXPORT_SYMBOL(vfs_parse_sb_flag);
 
+int vfs_parse_ro_rw(struct fs_context *fc, struct fs_parameter *param)
+{
+	if (strcmp(param->key, "ro") == 0)
+		fc->sb_flags |= SB_RDONLY;
+	else if (strcmp(param->key, "rw") == 0)
+		fc->sb_flags &= ~SB_RDONLY;
+	else
+		return -ENOPARAM;
+
+	if (param->type != fs_value_is_flag)
+		return invalf(fc, "%s: Unexpected value for '%s'",
+			      fc->fs_type->name, param->key);
+
+	fc->sb_flags_mask |= SB_RDONLY;
+	return 0;
+}
+EXPORT_SYMBOL(vfs_parse_ro_rw);
+
 /**
  * vfs_parse_fs_param - Add a single parameter to a superblock config
  * @fc: The filesystem context to modify
include/linux/fs_context.h +1 -0
index 39f4d8b0a390..bff6796a89ef 100644
@@ -128,6 +128,7 @@ extern struct fs_context *fs_context_for_submount(struct file_system_type *fs_ty
 
 extern struct fs_context *vfs_dup_fs_context(struct fs_context *fc);
 extern int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param);
+extern int vfs_parse_ro_rw(struct fs_context *fc, struct fs_parameter *param);
 extern int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param);
 extern int vfs_parse_fs_string(struct fs_context *fc, const char *key,
 			       const char *value, size_t v_size);
Signature · 1 line
2.21.0
#11 lore raw

PATCH 7/13 proc: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the proc filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 fs/proc/root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/proc/root.c +1 -1
index 6ef1527ad975..70127eaba04d 100644
@@ -58,7 +58,7 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct fs_parse_result result;
 	int ret, opt;
 
-	ret = vfs_parse_sb_flag(fc, param);
+	ret = vfs_parse_ro_rw(fc, param);
 	if (ret != -ENOPARAM)
 		return ret;
 
Signature · 1 line
2.21.0
#12 lore raw

PATCH 8/13 sysfs: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the sysfs filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 fs/sysfs/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/sysfs/mount.c +1 -1
index ba576a976e8c..4797b7952fc5 100644
@@ -49,7 +49,7 @@ static void sysfs_fs_context_free(struct fs_context *fc)
 
 static const struct fs_context_operations sysfs_fs_context_ops = {
 	.free		= sysfs_fs_context_free,
-	.parse_param	= vfs_parse_sb_flag,
+	.parse_param	= vfs_parse_ro_rw,
 	.get_tree	= sysfs_get_tree,
 };
 
Signature · 1 line
2.21.0
#13 lore raw

PATCH 9/13 mqueue: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the mqueue filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 ipc/mqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ipc/mqueue.c +1 -1
index 557aa887996a..1e8567c20d6a 100644
@@ -1577,7 +1577,7 @@ static const struct super_operations mqueue_super_ops = {
 
 static const struct fs_context_operations mqueue_fs_context_ops = {
 	.free		= mqueue_fs_context_free,
-	.parse_param	= vfs_parse_sb_flag,
+	.parse_param	= vfs_parse_ro_rw,
 	.get_tree	= mqueue_get_tree,
 };
 
Signature · 1 line
2.21.0
#14 lore raw

PATCH 10/13 cpuset: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the cpuset filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 kernel/cgroup/cpuset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/cpuset.c +1 -1
index 025f6c6083a3..f6f6b5b44fc3 100644
@@ -394,7 +394,7 @@ static int cpuset_get_tree(struct fs_context *fc)
 }
 
 static const struct fs_context_operations cpuset_fs_context_ops = {
-	.parse_param	= vfs_parse_sb_flag,
+	.parse_param	= vfs_parse_ro_rw,
 	.get_tree	= cpuset_get_tree,
 };
 
Signature · 1 line
2.21.0
#15 lore raw

PATCH 11/13 cgroup: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the cgroup filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 kernel/cgroup/cgroup-v1.c | 2 +-
 kernel/cgroup/cgroup.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cgroup-v1.c +1 -1
index f960e6149311..1f50d59f7f4e 100644
@@ -929,7 +929,7 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct fs_parse_result result;
 	int ret, opt, i;
 
-	ret = vfs_parse_sb_flag(fc, param);
+	ret = vfs_parse_ro_rw(fc, param);
 	if (ret != -ENOPARAM)
 		return ret;
 
kernel/cgroup/cgroup.c +1 -1
index 93890285b510..f2e86b3942b3 100644
@@ -1836,7 +1836,7 @@ static int cgroup2_parse_param(struct fs_context *fc, struct fs_parameter *param
 	struct fs_parse_result result;
 	int ret, opt;
 
-	ret = vfs_parse_sb_flag(fc, param);
+	ret = vfs_parse_ro_rw(fc, param);
 	if (ret != -ENOPARAM)
 		return ret;
 
Signature · 1 line
2.21.0
#16 lore raw

PATCH 12/13 fusectl: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the fusectl filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 fs/fuse/control.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/control.c +1 -1
index c35013ed7f65..f3aab288929f 100644
@@ -351,7 +351,7 @@ static int fuse_ctl_get_tree(struct fs_context *fc)
 
 static const struct fs_context_operations fuse_ctl_context_ops = {
 	.get_tree	= fuse_ctl_get_tree,
-	.parse_param	= vfs_parse_fs_param,
+	.parse_param	= vfs_parse_ro_rw,
 };
 
 static int fuse_ctl_init_fs_context(struct fs_context *fc)
Signature · 1 line
2.21.0
#17 lore raw

PATCH 13/13 resctrl: don't ignore options

In reply to Miklos Szeredi

The options "sync", "async", "dirsync", "lazytime", "nolazytime", "mand" and "nomand" make no sense for the resctrl filesystem. If these options are supplied to fsconfig(FSCONFIG_SET_FLAG), then return -EINVAL instead of silently ignoring the option.

Any implementation, such as mount(8) that needs to parse this option without failing should simply ignore the return value from fsconfig().

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
index 83d3c358f95e..16b110d31457 100644
@@ -2053,7 +2053,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct fs_parse_result result;
 	int ret, opt;
 
-	ret = vfs_parse_sb_flag(fc, param);
+	ret = vfs_parse_ro_rw(fc, param);
 	if (ret != -ENOPARAM)
 		return ret;
 
Signature · 1 line
2.21.0
maintainer
#18 lore raw
In reply to Miklos Szeredi

Hi David,

Ping? Have you had a chance of looking at this series?

Köszi,
Miklos

Quoted 71 lines · Miklos Szeredi

vfs_parse_sb_flag() accepted any kind of param with a matching key, not just a flag. This is wrong, only allow flag type and return -EINVAL otherwise.

---
 fs/fs_context.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
fs/fs_context.c +15 -17
index 103643c68e3f..e56310fd8c75 100644
@@ -81,30 +81,29 @@ static const char *const forbidden_sb_flag[] = {
 /*
  * Check for a common mount option that manipulates s_flags.
  */
-static int vfs_parse_sb_flag(struct fs_context *fc, const char *key)
+static int vfs_parse_sb_flag(struct fs_context *fc, struct fs_parameter *param)
 {
-       unsigned int token;
+       const char *key = param->key;
+       unsigned int set, clear;
        unsigned int i;
 
        for (i = 0; i < ARRAY_SIZE(forbidden_sb_flag); i++)
                if (strcmp(key, forbidden_sb_flag[i]) == 0)
                        return -EINVAL;
 
-       token = lookup_constant(common_set_sb_flag, key, 0);
-       if (token) {
-               fc->sb_flags |= token;
-               fc->sb_flags_mask |= token;
-               return 0;
-       }
+       set = lookup_constant(common_set_sb_flag, key, 0);
+       clear = lookup_constant(common_clear_sb_flag, key, 0);
+       if (!set && !clear)
+               return -ENOPARAM;
 
-       token = lookup_constant(common_clear_sb_flag, key, 0);
-       if (token) {
-               fc->sb_flags &= ~token;
-               fc->sb_flags_mask |= token;
-               return 0;
-       }
+       if (param->type != fs_value_is_flag)
+               return invalf(fc, "%s: Unexpected value for '%s'",
+                             fc->fs_type->name, param->key);
 
-       return -ENOPARAM;
+       fc->sb_flags |= set;
+       fc->sb_flags &= ~clear;
+       fc->sb_flags_mask |= set | clear;
+       return 0;
 }
 
 /**
@@ -130,7 +129,7 @@ int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param)
        if (!param->key)
                return invalf(fc, "Unnamed parameter\n");
 
-       ret = vfs_parse_sb_flag(fc, param->key);
+       ret = vfs_parse_sb_flag(fc, param);
        if (ret != -ENOPARAM)
                return ret;
 
--

2.21.0

maintainer
#19 lore raw
Quoted 1 line · Miklos Szeredi

Ping? Have you had a chance of looking at this series?

Yeah, through due to time pressure, I haven't managed to do much with it.

I don't agree with all your changes, and also I'd like them to wait till after the branch of mount API filesystem conversions that I've given to Al has had a chance to hopefully go in in this merge window, along with whatever changes Al has made to it.

Bocsánat,
David

maintainer
#20 lore raw
Quoted 11 lines · David Howells
Quoted 1 line · Miklos Szeredi

Ping? Have you had a chance of looking at this series?

Yeah, through due to time pressure, I haven't managed to do much with it.

I don't agree with all your changes, and also I'd like them to wait till after the branch of mount API filesystem conversions that I've given to Al has had a chance to hopefully go in in this merge window, along with whatever changes Al has made to it.

Ping?

Thanks,
Miklos