]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
NFSD: correctly range-check v4.x minor version when setting versions.
authorNeilBrown <neilb@suse.com>
Wed, 21 Dec 2016 03:32:19 +0000 (14:32 +1100)
committerJ. Bruce Fields <bfields@redhat.com>
Tue, 31 Jan 2017 17:31:53 +0000 (12:31 -0500)
Writing to /proc/fs/nfsd/versions allows individual major versions
and NFSv4 minor versions to be enabled or disabled.

However NFSv4.0 cannot currently be disabled, thought there is no good reason.
Also the minor number is parsed as a 'long' but used as an 'int'
so '4294967297' will be incorrectly treated as '1'.

This patch removes the test on 'minor == 0' and switches to kstrtouint()
to get correct range checking.

When reading from /proc/fs/nfsd/versions, 4.0 is current not reported.
To allow the disabling for v4.0 to be visible, while maintaining
backward compatibility, change code to report "-4.0" if appropriate, but
not "+4.0".

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfsctl.c

index f3b2f34b10a3f19cd018c9fd8d176dfae44ea70b..d54fb0e3f30e9f0a6c3ef42a10c7a33acb517d84 100644 (file)
@@ -569,8 +569,7 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size)
                        if (*minorp == '.') {
                                if (num != 4)
                                        return -EINVAL;
-                               minor = simple_strtoul(minorp+1, NULL, 0);
-                               if (minor == 0)
+                               if (kstrtouint(minorp+1, 0, &minor) < 0)
                                        return -EINVAL;
                                if (nfsd_minorversion(minor, sign == '-' ?
                                                     NFSD_CLEAR : NFSD_SET) < 0)
@@ -613,8 +612,13 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size)
                        tlen += len;
                }
        if (nfsd_vers(4, NFSD_AVAIL))
-               for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
+               for (minor = 0; minor <= NFSD_SUPPORTED_MINOR_VERSION;
                     minor++) {
+                       if (minor == 0 && nfsd_minorversion(minor, NFSD_TEST))
+                               /* for backward compatibility, don't report
+                                * +4.0
+                                */
+                               continue;
                        len = snprintf(buf, remaining, " %c4.%u",
                                        (nfsd_vers(4, NFSD_TEST) &&
                                         nfsd_minorversion(minor, NFSD_TEST)) ?