Commit f45663ce authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust

NFS: Allow either strict or sloppy mount option parsing

The kernel's NFS client mount option parser currently doesn't allow
unrecognized or incorrect mount options.  This prevents misspellings or
incorrectly specified mount options from possibly causing silent data
corruption.

However, NFS mount options are not standardized, so different operating
systems can use differently spelled mount options to support similar
features, or can support mount options which no other operating system
supports.

"Sloppy" mount option parsing, which allows the parser to ignore any
option it doesn't recognize, is needed to support automounters that often
use maps that are shared between heterogenous operating systems.

The legacy mount command ignores the validity of the values of mount
options entirely, except for the "sec=" and "proto=" options.  If an
incorrect value is specified, the out-of-range value is passed to the
kernel; if a value is specified that contains non-numeric characters,
it appears as though the legacy mount command sets that option to zero
(probably incorrect behavior in general).

In any case, this sets a precedent which we will partially follow for
the kernel mount option parser:

	+ if "sloppy" is not set, the parser will be strict about both
	  unrecognized options (same as legacy) and invalid option
	  values (stricter than legacy)

	+ if "sloppy" is set, the parser will ignore unrecognized
	  options and invalid option values (same as legacy)

An "invalid" option value in this case means that either the type
(integer, short, or string) or sign (for integer values) of the specified
value is incorrect.

This patch does two things: it changes the NFS client's mount option
parsing loop so that it parses the whole string instead of failing at
the first unrecognized option or invalid option value.  An unrecognized
option or an invalid option value cause the option to be skipped.

