23 #include <linux/module.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
38 #include <linux/nfs_fs.h>
45 #include <linux/nfs_idmap.h>
48 #include <linux/in6.h>
49 #include <linux/slab.h>
51 #include <linux/netdevice.h>
53 #include <linux/magic.h>
59 #include <asm/uaccess.h>
70 #define NFSDBG_FACILITY NFSDBG_VFS
71 #define NFS_TEXT_DATA 1
73 #if IS_ENABLED(CONFIG_NFS_V3)
74 #define NFS_DEFAULT_VERSION 3
76 #define NFS_DEFAULT_VERSION 2
287 int flags,
const char *dev_name,
void *raw_data);
301 .mount = nfs_xdev_mount,
322 #if IS_ENABLED(CONFIG_NFS_V4)
324 static int nfs4_validate_mount_data(
void *
options,
336 static int __init register_nfs4_fs(
void)
341 static void unregister_nfs4_fs(
void)
346 static int __init register_nfs4_fs(
void)
351 static void unregister_nfs4_fs(
void)
356 static struct shrinker acl_shrinker = {
372 ret = register_nfs4_fs();
383 unregister_nfs4_fs();
397 unregister_nfs4_fs();
419 static int nfs_deactivate_super_async_work(
void *
ptr)
432 static void nfs_deactivate_super_async(
struct super_block *
sb)
439 if (!atomic_add_unless(&sb->
s_active, -1, 1)) {
446 task =
kthread_run(nfs_deactivate_super_async_work, sb,
447 "%s-deactivate-super", buf);
449 pr_err(
"%s: kthread_run: %ld\n",
450 __func__, PTR_ERR(task));
463 nfs_deactivate_super_async(sb);
473 unsigned char blockbits;
474 unsigned long blockres;
483 error = server->
nfs_client->rpc_ops->statfs(server, fh, &res);
485 struct dentry *pd_dentry;
488 if (pd_dentry !=
NULL) {
493 nfs_free_fattr(res.
fattr);
514 blockbits = dentry->
d_sb->s_blocksize_bits;
515 blockres = (1 << blockbits) - 1;
528 dprintk(
"%s: statfs error = %d\n", __func__, -error);
536 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
538 static const struct {
539 rpc_authflavor_t flavour;
542 { RPC_AUTH_NULL,
"null" },
543 { RPC_AUTH_UNIX,
"sys" },
544 { RPC_AUTH_GSS_KRB5,
"krb5" },
545 { RPC_AUTH_GSS_KRB5I,
"krb5i" },
546 { RPC_AUTH_GSS_KRB5P,
"krb5p" },
547 { RPC_AUTH_GSS_LKEY,
"lkey" },
548 { RPC_AUTH_GSS_LKEYI,
"lkeyi" },
549 { RPC_AUTH_GSS_LKEYP,
"lkeyp" },
550 { RPC_AUTH_GSS_SPKM,
"spkm" },
551 { RPC_AUTH_GSS_SPKMI,
"spkmi" },
552 { RPC_AUTH_GSS_SPKMP,
"spkmp" },
557 for (i = 0; sec_flavours[
i].flavour !=
UINT_MAX; i++) {
558 if (sec_flavours[i].flavour == flavour)
561 return sec_flavours[
i].str;
634 nfs_show_mountd_netid(m, nfss, showdefaults);
637 #if IS_ENABLED(CONFIG_NFS_V4)
643 seq_printf(m,
",clientaddr=%s", clp->cl_ipaddr);
652 static void nfs_show_nfs_version(
struct seq_file *m,
654 unsigned int minorversion)
667 static const struct proc_nfs_info {
683 const struct proc_nfs_info *nfs_infop;
686 int local_flock, local_fcntl;
691 if (nfss->
bsize != 0)
702 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
703 if (nfss->
flags & nfs_infop->flag)
721 seq_printf(m,
",sec=%s", nfs_pseudoflavour_to_name(nfss->
client->cl_auth->au_flavor));
724 nfs_show_mountd_options(m, nfss, showdefaults);
726 nfs_show_nfsv4_options(m, nfss, showdefaults);
744 if (!local_flock && !local_fcntl)
746 else if (local_flock && local_fcntl)
748 else if (local_flock)
761 nfs_show_mount_options(m, nfss, 0);
773 #if IS_ENABLED(CONFIG_NFS_V4)
774 #ifdef CONFIG_NFS_V4_1
785 #ifdef CONFIG_NFS_V4_1
789 if (server->pnfs_curr_ld)
790 seq_printf(m,
"%s", server->pnfs_curr_ld->name);
798 struct nfs41_impl_id *impl_id = nfss->
nfs_client->cl_implid;
799 seq_printf(m,
"\n\timpl_id:\tname='%s',domain='%s',"
801 impl_id->name, impl_id->domain,
802 impl_id->date.seconds, impl_id->date.nseconds);
806 #if IS_ENABLED(CONFIG_NFS_V4)
819 char *devname, *
dummy;
825 err = PTR_ERR(devname);
847 struct rpc_auth *
auth = nfss->
client->cl_auth;
860 nfs_show_mount_options(m, nfss, 1);
864 show_implementation_id(m, nfss);
873 #if IS_ENABLED(CONFIG_NFS_V4)
874 if (nfss->
nfs_client->rpc_ops->version == 4) {
876 seq_printf(m,
"bm0=0x%x", nfss->attr_bitmask[0]);
877 seq_printf(m,
",bm1=0x%x", nfss->attr_bitmask[1]);
878 seq_printf(m,
",acl=0x%x", nfss->acl_bitmask);
879 show_sessions(m, nfss);
887 seq_printf(m,
"\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
889 seq_printf(m,
",pseudoflavor=%u", auth->au_flavor);
904 #ifdef CONFIG_NFS_FSCACHE
906 totals.fscache[i] += stats->fscache[i];
918 #ifdef CONFIG_NFS_FSCACHE
965 data->
nfs_server.protocol = XPRT_TRANSPORT_TCP;
971 security_init_mnt_opts(&data->
lsm_opts);
984 security_free_mnt_opts(&data->
lsm_opts);
995 static int nfs_verify_server_address(
struct sockaddr *
addr)
1004 return !ipv6_addr_any(sa);
1008 dfprintk(MOUNT,
"NFS: Invalid IP address specified\n");
1016 static void nfs_set_port(
struct sockaddr *sap,
int *
port,
1017 const unsigned short default_port)
1020 *port = default_port;
1022 rpc_set_port(sap, *port);
1032 case XPRT_TRANSPORT_UDP:
1033 case XPRT_TRANSPORT_TCP:
1034 case XPRT_TRANSPORT_RDMA:
1037 mnt->
nfs_server.protocol = XPRT_TRANSPORT_TCP;
1047 nfs_validate_transport_protocol(mnt);
1049 if (mnt->
mount_server.protocol == XPRT_TRANSPORT_UDP ||
1053 case XPRT_TRANSPORT_UDP:
1056 case XPRT_TRANSPORT_TCP:
1057 case XPRT_TRANSPORT_RDMA:
1065 static int nfs_parse_security_flavors(
char *
value,
1070 dfprintk(MOUNT,
"NFS: parsing sec=%s option\n", value);
1072 switch (
match_token(value, nfs_secflavor_tokens, args)) {
1115 static int nfs_parse_version_string(
char *
string,
1120 switch (
match_token(
string, nfs_vers_tokens, args)) {
1164 rc = kstrtoul(
string, 10, option);
1176 static int nfs_parse_mount_options(
char *
raw,
1180 int rc, sloppy = 0, invalid_option = 0;
1185 dfprintk(MOUNT,
"NFS: mount options string was NULL.\n");
1188 dfprintk(MOUNT,
"NFS: nfs mount opts='%s'\n", raw);
1190 secdata = alloc_secdata();
1196 goto out_security_failure;
1200 goto out_security_failure;
1202 free_secdata(secdata);
1212 dfprintk(MOUNT,
"NFS: parsing nfs mount option '%s'\n", p);
1214 token =
match_token(p, nfs_mount_option_tokens, args);
1256 mnt->
nfs_server.protocol = XPRT_TRANSPORT_UDP;
1260 mnt->
nfs_server.protocol = XPRT_TRANSPORT_TCP;
1264 mnt->
nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1312 if (nfs_get_option_ul(args, &option) ||
1314 goto out_invalid_value;
1318 if (nfs_get_option_ul(args, &option))
1319 goto out_invalid_value;
1323 if (nfs_get_option_ul(args, &option))
1324 goto out_invalid_value;
1328 if (nfs_get_option_ul(args, &option))
1329 goto out_invalid_value;
1333 if (nfs_get_option_ul(args, &option) || option == 0)
1334 goto out_invalid_value;
1338 if (nfs_get_option_ul(args, &option) || option == 0)
1339 goto out_invalid_value;
1343 if (nfs_get_option_ul(args, &option))
1344 goto out_invalid_value;
1348 if (nfs_get_option_ul(args, &option))
1349 goto out_invalid_value;
1353 if (nfs_get_option_ul(args, &option))
1354 goto out_invalid_value;
1358 if (nfs_get_option_ul(args, &option))
1359 goto out_invalid_value;
1363 if (nfs_get_option_ul(args, &option))
1364 goto out_invalid_value;
1369 if (nfs_get_option_ul(args, &option))
1370 goto out_invalid_value;
1374 if (nfs_get_option_ul(args, &option) ||
1376 goto out_invalid_value;
1380 if (nfs_get_option_ul(args, &option) ||
1383 goto out_invalid_value;
1387 if (nfs_get_option_ul(args, &option))
1388 goto out_invalid_value;
1390 goto out_invalid_value;
1401 rc = nfs_parse_version_string(
string, mnt, args);
1404 goto out_invalid_value;
1410 rc = nfs_parse_security_flavors(
string, mnt);
1413 dfprintk(MOUNT,
"NFS: unrecognized "
1414 "security flavor\n");
1423 nfs_xprt_protocol_tokens, args);
1431 mnt->
nfs_server.protocol = XPRT_TRANSPORT_UDP;
1437 mnt->
nfs_server.protocol = XPRT_TRANSPORT_TCP;
1442 mnt->
nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1446 dfprintk(MOUNT,
"NFS: unrecognized "
1447 "transport protocol\n");
1458 nfs_xprt_protocol_tokens, args);
1475 dfprintk(MOUNT,
"NFS: unrecognized "
1476 "transport protocol\n");
1491 goto out_invalid_address;
1498 if (nfs_get_option_str(args,
1513 goto out_invalid_address;
1520 nfs_lookupcache_tokens, args);
1535 "lookupcache argument\n");
1548 token =
match_token(
string, nfs_local_lock_tokens,
1568 "local_lock argument\n");
1578 dfprintk(MOUNT,
"NFS: relaxing parsing rules\n");
1582 dfprintk(MOUNT,
"NFS: ignoring mount option "
1588 dfprintk(MOUNT,
"NFS: unrecognized mount option "
1593 if (!sloppy && invalid_option)
1597 goto out_minorversion_mismatch;
1601 goto out_migration_misuse;
1608 protofamily != mnt->
nfs_server.address.ss_family)
1609 goto out_proto_mismatch;
1613 if (mountfamily != mnt->
mount_server.address.ss_family)
1614 goto out_mountproto_mismatch;
1616 if (mountfamily != mnt->
nfs_server.address.ss_family)
1617 goto out_mountproto_mismatch;
1623 out_mountproto_mismatch:
1624 printk(
KERN_INFO "NFS: mount server address does not match mountproto= "
1628 printk(
KERN_INFO "NFS: server address does not match proto= option\n");
1630 out_invalid_address:
1636 out_minorversion_mismatch:
1640 out_migration_misuse:
1642 "NFS: 'migration' not supported for this NFS version\n");
1647 out_security_failure:
1648 free_secdata(secdata);
1671 if (server_authlist_len == 0)
1686 for (j = 0; j < server_authlist_len; j++)
1688 dfprintk(MOUNT,
"NFS: using auth flavor %d\n",
1694 dfprintk(MOUNT,
"NFS: server does not support requested auth flavor\n");
1707 unsigned int server_authlist_len =
ARRAY_SIZE(server_authlist);
1715 .auth_flav_len = &server_authlist_len,
1716 .auth_flavs = server_authlist,
1754 dfprintk(MOUNT,
"NFS: unable to mount server %s, error %d\n",
1764 return nfs_walk_authlist(args, &request);
1774 if (mount_info->
parsed->need_mount) {
1775 status = nfs_request_mount(mount_info->
parsed, mount_info->
mntfh);
1777 return ERR_PTR(status);
1781 server = nfs_mod->
rpc_ops->create_server(mount_info, nfs_mod);
1783 return ERR_CAST(server);
1798 static int nfs_parse_devname(
const char *dev_name,
1799 char **hostname,
size_t maxnamlen,
1800 char **export_path,
size_t maxpathlen)
1806 if (*dev_name ==
'[') {
1807 end =
strchr(++dev_name,
']');
1808 if (end ==
NULL || end[1] !=
':')
1809 goto out_bad_devname;
1811 len = end - dev_name;
1816 end =
strchr(dev_name,
':');
1818 goto out_bad_devname;
1819 len = end - dev_name;
1822 comma =
strchr(dev_name,
',');
1823 if (comma !=
NULL && comma < end)
1827 if (len > maxnamlen)
1832 if (*hostname ==
NULL)
1835 if (len > maxpathlen)
1841 dfprintk(MOUNT,
"NFS: MNTPATH: '%s'\n", *export_path);
1845 dfprintk(MOUNT,
"NFS: device name not in host:path format\n");
1849 dfprintk(MOUNT,
"NFS: not enough memory to parse device name\n");
1853 dfprintk(MOUNT,
"NFS: server hostname too long\n");
1857 dfprintk(MOUNT,
"NFS: export pathname too long\n");
1877 static int nfs23_validate_mount_data(
void *
options,
1880 const char *dev_name)
1907 goto out_invalid_fh;
1917 if (mntfh->
size <
sizeof(mntfh->
data))
1919 sizeof(mntfh->
data) - mntfh->
size);
1940 if (!nfs_verify_server_address(sap))
1941 goto out_no_address;
1944 args->
nfs_server.protocol = XPRT_TRANSPORT_UDP;
1970 #ifdef CONFIG_SECURITY_SELINUX
1975 strcpy(opts_str,
"context=");
1992 #if !IS_ENABLED(CONFIG_NFS_V3)
1994 goto out_v3_not_compiled;
2000 dfprintk(MOUNT,
"NFS: mount program didn't pass any mount data\n");
2004 dfprintk(MOUNT,
"NFS: nfs_mount_data version %d does not support v3\n",
2009 dfprintk(MOUNT,
"NFS: nfs_mount_data version supports only AUTH_SYS\n");
2012 #if !IS_ENABLED(CONFIG_NFS_V3)
2013 out_v3_not_compiled:
2014 dfprintk(MOUNT,
"NFS: NFSv3 is not compiled into kernel\n");
2019 dfprintk(MOUNT,
"NFS: not enough memory to handle mount options\n");
2023 dfprintk(MOUNT,
"NFS: mount program didn't pass remote address\n");
2027 dfprintk(MOUNT,
"NFS: invalid root filehandle\n");
2031 #if IS_ENABLED(CONFIG_NFS_V4)
2036 const char *dev_name)
2038 if (fs_type == &nfs_fs_type)
2039 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2040 return nfs4_validate_mount_data(options, args, dev_name);
2047 const char *dev_name)
2049 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2053 static int nfs_validate_text_mount_data(
void *options,
2055 const char *dev_name)
2062 if (nfs_parse_mount_options((
char *)options, args) == 0)
2065 if (!nfs_verify_server_address(sap))
2066 goto out_no_address;
2069 #if IS_ENABLED(CONFIG_NFS_V4)
2073 nfs_validate_transport_protocol(args);
2074 nfs4_validate_mount_flags(args);
2076 goto out_v4_not_compiled;
2079 nfs_set_mount_transport_protocol(args);
2081 nfs_set_port(sap, &args->
nfs_server.port, port);
2086 return nfs_parse_devname(dev_name,
2092 #if !IS_ENABLED(CONFIG_NFS_V4)
2093 out_v4_not_compiled:
2094 dfprintk(MOUNT,
"NFS: NFSv4 is not compiled into kernel\n");
2099 dfprintk(MOUNT,
"NFS: mount program didn't pass remote address\n");
2103 dfprintk(MOUNT,
"NFS: Too many RPC auth flavours specified\n");
2108 nfs_compare_remount_data(
struct nfs_server *nfss,
2120 data->
timeo != (10
U * nfss->
client->cl_timeout->to_initval /
HZ) ||
2146 if ((nfsvers == 4 && (!options4 || options4->
version == 1)) ||
2147 (nfsvers <= 3 && (!options || (options->
version >= 1 &&
2172 error = nfs_parse_mount_options((
char *)options, data);
2186 error = nfs_compare_remount_data(nfss, data);
2227 if (data && data->
bsize)
2230 if (server->
nfs_client->rpc_ops->version != 2) {
2257 if (server->
nfs_client->rpc_ops->version != 2) {
2303 static int nfs_set_super(
struct super_block *s,
void *data)
2318 static int nfs_compare_super_address(
struct nfs_server *server1,
2355 static int nfs_compare_super(
struct super_block *sb,
void *data)
2359 int mntflags = sb_mntdata->
mntflags;
2361 if (!nfs_compare_super_address(old, server))
2366 if (
memcmp(&old->fsid, &server->
fsid,
sizeof(old->fsid)) != 0)
2368 return nfs_compare_mount_options(sb, server, mntflags);
2371 #ifdef CONFIG_NFS_FSCACHE
2372 static void nfs_get_cache_cookie(
struct super_block *sb,
2382 }
else if (cloned) {
2384 if (mnt_s->fscache_key) {
2385 uniq = mnt_s->fscache_key->key.uniquifier;
2386 ulen = mnt_s->fscache_key->key.uniq_len;
2393 static void nfs_get_cache_cookie(
struct super_block *sb,
2400 static int nfs_bdi_register(
struct nfs_server *server)
2424 int flags,
const char *dev_name,
2430 int (*compare_super)(
struct super_block *,
void *) = nfs_compare_super;
2438 compare_super =
NULL;
2445 s =
sget(nfs_mod->
nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
2447 mntroot = ERR_CAST(s);
2455 error = nfs_bdi_register(server);
2457 mntroot = ERR_PTR(error);
2458 goto error_splat_bdi;
2465 nfs_get_cache_cookie(s, mount_info->
parsed, mount_info->
cloned);
2469 if (IS_ERR(mntroot))
2470 goto error_splat_super;
2472 error = mount_info->
set_security(s, mntroot, mount_info);
2474 goto error_splat_root;
2487 mntroot = ERR_PTR(error);
2489 if (server && !s->
s_root)
2498 int flags,
const char *dev_name,
void *raw_data)
2508 mount_info.
parsed = nfs_alloc_parsed_mount_data();
2514 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.
parsed, mount_info.
mntfh, dev_name);
2516 error = nfs_validate_text_mount_data(raw_data, mount_info.
parsed, dev_name);
2518 mntroot = ERR_PTR(error);
2523 if (IS_ERR(nfs_mod)) {
2524 mntroot = ERR_CAST(nfs_mod);
2528 mntroot = nfs_mod->
rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
2532 nfs_free_parsed_mount_data(mount_info.
parsed);
2533 nfs_free_fhandle(mount_info.
mntfh);
2568 const char *dev_name,
void *raw_data)
2581 dprintk(
"--> nfs_xdev_mount_common()\n");
2587 if (IS_ERR(server)) {
2588 error = PTR_ERR(server);
2593 dprintk(
"<-- nfs_xdev_mount_common() = 0\n");
2598 dprintk(
"<-- nfs_xdev_mount_common() = %d [error]\n", error);
2602 #if IS_ENABLED(CONFIG_NFS_V4)
2613 static int nfs4_validate_mount_data(
void *options,
2615 const char *dev_name)
2626 switch (data->version) {
2628 if (data->host_addrlen >
sizeof(args->
nfs_server.address))
2629 goto out_no_address;
2630 if (data->host_addrlen == 0)
2631 goto out_no_address;
2632 args->
nfs_server.addrlen = data->host_addrlen;
2635 if (!nfs_verify_server_address(sap))
2636 goto out_no_address;
2639 if (data->auth_flavourlen) {
2640 if (data->auth_flavourlen > 1)
2641 goto out_inval_auth;
2643 data->auth_flavours,
2657 dfprintk(MOUNT,
"NFS: MNTPATH: '%s'\n", c);
2670 args->
rsize = data->rsize;
2671 args->
wsize = data->wsize;
2672 args->
timeo = data->timeo;
2673 args->
retrans = data->retrans;
2679 nfs_validate_transport_protocol(args);
2689 dfprintk(MOUNT,
"NFS4: mount program didn't pass any mount data\n");
2693 dfprintk(MOUNT,
"NFS4: Invalid number of RPC auth flavours %d\n",
2694 data->auth_flavourlen);
2698 dfprintk(MOUNT,
"NFS4: mount program didn't pass remote address\n");
2711 bool nfs4_disable_idmapping =
true;
2713 unsigned short send_implementation_id = 1;
2714 char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] =
"";
2724 #define NFS_CALLBACK_MAXPORTNR (65535U)
2726 static int param_set_portnr(
const char *
val,
const struct kernel_param *kp)
2733 ret = kstrtoul(val, 0, &num);
2734 if (ret == -
EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2736 *((
unsigned int *)kp->
arg) = num;
2740 .
set = param_set_portnr,
2743 #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2749 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
2751 "Turn off NFSv4 idmapping when using 'sec=sys'");
2753 MODULE_PARM_DESC(max_session_slots,
"Maximum number of outstanding NFSv4.1 "
2754 "requests the client will negotiate");
2757 "Send implementation ID with NFSv4.1 exchange_id");