From: Laura Abbott <labbott@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ilya Dryomov <idryomov@gmail.com>,
Al Viro <viro@zeniv.linux.org.uk>,
David Howells <dhowells@redhat.com>,
Jeremi Piotrowski <jeremi.piotrowski@gmail.com>,
Linux FS Devel <linux-fsdevel@vger.kernel.org>,
Phillip Lougher <phillip@squashfs.org.uk>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] vfs: Don't reject unknown parameters
Date: Thu, 12 Dec 2019 15:01:56 -0500 [thread overview]
Message-ID: <cf4c9634-1503-d182-cb12-810fb969bc96@redhat.com> (raw)
In-Reply-To: <CAHk-=wh7Wuk9QCP6oH5Qc1a89_X6H1CHRK_OyB4NLmX7nRYJeA@mail.gmail.com>
On 12/12/19 12:56 PM, Linus Torvalds wrote:
> On Thu, Dec 12, 2019 at 9:47 AM Laura Abbott <labbott@redhat.com> wrote:
>>
>> Good point, I think I missed how that code flow worked for printing
>> out the error. I debated putting in a dummy parse_param but I
>> figured that squashfs wouldn't be the only fs that didn't take
>> arguments (it's in the minority but certainly not the only one).
>
> I think printing out the error part is actually fine - it would act as
> a warning for invalid parameters like this.
>
> So I think a dummy parse_param that prints out a warning is likely the
> right thing to do.
>
> Something like the attached, perhaps? Totally untested.
>
> Linus
>
That doesn't quite work. We can't just unconditionally return success
because we rely on -ENOPARAM being returned to parse the source option
back in vfs_parse_fs_param. I think ramfs may also be broken for the
same reason right now as well from reading the code. We also rely on the
fallback source parsing for file systems that do have ->parse_param.
We could do all this in squashfs but given other file systems that don't
have args will also hit this we could just make it generic. The following
works for me (under commenting and poor name choices notwithstanding)
diff --git a/fs/fs_parser.c b/fs/fs_parser.c
index d1930adce68d..5e45e36d51e7 100644
--- a/fs/fs_parser.c
+++ b/fs/fs_parser.c
@@ -302,6 +302,50 @@ int fs_lookup_param(struct fs_context *fc,
}
EXPORT_SYMBOL(fs_lookup_param);
+enum {
+ NO_OPT_SOURCE,
+};
+
+static const struct fs_parameter_spec no_opt_fs_param_specs[] = {
+ fsparam_string ("source", NO_OPT_SOURCE),
+ {}
+};
+
+const struct fs_parameter_description no_opt_fs_parameters = {
+ .name = "no_opt_fs",
+ .specs = no_opt_fs_param_specs,
+};
+
+int fs_no_opt_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+ struct fs_parse_result result;
+ int opt;
+
+ opt = fs_parse(fc, &no_opt_fs_parameters, param, &result);
+ if (opt < 0) {
+ /* Just log an error for backwards compatibility */
+ errorf(fc, "%s: Unknown parameter '%s'",
+ fc->fs_type->name, param->key);
+ return 0;
+ }
+
+ switch (opt) {
+ case NO_OPT_SOURCE:
+ if (param->type != fs_value_is_string)
+ return invalf(fc, "%s: Non-string source",
+ fc->fs_type->name);
+ if (fc->source)
+ return invalf(fc, "%s: Multiple sources specified",
+ fc->fs_type->name);
+ fc->source = param->string;
+ param->string = NULL;
+ break;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(fs_no_opt_parse_param);
+
#ifdef CONFIG_VALIDATE_FS_PARSER
/**
* validate_constant_table - Validate a constant table
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 0cc4ceec0562..07a9b38f7bf5 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -18,6 +18,7 @@
#include <linux/fs.h>
#include <linux/fs_context.h>
+#include <linux/fs_parser.h>
#include <linux/vfs.h>
#include <linux/slab.h>
#include <linux/mutex.h>
@@ -358,6 +359,7 @@ static int squashfs_reconfigure(struct fs_context *fc)
static const struct fs_context_operations squashfs_context_ops = {
.get_tree = squashfs_get_tree,
.reconfigure = squashfs_reconfigure,
+ .parse_param = fs_no_opt_parse_param,
};
static int squashfs_init_fs_context(struct fs_context *fc)
diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h
index dee140db6240..f67b2afcc491 100644
--- a/include/linux/fs_parser.h
+++ b/include/linux/fs_parser.h
@@ -106,6 +106,8 @@ static inline bool fs_validate_description(const struct fs_parameter_description
{ return true; }
#endif
+extern int fs_no_opt_parse_param(struct fs_context *fc, struct fs_parameter *param);
+
/*
* Parameter type, name, index and flags element constructors. Use as:
*
next prev parent reply other threads:[~2019-12-12 20:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-12 14:50 [PATCH] vfs: Don't reject unknown parameters Laura Abbott
2019-12-12 17:13 ` Ilya Dryomov
2019-12-12 17:47 ` Laura Abbott
2019-12-12 17:56 ` Linus Torvalds
2019-12-12 20:01 ` Laura Abbott [this message]
2019-12-12 21:36 ` Al Viro
2019-12-13 9:15 ` Miklos Szeredi
2019-12-13 9:30 ` Miklos Szeredi
2019-12-17 17:46 ` Al Viro
2019-12-17 17:49 ` David Howells
2019-12-17 18:08 ` 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=cf4c9634-1503-d182-cb12-810fb969bc96@redhat.com \
--to=labbott@redhat.com \
--cc=dhowells@redhat.com \
--cc=idryomov@gmail.com \
--cc=jeremi.piotrowski@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=phillip@squashfs.org.uk \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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).