Skip to contentSkip to conversation

vfs: parse sloppy mount option in correct order

PATCH Superseded Roberto Bergantinos Corpas 5 participants 8 messages Jul 21, 2021 – Jan 27, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: parse sloppy mount option in correct order

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt host#

This patch correct that behaviour so that sloppy takes precedence if specified anywhere on the string

---
 fs/fs_context.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/fs_context.c +5 -1
index de1985eae535..f930808e9db8 100644
@@ -210,8 +210,12 @@ int generic_parse_monolithic(struct fs_context *fc, void *data)
 	if (ret)
 		return ret;
 
+	/* 'sloppy' should be parsed first */
+	if (strstr((const char *)data, "sloppy") != NULL)
+		vfs_parse_fs_string(fc, "sloppy", NULL, 0);
+
 	while ((key = strsep(&options, ",")) != NULL) {
-		if (*key) {
+		if (*key && strcmp(key, "sloppy")) {
 			size_t v_len = 0;
 			char *value = strchr(key, '=');
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 5 lines · Roberto Bergantinos Corpas

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

Quoted 7 lines

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt host#

This patch correct that behaviour so that sloppy takes precedence if specified anywhere on the string

It's slightly overcorrected, but that probably doesn't matter.

I wonder if we should put a "bool sloppy" in struct fs_context, put the handling in vfs_parse_fs_param() (ie. skip the error message).

David

#2 lore raw

David,

i came up with the following approach, i drop the sloppy booleans
from cifs/nfs and leave it at fs_context level

, let me know what you think and ill send as new version :

fs/cifs/fs_context.c +0 -0
index 7ec35f3f0a5f..5a8c074df74a 100644
@@ -866,7 +866,7 @@ static int smb3_fs_context_parse_param(struct

fs_context *fc,

     if (!skip_parsing) {
         opt = fs_parse(fc, smb3_fs_parameters, param, &result);
         if (opt < 0)
-            return ctx->sloppy ? 1 : opt;
+            return fc->sloppy ? 1 : opt;
     }

     switch (opt) {
@@ -1412,7 +1412,7 @@ static int smb3_fs_context_parse_param(struct
fs_context *fc,
         ctx->multiuser = true;
         break;
     case Opt_sloppy:
-        ctx->sloppy = true;
+        fc->sloppy = true;
         break;
     case Opt_nosharesock:
         ctx->nosharesock = true;
fs/cifs/fs_context.h +0 -1
index e54090d9ef36..52a67a96fb67 100644
@@ -155,7 +155,6 @@ struct smb3_fs_context {
     bool uid_specified;
     bool cruid_specified;
     bool gid_specified;
-    bool sloppy;
     bool got_ip;
     bool got_version;
     bool got_rsize;
fs/fs_context.c +0 -0
index 24ce12f0db32..3c1c999fc1fb 100644
@@ -155,8 +155,14 @@ int vfs_parse_fs_param(struct fs_context *fc,

struct fs_parameter *param)

     if (ret != -ENOPARAM)
         return ret;

- return invalf(fc, "%s: Unknown parameter '%s'",
- fc->fs_type->name, param->key);
+ /* We got an invalid parameter, but sloppy may have been specified
+ * later on param string. Let's wait to process whole params to return
+ * EINVAL */
+
+ fc->param_inval = true;
+ errorf(fc, "%s: Unknown parameter '%s'",fc->fs_type->name, param->key);
+
+ return 0;
}
EXPORT_SYMBOL(vfs_parse_fs_param);

@@ -227,6 +233,9 @@ int generic_parse_monolithic(struct fs_context *fc, void *data)

         }
     }

+ if (!fc->sloppy && fc->param_inval)
+ ret = -EINVAL;
+

     return ret;

}
EXPORT_SYMBOL(generic_parse_monolithic);

fs/nfs/fs_context.c +2 -2
index ea17fa1f31ec..c9ff68e17b68 100644
@@ -482,7 +482,7 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
 
     opt = fs_parse(fc, nfs_fs_parameters, param, &result);
     if (opt < 0)
-        return ctx->sloppy ? 1 : opt;
+        return fc->sloppy ? 1 : opt;
 
     if (fc->security)
         ctx->has_sec_mnt_opts = 1;
@@ -837,7 +837,7 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
          * Special options
          */
     case Opt_sloppy:
-        ctx->sloppy = true;
+        fc->sloppy = true;
         dfprintk(MOUNT, "NFS:   relaxing parsing rules\n");
         break;
     }
fs/nfs/internal.h +0 -1
index 12f6acb483bb..9febdc95b4d0 100644
@@ -80,7 +80,6 @@ struct nfs_fs_context {
     bool            internal;
     bool            skip_reconfig_option_check;
     bool            need_mount;
-    bool            sloppy;
     unsigned int        flags;        /* NFS{,4}_MOUNT_* flags */
     unsigned int        rsize, wsize;
     unsigned int        timeo, retrans;
include/linux/fs_context.h +1 -0
index 13fa6f3df8e4..06a4b72a0f98 100644
@@ -110,6 +110,8 @@ struct fs_context {
     bool            need_free:1;    /* Need to call ops->free() */
     bool            global:1;    /* Goes into &init_user_ns */
     bool            oldapi:1;    /* Coming from mount(2) */
+    bool                    sloppy:1;       /* If fs support it and

was specified */
+ bool param_inval:1; /* If set, check sloppy value */
};

struct fs_context_operations {

Quoted 23 lines · David Howells
Quoted 5 lines · Roberto Bergantinos Corpas

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

Quoted 7 lines

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt host#

This patch correct that behaviour so that sloppy takes precedence if specified anywhere on the string

It's slightly overcorrected, but that probably doesn't matter.

I wonder if we should put a "bool sloppy" in struct fs_context, put the handling in vfs_parse_fs_param() (ie. skip the error message).

David

#3 lore raw
In reply to Roberto Bergantinos Corpas
Quoted 8 lines · Roberto Bergantinos Corpas

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt

It isn't clear to me that this is incorrect behaviour. Perhaps the user actually wants the options to the left parsed strictly and the options to the right parsed sloppily?

#4 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Roberto Bergantinos Corpas

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

Quoted 7 lines
Quoted 3 lines

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt

It isn't clear to me that this is incorrect behaviour. Perhaps the user actually wants the options to the left parsed strictly and the options to the right parsed sloppily?

I don't think mount options have ever been order-dependent, at least not intentionally so, have they?

And what matters most here is surely "how did it work before the mount API change?"

And it seems to me that previously, invalid options were noted, and whether the mount would fail was left to the end, depending on whether sloppy was seen anywhere in the mount options string. This is the old option parsing:

        while ((p = strsep(&raw, ",")) != NULL) {
...
                switch (token) {
...
                case Opt_sloppy:
                        sloppy = 1;
                        dfprintk(MOUNT, "NFS:   relaxing parsing rules\n");
                        break;
...
                default:
                        invalid_option = 1;
                        dfprintk(MOUNT, "NFS:   unrecognized mount option "
                                        "'%s'\n", p);
                }
        }

        if (!sloppy && invalid_option)
                return 0;

-Eric

#5 lore raw
Quoted 35 lines · Eric Sandeen
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Roberto Bergantinos Corpas

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

Quoted 7 lines
Quoted 3 lines

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt

It isn't clear to me that this is incorrect behaviour. Perhaps the user actually wants the options to the left parsed strictly and the options to the right parsed sloppily?

I don't think mount options have ever been order-dependent, at least not intentionally so, have they?

And what matters most here is surely "how did it work before the mount API change?"

Quoted 1 line

And it seems to me that previously, invalid options were noted, and whether the

mount would fail was left to the end, depending on whether sloppy was seen anywhere in the mount options string. This is the old option parsing:

         while ((p = strsep(&raw, ",")) != NULL) {
...
                 switch (token) {
...
                 case Opt_sloppy:
                         sloppy = 1;
                         dfprintk(MOUNT, "NFS:   relaxing parsing rules\n");
                         break;
...
                 default:
Quoted 8 lines
                         invalid_option = 1;
                         dfprintk(MOUNT, "NFS:   unrecognized mount option "
                                         "'%s'\n", p);
                 }
         }

         if (!sloppy && invalid_option)
                 return 0;

Agree, that's my main point. I think that breaks from previous
behaviour and indeed causes issues on the field.
My understanding too is that there's no order-dependency.

roberto

Quoted 3 lines

-Eric

#6 lore raw
Quoted 43 lines · Roberto Bergantinos Corpas
Quoted 41 lines · Eric Sandeen
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Roberto Bergantinos Corpas

With addition of fs_context support, options string is parsed sequentially, if 'sloppy' option is not leftmost one, we may return ENOPARAM to userland if a non-valid option preceeds sloopy and mount will fail :

Quoted 7 lines
Quoted 3 lines

host# mount -o quota,sloppy 172.23.1.225:/share /mnt mount.nfs: an incorrect mount option was specified host# mount -o sloppy,quota 172.23.1.225:/share /mnt

It isn't clear to me that this is incorrect behaviour. Perhaps the user actually wants the options to the left parsed strictly and the options to the right parsed sloppily?

I don't think mount options have ever been order-dependent, at least not intentionally so, have they?

And what matters most here is surely "how did it work before the mount API change?"

Quoted 1 line

And it seems to me that previously, invalid options were noted, and whether the

mount would fail was left to the end, depending on whether sloppy was seen anywhere in the mount options string. This is the old option parsing:

         while ((p = strsep(&raw, ",")) != NULL) {
...
                 switch (token) {
...
                 case Opt_sloppy:
                         sloppy = 1;
                         dfprintk(MOUNT, "NFS:   relaxing parsing rules\n");
                         break;
...
                 default:
                         invalid_option = 1;
                         dfprintk(MOUNT, "NFS:   unrecognized mount option "
                                         "'%s'\n", p);
                 }
         }
Quoted 9 lines
Quoted 2 lines
         if (!sloppy && invalid_option)
                 return 0;

Agree, that's my main point. I think that breaks from previous
behaviour and indeed causes issues on the field.
My understanding too is that there's no order-dependency.

roberto

Hi Roberto, Eric and David H, this seems to have stalled. What are the next steps here?

Roberto, it sounded like David H was suggesting maybe an alternative approach. Did you look into that?

Then there was a discussion about whether this change was intended behavior or not, and the main point made was it was a change in behavior, which I don't think was intended. I guess one could make the argument order was never guaranteed, but then why make behavior order dependent now if it was not intentional kernel change? I agree if possible we should retain the order independent behavior in the kernel.

#7 lore raw
Quoted 2 lines

Roberto, it sounded like David H was suggesting maybe an alternative approach. Did you look into that?

No, sorry about that, it is in my todo list. i'll take a look at it