Then, the patch adds a "sloppy" mount option that allows the parsing
to succeed anyway if there were any problems during parsing.  When
parsing a set of options is complete, if there are errors and "sloppy"
was specified, return success anyway.  Otherwise, only return success
if there are no errors.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 6738b251
...@@ -92,8 +92,8 @@ enum { ...@@ -92,8 +92,8 @@ enum {
Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Opt_addr, Opt_mountaddr, Opt_clientaddr, Opt_addr, Opt_mountaddr, Opt_clientaddr,
/* Mount options that are ignored */ /* Special mount options */
Opt_userspace, Opt_deprecated, Opt_userspace, Opt_deprecated, Opt_sloppy,
Opt_err Opt_err
}; };
...@@ -103,6 +103,8 @@ static match_table_t nfs_mount_option_tokens = { ...@@ -103,6 +103,8 @@ static match_table_t nfs_mount_option_tokens = {
{ Opt_userspace, "fg" }, { Opt_userspace, "fg" },
{ Opt_userspace, "retry=%s" }, { Opt_userspace, "retry=%s" },
{ Opt_sloppy, "sloppy" },
{ Opt_soft, "soft" }, { Opt_soft, "soft" },
{ Opt_hard, "hard" }, { Opt_hard, "hard" },
{ Opt_deprecated, "intr" }, { Opt_deprecated, "intr" },
...@@ -917,15 +919,22 @@ static int nfs_parse_security_flavors(char *value, ...@@ -917,15 +919,22 @@ static int nfs_parse_security_flavors(char *value,
return 1; return 1;
} }
static void nfs_parse_invalid_value(const char *option)
{
dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
}
/* /*
* Error-check and convert a string of mount options from user space into * Error-check and convert a string of mount options from user space into
* a data structure * a data structure. The whole mount string is processed; bad options are
* skipped as they are encountered. If there were no errors, return 1;
* otherwise return 0 (zero).
*/ */
static int nfs_parse_mount_options(char *raw, static int nfs_parse_mount_options(char *raw,
struct nfs_parsed_mount_data *mnt) struct nfs_parsed_mount_data *mnt)
{ {
char *p, *string, *secdata; char *p, *string, *secdata;
int rc; int rc, sloppy = 0, errors = 0;
if (!raw) { if (!raw) {
dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
...@@ -958,6 +967,10 @@ static int nfs_parse_mount_options(char *raw, ...@@ -958,6 +967,10 @@ static int nfs_parse_mount_options(char *raw,
token = match_token(p, nfs_mount_option_tokens, args); token = match_token(p, nfs_mount_option_tokens, args);
switch (token) { switch (token) {
/*
* boolean options: foo/nofoo
*/
case Opt_soft: case Opt_soft:
mnt->flags |= NFS_MOUNT_SOFT; mnt->flags |= NFS_MOUNT_SOFT;
break; break;
...@@ -1025,103 +1038,145 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1025,103 +1038,145 @@ static int nfs_parse_mount_options(char *raw,
mnt->flags |= NFS_MOUNT_UNSHARED; mnt->flags |= NFS_MOUNT_UNSHARED;
break; break;
/*
* options that take numeric values
*/
case Opt_port: case Opt_port:
if (match_int(args, &option)) if (match_int(args, &option) ||
return 0; option < 0 || option > USHORT_MAX) {
if (option < 0 || option > 65535) errors++;
return 0; nfs_parse_invalid_value("port");
mnt->nfs_server.port = option; } else
mnt->nfs_server.port = option;
break; break;
case Opt_rsize: case Opt_rsize:
if (match_int(args, &mnt->rsize)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("rsize");
} else
mnt->rsize = option;
break; break;
case Opt_wsize: case Opt_wsize:
if (match_int(args, &mnt->wsize)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("wsize");
} else
mnt->wsize = option;
break; break;
case Opt_bsize: case Opt_bsize:
if (match_int(args, &option)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
if (option < 0) nfs_parse_invalid_value("bsize");
return 0; } else
mnt->bsize = option; mnt->bsize = option;
break; break;
case Opt_timeo: case Opt_timeo:
if (match_int(args, &mnt->timeo)) if (match_int(args, &option) || option <= 0) {
return 0; errors++;
nfs_parse_invalid_value("timeo");
} else
mnt->timeo = option;
break; break;
case Opt_retrans: case Opt_retrans:
if (match_int(args, &mnt->retrans)) if (match_int(args, &option) || option <= 0) {
return 0; errors++;
nfs_parse_invalid_value("retrans");
} else
mnt->retrans = option;
break; break;
case Opt_acregmin: case Opt_acregmin:
if (match_int(args, &mnt->acregmin)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("acregmin");
} else
mnt->acregmin = option;
break; break;
case Opt_acregmax: case Opt_acregmax:
if (match_int(args, &mnt->acregmax)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("acregmax");
} else
mnt->acregmax = option;
break; break;
case Opt_acdirmin: case Opt_acdirmin:
if (match_int(args, &mnt->acdirmin)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("acdirmin");
} else
mnt->acdirmin = option;
break; break;
case Opt_acdirmax: case Opt_acdirmax:
if (match_int(args, &mnt->acdirmax)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("acdirmax");
} else
mnt->acdirmax = option;
break; break;
case Opt_actimeo: case Opt_actimeo:
if (match_int(args, &option)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
if (option < 0) nfs_parse_invalid_value("actimeo");
return 0; } else
mnt->acregmin = mnt->acregmin = mnt->acregmax =
mnt->acregmax = mnt->acdirmin = mnt->acdirmax = option;
mnt->acdirmin =
mnt->acdirmax = option;
break; break;
case Opt_namelen: case Opt_namelen:
if (match_int(args, &mnt->namlen)) if (match_int(args, &option) || option < 0) {
return 0; errors++;
nfs_parse_invalid_value("namlen");
} else
mnt->namlen = option;
break; break;
case Opt_mountport: case Opt_mountport:
if (match_int(args, &option)) if (match_int(args, &option) ||
return 0; option < 0 || option > USHORT_MAX) {
if (option < 0 || option > 65535) errors++;
return 0; nfs_parse_invalid_value("mountport");
mnt->mount_server.port = option; } else
mnt->mount_server.port = option;
break; break;
case Opt_mountvers: case Opt_mountvers:
if (match_int(args, &option)) if (match_int(args, &option) ||
return 0; option < NFS_MNT_VERSION ||
if (option < 0) option > NFS_MNT3_VERSION) {
return 0; errors++;
mnt->mount_server.version = option; nfs_parse_invalid_value("mountvers");
} else
mnt->mount_server.version = option;
break; break;
case Opt_nfsvers: case Opt_nfsvers:
if (match_int(args, &option)) if (match_int(args, &option)) {
return 0; errors++;
nfs_parse_invalid_value("nfsvers");
break;
}
switch (option) { switch (option) {
case 2: case NFS2_VERSION:
mnt->flags &= ~NFS_MOUNT_VER3; mnt->flags &= ~NFS_MOUNT_VER3;
break; break;
case 3: case NFS3_VERSION:
mnt->flags |= NFS_MOUNT_VER3; mnt->flags |= NFS_MOUNT_VER3;
break; break;
default: default:
goto out_unrec_vers; errors++;
nfs_parse_invalid_value("nfsvers");
} }
break; break;
/*
* options that take text values
*/
case Opt_sec: case Opt_sec:
string = match_strdup(args); string = match_strdup(args);
if (string == NULL) if (string == NULL)
goto out_nomem; goto out_nomem;
rc = nfs_parse_security_flavors(string, mnt); rc = nfs_parse_security_flavors(string, mnt);
kfree(string); kfree(string);
if (!rc) if (!rc) {
goto out_unrec_sec; errors++;
dfprintk(MOUNT, "NFS: unrecognized "
"security flavor\n");
}
break; break;
case Opt_proto: case Opt_proto:
string = match_strdup(args); string = match_strdup(args);
...@@ -1146,7 +1201,9 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1146,7 +1201,9 @@ static int nfs_parse_mount_options(char *raw,
mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
break; break;
default: default:
goto out_unrec_xprt; errors++;
dfprintk(MOUNT, "NFS: unrecognized "
"transport protocol\n");
} }
break; break;
case Opt_mountproto: case Opt_mountproto:
...@@ -1166,7 +1223,9 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1166,7 +1223,9 @@ static int nfs_parse_mount_options(char *raw,
break; break;
case Opt_xprt_rdma: /* not used for side protocols */ case Opt_xprt_rdma: /* not used for side protocols */
default: default:
goto out_unrec_xprt; errors++;
dfprintk(MOUNT, "NFS: unrecognized "
"transport protocol\n");
} }
break; break;
case Opt_addr: case Opt_addr:
...@@ -1204,6 +1263,13 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1204,6 +1263,13 @@ static int nfs_parse_mount_options(char *raw,
kfree(string); kfree(string);
break; break;
/*
* Special options
*/
case Opt_sloppy:
sloppy = 1;
dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
break;
case Opt_userspace: case Opt_userspace:
case Opt_deprecated: case Opt_deprecated:
dfprintk(MOUNT, "NFS: ignoring mount option " dfprintk(MOUNT, "NFS: ignoring mount option "
...@@ -1211,7 +1277,9 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1211,7 +1277,9 @@ static int nfs_parse_mount_options(char *raw,
break; break;
default: default:
goto out_unknown; errors++;
dfprintk(MOUNT, "NFS: unrecognized mount option "
"'%s'\n", p);
} }
} }
...@@ -1224,21 +1292,6 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1224,21 +1292,6 @@ static int nfs_parse_mount_options(char *raw,
free_secdata(secdata); free_secdata(secdata);
printk(KERN_INFO "NFS: security options invalid: %d\n", rc); printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
return 0; return 0;
out_unrec_vers:
printk(KERN_INFO "NFS: unrecognized NFS version number\n");
return 0;
out_unrec_xprt:
printk(KERN_INFO "NFS: unrecognized transport protocol\n");
return 0;
out_unrec_sec:
printk(KERN_INFO "NFS: unrecognized security flavor\n");
return 0;
out_unknown:
printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
return 0;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment