David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * linux/fs/nfs/fs_context.c |
| 4 | * |
| 5 | * Copyright (C) 1992 Rick Sladkey |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 6 | * Conversion to new mount api Copyright (C) David Howells |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 7 | * |
| 8 | * NFS mount handling. |
| 9 | * |
| 10 | * Split from fs/nfs/super.c by David Howells <dhowells@redhat.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/fs.h> |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 15 | #include <linux/fs_context.h> |
| 16 | #include <linux/fs_parser.h> |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 17 | #include <linux/nfs_fs.h> |
| 18 | #include <linux/nfs_mount.h> |
| 19 | #include <linux/nfs4_mount.h> |
| 20 | #include "nfs.h" |
| 21 | #include "internal.h" |
| 22 | |
| 23 | #define NFSDBG_FACILITY NFSDBG_MOUNT |
| 24 | |
| 25 | #if IS_ENABLED(CONFIG_NFS_V3) |
| 26 | #define NFS_DEFAULT_VERSION 3 |
| 27 | #else |
| 28 | #define NFS_DEFAULT_VERSION 2 |
| 29 | #endif |
| 30 | |
| 31 | #define NFS_MAX_CONNECTIONS 16 |
| 32 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 33 | enum nfs_param { |
| 34 | Opt_ac, |
| 35 | Opt_acdirmax, |
| 36 | Opt_acdirmin, |
| 37 | Opt_acl, |
| 38 | Opt_acregmax, |
| 39 | Opt_acregmin, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 40 | Opt_actimeo, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 41 | Opt_addr, |
| 42 | Opt_bg, |
| 43 | Opt_bsize, |
| 44 | Opt_clientaddr, |
| 45 | Opt_cto, |
| 46 | Opt_fg, |
| 47 | Opt_fscache, |
| 48 | Opt_hard, |
| 49 | Opt_intr, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 50 | Opt_local_lock, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 51 | Opt_lock, |
| 52 | Opt_lookupcache, |
| 53 | Opt_migration, |
| 54 | Opt_minorversion, |
| 55 | Opt_mountaddr, |
| 56 | Opt_mounthost, |
| 57 | Opt_mountport, |
| 58 | Opt_mountproto, |
| 59 | Opt_mountvers, |
| 60 | Opt_namelen, |
| 61 | Opt_nconnect, |
| 62 | Opt_port, |
| 63 | Opt_posix, |
| 64 | Opt_proto, |
| 65 | Opt_rdirplus, |
| 66 | Opt_rdma, |
| 67 | Opt_resvport, |
| 68 | Opt_retrans, |
| 69 | Opt_retry, |
| 70 | Opt_rsize, |
| 71 | Opt_sec, |
| 72 | Opt_sharecache, |
| 73 | Opt_sloppy, |
| 74 | Opt_soft, |
| 75 | Opt_softerr, |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame^] | 76 | Opt_softreval, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 77 | Opt_source, |
| 78 | Opt_tcp, |
| 79 | Opt_timeo, |
| 80 | Opt_udp, |
| 81 | Opt_v, |
| 82 | Opt_vers, |
| 83 | Opt_wsize, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 84 | }; |
| 85 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 86 | static const struct fs_parameter_spec nfs_param_specs[] = { |
| 87 | fsparam_flag_no("ac", Opt_ac), |
| 88 | fsparam_u32 ("acdirmax", Opt_acdirmax), |
| 89 | fsparam_u32 ("acdirmin", Opt_acdirmin), |
| 90 | fsparam_flag_no("acl", Opt_acl), |
| 91 | fsparam_u32 ("acregmax", Opt_acregmax), |
| 92 | fsparam_u32 ("acregmin", Opt_acregmin), |
| 93 | fsparam_u32 ("actimeo", Opt_actimeo), |
| 94 | fsparam_string("addr", Opt_addr), |
| 95 | fsparam_flag ("bg", Opt_bg), |
| 96 | fsparam_u32 ("bsize", Opt_bsize), |
| 97 | fsparam_string("clientaddr", Opt_clientaddr), |
| 98 | fsparam_flag_no("cto", Opt_cto), |
| 99 | fsparam_flag ("fg", Opt_fg), |
| 100 | __fsparam(fs_param_is_string, "fsc", Opt_fscache, |
| 101 | fs_param_neg_with_no|fs_param_v_optional), |
| 102 | fsparam_flag ("hard", Opt_hard), |
| 103 | __fsparam(fs_param_is_flag, "intr", Opt_intr, |
| 104 | fs_param_neg_with_no|fs_param_deprecated), |
| 105 | fsparam_enum ("local_lock", Opt_local_lock), |
| 106 | fsparam_flag_no("lock", Opt_lock), |
| 107 | fsparam_enum ("lookupcache", Opt_lookupcache), |
| 108 | fsparam_flag_no("migration", Opt_migration), |
| 109 | fsparam_u32 ("minorversion", Opt_minorversion), |
| 110 | fsparam_string("mountaddr", Opt_mountaddr), |
| 111 | fsparam_string("mounthost", Opt_mounthost), |
| 112 | fsparam_u32 ("mountport", Opt_mountport), |
| 113 | fsparam_string("mountproto", Opt_mountproto), |
| 114 | fsparam_u32 ("mountvers", Opt_mountvers), |
| 115 | fsparam_u32 ("namlen", Opt_namelen), |
| 116 | fsparam_u32 ("nconnect", Opt_nconnect), |
| 117 | fsparam_string("nfsvers", Opt_vers), |
| 118 | fsparam_u32 ("port", Opt_port), |
| 119 | fsparam_flag_no("posix", Opt_posix), |
| 120 | fsparam_string("proto", Opt_proto), |
| 121 | fsparam_flag_no("rdirplus", Opt_rdirplus), |
| 122 | fsparam_flag ("rdma", Opt_rdma), |
| 123 | fsparam_flag_no("resvport", Opt_resvport), |
| 124 | fsparam_u32 ("retrans", Opt_retrans), |
| 125 | fsparam_string("retry", Opt_retry), |
| 126 | fsparam_u32 ("rsize", Opt_rsize), |
| 127 | fsparam_string("sec", Opt_sec), |
| 128 | fsparam_flag_no("sharecache", Opt_sharecache), |
| 129 | fsparam_flag ("sloppy", Opt_sloppy), |
| 130 | fsparam_flag ("soft", Opt_soft), |
| 131 | fsparam_flag ("softerr", Opt_softerr), |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame^] | 132 | fsparam_flag ("softreval", Opt_softreval), |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 133 | fsparam_string("source", Opt_source), |
| 134 | fsparam_flag ("tcp", Opt_tcp), |
| 135 | fsparam_u32 ("timeo", Opt_timeo), |
| 136 | fsparam_flag ("udp", Opt_udp), |
| 137 | fsparam_flag ("v2", Opt_v), |
| 138 | fsparam_flag ("v3", Opt_v), |
| 139 | fsparam_flag ("v4", Opt_v), |
| 140 | fsparam_flag ("v4.0", Opt_v), |
| 141 | fsparam_flag ("v4.1", Opt_v), |
| 142 | fsparam_flag ("v4.2", Opt_v), |
| 143 | fsparam_string("vers", Opt_vers), |
| 144 | fsparam_u32 ("wsize", Opt_wsize), |
| 145 | {} |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | enum { |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 149 | Opt_local_lock_all, |
| 150 | Opt_local_lock_flock, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 151 | Opt_local_lock_none, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 152 | Opt_local_lock_posix, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | enum { |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 156 | Opt_lookupcache_all, |
| 157 | Opt_lookupcache_none, |
| 158 | Opt_lookupcache_positive, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 159 | }; |
| 160 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 161 | static const struct fs_parameter_enum nfs_param_enums[] = { |
| 162 | { Opt_local_lock, "all", Opt_local_lock_all }, |
| 163 | { Opt_local_lock, "flock", Opt_local_lock_flock }, |
| 164 | { Opt_local_lock, "none", Opt_local_lock_none }, |
| 165 | { Opt_local_lock, "posix", Opt_local_lock_posix }, |
| 166 | { Opt_lookupcache, "all", Opt_lookupcache_all }, |
| 167 | { Opt_lookupcache, "none", Opt_lookupcache_none }, |
| 168 | { Opt_lookupcache, "pos", Opt_lookupcache_positive }, |
| 169 | { Opt_lookupcache, "positive", Opt_lookupcache_positive }, |
| 170 | {} |
| 171 | }; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 172 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 173 | static const struct fs_parameter_description nfs_fs_parameters = { |
| 174 | .name = "nfs", |
| 175 | .specs = nfs_param_specs, |
| 176 | .enums = nfs_param_enums, |
| 177 | }; |
| 178 | |
| 179 | enum { |
| 180 | Opt_vers_2, |
| 181 | Opt_vers_3, |
| 182 | Opt_vers_4, |
| 183 | Opt_vers_4_0, |
| 184 | Opt_vers_4_1, |
| 185 | Opt_vers_4_2, |
| 186 | }; |
| 187 | |
| 188 | static const struct constant_table nfs_vers_tokens[] = { |
| 189 | { "2", Opt_vers_2 }, |
| 190 | { "3", Opt_vers_3 }, |
| 191 | { "4", Opt_vers_4 }, |
| 192 | { "4.0", Opt_vers_4_0 }, |
| 193 | { "4.1", Opt_vers_4_1 }, |
| 194 | { "4.2", Opt_vers_4_2 }, |
| 195 | }; |
| 196 | |
| 197 | enum { |
| 198 | Opt_xprt_rdma, |
| 199 | Opt_xprt_rdma6, |
| 200 | Opt_xprt_tcp, |
| 201 | Opt_xprt_tcp6, |
| 202 | Opt_xprt_udp, |
| 203 | Opt_xprt_udp6, |
| 204 | nr__Opt_xprt |
| 205 | }; |
| 206 | |
| 207 | static const struct constant_table nfs_xprt_protocol_tokens[nr__Opt_xprt] = { |
| 208 | { "rdma", Opt_xprt_rdma }, |
| 209 | { "rdma6", Opt_xprt_rdma6 }, |
| 210 | { "tcp", Opt_xprt_tcp }, |
| 211 | { "tcp6", Opt_xprt_tcp6 }, |
| 212 | { "udp", Opt_xprt_udp }, |
| 213 | { "udp6", Opt_xprt_udp6 }, |
| 214 | }; |
| 215 | |
| 216 | enum { |
| 217 | Opt_sec_krb5, |
| 218 | Opt_sec_krb5i, |
| 219 | Opt_sec_krb5p, |
| 220 | Opt_sec_lkey, |
| 221 | Opt_sec_lkeyi, |
| 222 | Opt_sec_lkeyp, |
| 223 | Opt_sec_none, |
| 224 | Opt_sec_spkm, |
| 225 | Opt_sec_spkmi, |
| 226 | Opt_sec_spkmp, |
| 227 | Opt_sec_sys, |
| 228 | nr__Opt_sec |
| 229 | }; |
| 230 | |
| 231 | static const struct constant_table nfs_secflavor_tokens[] = { |
| 232 | { "krb5", Opt_sec_krb5 }, |
| 233 | { "krb5i", Opt_sec_krb5i }, |
| 234 | { "krb5p", Opt_sec_krb5p }, |
| 235 | { "lkey", Opt_sec_lkey }, |
| 236 | { "lkeyi", Opt_sec_lkeyi }, |
| 237 | { "lkeyp", Opt_sec_lkeyp }, |
| 238 | { "none", Opt_sec_none }, |
| 239 | { "null", Opt_sec_none }, |
| 240 | { "spkm3", Opt_sec_spkm }, |
| 241 | { "spkm3i", Opt_sec_spkmi }, |
| 242 | { "spkm3p", Opt_sec_spkmp }, |
| 243 | { "sys", Opt_sec_sys }, |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 244 | }; |
| 245 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 246 | /* |
| 247 | * Sanity-check a server address provided by the mount command. |
| 248 | * |
| 249 | * Address family must be initialized, and address must not be |
| 250 | * the ANY address for that family. |
| 251 | */ |
| 252 | static int nfs_verify_server_address(struct sockaddr *addr) |
| 253 | { |
| 254 | switch (addr->sa_family) { |
| 255 | case AF_INET: { |
| 256 | struct sockaddr_in *sa = (struct sockaddr_in *)addr; |
| 257 | return sa->sin_addr.s_addr != htonl(INADDR_ANY); |
| 258 | } |
| 259 | case AF_INET6: { |
| 260 | struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; |
| 261 | return !ipv6_addr_any(sa); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | dfprintk(MOUNT, "NFS: Invalid IP address specified\n"); |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Sanity check the NFS transport protocol. |
| 271 | * |
| 272 | */ |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 273 | static void nfs_validate_transport_protocol(struct nfs_fs_context *ctx) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 274 | { |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 275 | switch (ctx->nfs_server.protocol) { |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 276 | case XPRT_TRANSPORT_UDP: |
| 277 | case XPRT_TRANSPORT_TCP: |
| 278 | case XPRT_TRANSPORT_RDMA: |
| 279 | break; |
| 280 | default: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 281 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * For text based NFSv2/v3 mounts, the mount protocol transport default |
| 287 | * settings should depend upon the specified NFS transport. |
| 288 | */ |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 289 | static void nfs_set_mount_transport_protocol(struct nfs_fs_context *ctx) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 290 | { |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 291 | nfs_validate_transport_protocol(ctx); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 292 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 293 | if (ctx->mount_server.protocol == XPRT_TRANSPORT_UDP || |
| 294 | ctx->mount_server.protocol == XPRT_TRANSPORT_TCP) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 295 | return; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 296 | switch (ctx->nfs_server.protocol) { |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 297 | case XPRT_TRANSPORT_UDP: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 298 | ctx->mount_server.protocol = XPRT_TRANSPORT_UDP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 299 | break; |
| 300 | case XPRT_TRANSPORT_TCP: |
| 301 | case XPRT_TRANSPORT_RDMA: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 302 | ctx->mount_server.protocol = XPRT_TRANSPORT_TCP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * Add 'flavor' to 'auth_info' if not already present. |
| 308 | * Returns true if 'flavor' ends up in the list, false otherwise |
| 309 | */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 310 | static int nfs_auth_info_add(struct fs_context *fc, |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 311 | struct nfs_auth_info *auth_info, |
| 312 | rpc_authflavor_t flavor) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 313 | { |
| 314 | unsigned int i; |
| 315 | unsigned int max_flavor_len = ARRAY_SIZE(auth_info->flavors); |
| 316 | |
| 317 | /* make sure this flavor isn't already in the list */ |
| 318 | for (i = 0; i < auth_info->flavor_len; i++) { |
| 319 | if (flavor == auth_info->flavors[i]) |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 320 | return 0; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 323 | if (auth_info->flavor_len + 1 >= max_flavor_len) |
| 324 | return nfs_invalf(fc, "NFS: too many sec= flavors"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 325 | |
| 326 | auth_info->flavors[auth_info->flavor_len++] = flavor; |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 327 | return 0; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /* |
| 331 | * Parse the value of the 'sec=' option. |
| 332 | */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 333 | static int nfs_parse_security_flavors(struct fs_context *fc, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 334 | struct fs_parameter *param) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 335 | { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 336 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 337 | rpc_authflavor_t pseudoflavor; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 338 | char *string = param->string, *p; |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 339 | int ret; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 340 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 341 | dfprintk(MOUNT, "NFS: parsing %s=%s option\n", param->key, param->string); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 342 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 343 | while ((p = strsep(&string, ":")) != NULL) { |
| 344 | if (!*p) |
| 345 | continue; |
| 346 | switch (lookup_constant(nfs_secflavor_tokens, p, -1)) { |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 347 | case Opt_sec_none: |
| 348 | pseudoflavor = RPC_AUTH_NULL; |
| 349 | break; |
| 350 | case Opt_sec_sys: |
| 351 | pseudoflavor = RPC_AUTH_UNIX; |
| 352 | break; |
| 353 | case Opt_sec_krb5: |
| 354 | pseudoflavor = RPC_AUTH_GSS_KRB5; |
| 355 | break; |
| 356 | case Opt_sec_krb5i: |
| 357 | pseudoflavor = RPC_AUTH_GSS_KRB5I; |
| 358 | break; |
| 359 | case Opt_sec_krb5p: |
| 360 | pseudoflavor = RPC_AUTH_GSS_KRB5P; |
| 361 | break; |
| 362 | case Opt_sec_lkey: |
| 363 | pseudoflavor = RPC_AUTH_GSS_LKEY; |
| 364 | break; |
| 365 | case Opt_sec_lkeyi: |
| 366 | pseudoflavor = RPC_AUTH_GSS_LKEYI; |
| 367 | break; |
| 368 | case Opt_sec_lkeyp: |
| 369 | pseudoflavor = RPC_AUTH_GSS_LKEYP; |
| 370 | break; |
| 371 | case Opt_sec_spkm: |
| 372 | pseudoflavor = RPC_AUTH_GSS_SPKM; |
| 373 | break; |
| 374 | case Opt_sec_spkmi: |
| 375 | pseudoflavor = RPC_AUTH_GSS_SPKMI; |
| 376 | break; |
| 377 | case Opt_sec_spkmp: |
| 378 | pseudoflavor = RPC_AUTH_GSS_SPKMP; |
| 379 | break; |
| 380 | default: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 381 | return nfs_invalf(fc, "NFS: sec=%s option not recognized", p); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 384 | ret = nfs_auth_info_add(fc, &ctx->auth_info, pseudoflavor); |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 385 | if (ret < 0) |
| 386 | return ret; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 387 | } |
| 388 | |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 389 | return 0; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 390 | } |
| 391 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 392 | static int nfs_parse_version_string(struct fs_context *fc, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 393 | const char *string) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 394 | { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 395 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 396 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 397 | ctx->flags &= ~NFS_MOUNT_VER3; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 398 | switch (lookup_constant(nfs_vers_tokens, string, -1)) { |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 399 | case Opt_vers_2: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 400 | ctx->version = 2; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 401 | break; |
| 402 | case Opt_vers_3: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 403 | ctx->flags |= NFS_MOUNT_VER3; |
| 404 | ctx->version = 3; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 405 | break; |
| 406 | case Opt_vers_4: |
| 407 | /* Backward compatibility option. In future, |
| 408 | * the mount program should always supply |
| 409 | * a NFSv4 minor version number. |
| 410 | */ |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 411 | ctx->version = 4; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 412 | break; |
| 413 | case Opt_vers_4_0: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 414 | ctx->version = 4; |
| 415 | ctx->minorversion = 0; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 416 | break; |
| 417 | case Opt_vers_4_1: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 418 | ctx->version = 4; |
| 419 | ctx->minorversion = 1; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 420 | break; |
| 421 | case Opt_vers_4_2: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 422 | ctx->version = 4; |
| 423 | ctx->minorversion = 2; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 424 | break; |
| 425 | default: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 426 | return nfs_invalf(fc, "NFS: Unsupported NFS version"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 427 | } |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 428 | return 0; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 429 | } |
| 430 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 431 | /* |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 432 | * Parse a single mount parameter. |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 433 | */ |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 434 | static int nfs_fs_context_parse_param(struct fs_context *fc, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 435 | struct fs_parameter *param) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 436 | { |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 437 | struct fs_parse_result result; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 438 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 439 | unsigned short protofamily, mountfamily; |
| 440 | unsigned int len; |
| 441 | int ret, opt; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 442 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 443 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", param->key); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 444 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 445 | opt = fs_parse(fc, &nfs_fs_parameters, param, &result); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 446 | if (opt < 0) |
| 447 | return ctx->sloppy ? 1 : opt; |
| 448 | |
| 449 | switch (opt) { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 450 | case Opt_source: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 451 | if (fc->source) |
| 452 | return nfs_invalf(fc, "NFS: Multiple sources not supported"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 453 | fc->source = param->string; |
| 454 | param->string = NULL; |
| 455 | break; |
| 456 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 457 | /* |
| 458 | * boolean options: foo/nofoo |
| 459 | */ |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 460 | case Opt_soft: |
| 461 | ctx->flags |= NFS_MOUNT_SOFT; |
| 462 | ctx->flags &= ~NFS_MOUNT_SOFTERR; |
| 463 | break; |
| 464 | case Opt_softerr: |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame^] | 465 | ctx->flags |= NFS_MOUNT_SOFTERR | NFS_MOUNT_SOFTREVAL; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 466 | ctx->flags &= ~NFS_MOUNT_SOFT; |
| 467 | break; |
| 468 | case Opt_hard: |
Trond Myklebust | c74dfe9 | 2020-01-06 15:39:37 -0500 | [diff] [blame^] | 469 | ctx->flags &= ~(NFS_MOUNT_SOFT | |
| 470 | NFS_MOUNT_SOFTERR | |
| 471 | NFS_MOUNT_SOFTREVAL); |
| 472 | break; |
| 473 | case Opt_softreval: |
| 474 | if (result.negated) |
| 475 | ctx->flags &= ~NFS_MOUNT_SOFTREVAL; |
| 476 | else |
| 477 | ctx->flags &= NFS_MOUNT_SOFTREVAL; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 478 | break; |
| 479 | case Opt_posix: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 480 | if (result.negated) |
| 481 | ctx->flags &= ~NFS_MOUNT_POSIX; |
| 482 | else |
| 483 | ctx->flags |= NFS_MOUNT_POSIX; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 484 | break; |
| 485 | case Opt_cto: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 486 | if (result.negated) |
| 487 | ctx->flags |= NFS_MOUNT_NOCTO; |
| 488 | else |
| 489 | ctx->flags &= ~NFS_MOUNT_NOCTO; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 490 | break; |
| 491 | case Opt_ac: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 492 | if (result.negated) |
| 493 | ctx->flags |= NFS_MOUNT_NOAC; |
| 494 | else |
| 495 | ctx->flags &= ~NFS_MOUNT_NOAC; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 496 | break; |
| 497 | case Opt_lock: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 498 | if (result.negated) { |
| 499 | ctx->flags |= NFS_MOUNT_NONLM; |
| 500 | ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL); |
| 501 | } else { |
| 502 | ctx->flags &= ~NFS_MOUNT_NONLM; |
| 503 | ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL); |
| 504 | } |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 505 | break; |
| 506 | case Opt_udp: |
| 507 | ctx->flags &= ~NFS_MOUNT_TCP; |
| 508 | ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
| 509 | break; |
| 510 | case Opt_tcp: |
| 511 | ctx->flags |= NFS_MOUNT_TCP; |
| 512 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
| 513 | break; |
| 514 | case Opt_rdma: |
| 515 | ctx->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 516 | ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 517 | xprt_load_transport(param->key); |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 518 | break; |
| 519 | case Opt_acl: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 520 | if (result.negated) |
| 521 | ctx->flags |= NFS_MOUNT_NOACL; |
| 522 | else |
| 523 | ctx->flags &= ~NFS_MOUNT_NOACL; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 524 | break; |
| 525 | case Opt_rdirplus: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 526 | if (result.negated) |
| 527 | ctx->flags |= NFS_MOUNT_NORDIRPLUS; |
| 528 | else |
| 529 | ctx->flags &= ~NFS_MOUNT_NORDIRPLUS; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 530 | break; |
| 531 | case Opt_sharecache: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 532 | if (result.negated) |
| 533 | ctx->flags |= NFS_MOUNT_UNSHARED; |
| 534 | else |
| 535 | ctx->flags &= ~NFS_MOUNT_UNSHARED; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 536 | break; |
| 537 | case Opt_resvport: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 538 | if (result.negated) |
| 539 | ctx->flags |= NFS_MOUNT_NORESVPORT; |
| 540 | else |
| 541 | ctx->flags &= ~NFS_MOUNT_NORESVPORT; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 542 | break; |
| 543 | case Opt_fscache: |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 544 | kfree(ctx->fscache_uniq); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 545 | ctx->fscache_uniq = param->string; |
| 546 | param->string = NULL; |
| 547 | if (result.negated) |
| 548 | ctx->options &= ~NFS_OPTION_FSCACHE; |
| 549 | else |
| 550 | ctx->options |= NFS_OPTION_FSCACHE; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 551 | break; |
| 552 | case Opt_migration: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 553 | if (result.negated) |
| 554 | ctx->options &= ~NFS_OPTION_MIGRATION; |
| 555 | else |
| 556 | ctx->options |= NFS_OPTION_MIGRATION; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 557 | break; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 558 | |
| 559 | /* |
| 560 | * options that take numeric values |
| 561 | */ |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 562 | case Opt_port: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 563 | if (result.uint_32 > USHRT_MAX) |
| 564 | goto out_of_bounds; |
| 565 | ctx->nfs_server.port = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 566 | break; |
| 567 | case Opt_rsize: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 568 | ctx->rsize = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 569 | break; |
| 570 | case Opt_wsize: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 571 | ctx->wsize = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 572 | break; |
| 573 | case Opt_bsize: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 574 | ctx->bsize = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 575 | break; |
| 576 | case Opt_timeo: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 577 | if (result.uint_32 < 1 || result.uint_32 > INT_MAX) |
| 578 | goto out_of_bounds; |
| 579 | ctx->timeo = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 580 | break; |
| 581 | case Opt_retrans: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 582 | if (result.uint_32 > INT_MAX) |
| 583 | goto out_of_bounds; |
| 584 | ctx->retrans = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 585 | break; |
| 586 | case Opt_acregmin: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 587 | ctx->acregmin = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 588 | break; |
| 589 | case Opt_acregmax: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 590 | ctx->acregmax = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 591 | break; |
| 592 | case Opt_acdirmin: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 593 | ctx->acdirmin = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 594 | break; |
| 595 | case Opt_acdirmax: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 596 | ctx->acdirmax = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 597 | break; |
| 598 | case Opt_actimeo: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 599 | ctx->acregmin = result.uint_32; |
| 600 | ctx->acregmax = result.uint_32; |
| 601 | ctx->acdirmin = result.uint_32; |
| 602 | ctx->acdirmax = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 603 | break; |
| 604 | case Opt_namelen: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 605 | ctx->namlen = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 606 | break; |
| 607 | case Opt_mountport: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 608 | if (result.uint_32 > USHRT_MAX) |
| 609 | goto out_of_bounds; |
| 610 | ctx->mount_server.port = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 611 | break; |
| 612 | case Opt_mountvers: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 613 | if (result.uint_32 < NFS_MNT_VERSION || |
| 614 | result.uint_32 > NFS_MNT3_VERSION) |
| 615 | goto out_of_bounds; |
| 616 | ctx->mount_server.version = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 617 | break; |
| 618 | case Opt_minorversion: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 619 | if (result.uint_32 > NFS4_MAX_MINOR_VERSION) |
| 620 | goto out_of_bounds; |
| 621 | ctx->minorversion = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 622 | break; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 623 | |
| 624 | /* |
| 625 | * options that take text values |
| 626 | */ |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 627 | case Opt_v: |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 628 | ret = nfs_parse_version_string(fc, param->key + 1); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 629 | if (ret < 0) |
| 630 | return ret; |
| 631 | break; |
| 632 | case Opt_vers: |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 633 | ret = nfs_parse_version_string(fc, param->string); |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 634 | if (ret < 0) |
| 635 | return ret; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 636 | break; |
| 637 | case Opt_sec: |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 638 | ret = nfs_parse_security_flavors(fc, param); |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 639 | if (ret < 0) |
| 640 | return ret; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 641 | break; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 642 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 643 | case Opt_proto: |
| 644 | protofamily = AF_INET; |
| 645 | switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) { |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 646 | case Opt_xprt_udp6: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 647 | protofamily = AF_INET6; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 648 | /* fall through */ |
| 649 | case Opt_xprt_udp: |
| 650 | ctx->flags &= ~NFS_MOUNT_TCP; |
| 651 | ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 652 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 653 | case Opt_xprt_tcp6: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 654 | protofamily = AF_INET6; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 655 | /* fall through */ |
| 656 | case Opt_xprt_tcp: |
| 657 | ctx->flags |= NFS_MOUNT_TCP; |
| 658 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
| 659 | break; |
| 660 | case Opt_xprt_rdma6: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 661 | protofamily = AF_INET6; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 662 | /* fall through */ |
| 663 | case Opt_xprt_rdma: |
| 664 | /* vector side protocols to TCP */ |
| 665 | ctx->flags |= NFS_MOUNT_TCP; |
| 666 | ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 667 | xprt_load_transport(param->string); |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 668 | break; |
| 669 | default: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 670 | return nfs_invalf(fc, "NFS: Unrecognized transport protocol"); |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 671 | } |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 672 | |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 673 | ctx->protofamily = protofamily; |
| 674 | break; |
| 675 | |
| 676 | case Opt_mountproto: |
| 677 | mountfamily = AF_INET; |
| 678 | switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) { |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 679 | case Opt_xprt_udp6: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 680 | mountfamily = AF_INET6; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 681 | /* fall through */ |
| 682 | case Opt_xprt_udp: |
| 683 | ctx->mount_server.protocol = XPRT_TRANSPORT_UDP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 684 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 685 | case Opt_xprt_tcp6: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 686 | mountfamily = AF_INET6; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 687 | /* fall through */ |
| 688 | case Opt_xprt_tcp: |
| 689 | ctx->mount_server.protocol = XPRT_TRANSPORT_TCP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 690 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 691 | case Opt_xprt_rdma: /* not used for side protocols */ |
| 692 | default: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 693 | return nfs_invalf(fc, "NFS: Unrecognized transport protocol"); |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 694 | } |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 695 | ctx->mountfamily = mountfamily; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 696 | break; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 697 | |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 698 | case Opt_addr: |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 699 | len = rpc_pton(fc->net_ns, param->string, param->size, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 700 | &ctx->nfs_server.address, |
| 701 | sizeof(ctx->nfs_server._address)); |
| 702 | if (len == 0) |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 703 | goto out_invalid_address; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 704 | ctx->nfs_server.addrlen = len; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 705 | break; |
| 706 | case Opt_clientaddr: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 707 | kfree(ctx->client_address); |
| 708 | ctx->client_address = param->string; |
| 709 | param->string = NULL; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 710 | break; |
| 711 | case Opt_mounthost: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 712 | kfree(ctx->mount_server.hostname); |
| 713 | ctx->mount_server.hostname = param->string; |
| 714 | param->string = NULL; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 715 | break; |
| 716 | case Opt_mountaddr: |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 717 | len = rpc_pton(fc->net_ns, param->string, param->size, |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 718 | &ctx->mount_server.address, |
| 719 | sizeof(ctx->mount_server._address)); |
| 720 | if (len == 0) |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 721 | goto out_invalid_address; |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 722 | ctx->mount_server.addrlen = len; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 723 | break; |
| 724 | case Opt_nconnect: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 725 | if (result.uint_32 < 1 || result.uint_32 > NFS_MAX_CONNECTIONS) |
| 726 | goto out_of_bounds; |
| 727 | ctx->nfs_server.nconnect = result.uint_32; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 728 | break; |
| 729 | case Opt_lookupcache: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 730 | switch (result.uint_32) { |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 731 | case Opt_lookupcache_all: |
| 732 | ctx->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 733 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 734 | case Opt_lookupcache_positive: |
| 735 | ctx->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE; |
| 736 | ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 737 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 738 | case Opt_lookupcache_none: |
| 739 | ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 740 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 741 | default: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 742 | goto out_invalid_value; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 743 | } |
| 744 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 745 | case Opt_local_lock: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 746 | switch (result.uint_32) { |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 747 | case Opt_local_lock_all: |
| 748 | ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | |
| 749 | NFS_MOUNT_LOCAL_FCNTL); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 750 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 751 | case Opt_local_lock_flock: |
| 752 | ctx->flags |= NFS_MOUNT_LOCAL_FLOCK; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 753 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 754 | case Opt_local_lock_posix: |
| 755 | ctx->flags |= NFS_MOUNT_LOCAL_FCNTL; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 756 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 757 | case Opt_local_lock_none: |
| 758 | ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | |
| 759 | NFS_MOUNT_LOCAL_FCNTL); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 760 | break; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 761 | default: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 762 | goto out_invalid_value; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 763 | } |
| 764 | break; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 765 | |
| 766 | /* |
| 767 | * Special options |
| 768 | */ |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 769 | case Opt_sloppy: |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 770 | ctx->sloppy = true; |
David Howells | cbd071b | 2019-12-10 07:31:08 -0500 | [diff] [blame] | 771 | dfprintk(MOUNT, "NFS: relaxing parsing rules\n"); |
| 772 | break; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 773 | } |
| 774 | |
David Howells | f8ee01e | 2019-12-10 07:31:07 -0500 | [diff] [blame] | 775 | return 0; |
| 776 | |
David Howells | f8ee01e | 2019-12-10 07:31:07 -0500 | [diff] [blame] | 777 | out_invalid_value: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 778 | return nfs_invalf(fc, "NFS: Bad mount option value specified"); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 779 | out_invalid_address: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 780 | return nfs_invalf(fc, "NFS: Bad IP address specified"); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 781 | out_of_bounds: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 782 | nfs_invalf(fc, "NFS: Value for '%s' out of range", param->key); |
Scott Mayhew | e38bb23 | 2019-12-10 07:31:12 -0500 | [diff] [blame] | 783 | return -ERANGE; |
| 784 | } |
| 785 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 786 | /* |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 787 | * Split fc->source into "hostname:export_path". |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 788 | * |
| 789 | * The leftmost colon demarks the split between the server's hostname |
| 790 | * and the export path. If the hostname starts with a left square |
| 791 | * bracket, then it may contain colons. |
| 792 | * |
| 793 | * Note: caller frees hostname and export path, even on error. |
| 794 | */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 795 | static int nfs_parse_source(struct fs_context *fc, |
| 796 | size_t maxnamlen, size_t maxpathlen) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 797 | { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 798 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 799 | const char *dev_name = fc->source; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 800 | size_t len; |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 801 | const char *end; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 802 | |
| 803 | if (unlikely(!dev_name || !*dev_name)) { |
| 804 | dfprintk(MOUNT, "NFS: device name not specified\n"); |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
| 808 | /* Is the host name protected with square brakcets? */ |
| 809 | if (*dev_name == '[') { |
| 810 | end = strchr(++dev_name, ']'); |
| 811 | if (end == NULL || end[1] != ':') |
| 812 | goto out_bad_devname; |
| 813 | |
| 814 | len = end - dev_name; |
| 815 | end++; |
| 816 | } else { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 817 | const char *comma; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 818 | |
| 819 | end = strchr(dev_name, ':'); |
| 820 | if (end == NULL) |
| 821 | goto out_bad_devname; |
| 822 | len = end - dev_name; |
| 823 | |
| 824 | /* kill possible hostname list: not supported */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 825 | comma = memchr(dev_name, ',', len); |
| 826 | if (comma) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 827 | len = comma - dev_name; |
| 828 | } |
| 829 | |
| 830 | if (len > maxnamlen) |
| 831 | goto out_hostname; |
| 832 | |
| 833 | /* N.B. caller will free nfs_server.hostname in all cases */ |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 834 | ctx->nfs_server.hostname = kmemdup_nul(dev_name, len, GFP_KERNEL); |
| 835 | if (!ctx->nfs_server.hostname) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 836 | goto out_nomem; |
| 837 | len = strlen(++end); |
| 838 | if (len > maxpathlen) |
| 839 | goto out_path; |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 840 | ctx->nfs_server.export_path = kmemdup_nul(end, len, GFP_KERNEL); |
| 841 | if (!ctx->nfs_server.export_path) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 842 | goto out_nomem; |
| 843 | |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 844 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", ctx->nfs_server.export_path); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 845 | return 0; |
| 846 | |
| 847 | out_bad_devname: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 848 | return nfs_invalf(fc, "NFS: device name not in host:path format"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 849 | out_nomem: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 850 | nfs_errorf(fc, "NFS: not enough memory to parse device name"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 851 | return -ENOMEM; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 852 | out_hostname: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 853 | nfs_errorf(fc, "NFS: server hostname too long"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 854 | return -ENAMETOOLONG; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 855 | out_path: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 856 | nfs_errorf(fc, "NFS: export pathname too long"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 857 | return -ENAMETOOLONG; |
| 858 | } |
| 859 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 860 | static inline bool is_remount_fc(struct fs_context *fc) |
| 861 | { |
| 862 | return fc->root != NULL; |
| 863 | } |
| 864 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 865 | /* |
David Howells | e558100 | 2019-12-10 07:31:10 -0500 | [diff] [blame] | 866 | * Parse monolithic NFS2/NFS3 mount data |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 867 | * - fills in the mount root filehandle |
| 868 | * |
| 869 | * For option strings, user space handles the following behaviors: |
| 870 | * |
| 871 | * + DNS: mapping server host name to IP address ("addr=" option) |
| 872 | * |
| 873 | * + failure mode: how to behave if a mount request can't be handled |
| 874 | * immediately ("fg/bg" option) |
| 875 | * |
| 876 | * + retry: how often to retry a mount request ("retry=" option) |
| 877 | * |
| 878 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, |
| 879 | * mountproto=tcp after mountproto=udp, and so on |
| 880 | */ |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 881 | static int nfs23_parse_monolithic(struct fs_context *fc, |
| 882 | struct nfs_mount_data *data) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 883 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 884 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 885 | struct nfs_fh *mntfh = ctx->mntfh; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 886 | struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 887 | int extra_flags = NFS_MOUNT_LEGACY_INTERFACE; |
| 888 | |
| 889 | if (data == NULL) |
| 890 | goto out_no_data; |
| 891 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 892 | ctx->version = NFS_DEFAULT_VERSION; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 893 | switch (data->version) { |
| 894 | case 1: |
| 895 | data->namlen = 0; /* fall through */ |
| 896 | case 2: |
| 897 | data->bsize = 0; /* fall through */ |
| 898 | case 3: |
| 899 | if (data->flags & NFS_MOUNT_VER3) |
| 900 | goto out_no_v3; |
| 901 | data->root.size = NFS2_FHSIZE; |
| 902 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 903 | /* Turn off security negotiation */ |
| 904 | extra_flags |= NFS_MOUNT_SECFLAVOUR; |
| 905 | /* fall through */ |
| 906 | case 4: |
| 907 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 908 | goto out_no_sec; |
| 909 | /* fall through */ |
| 910 | case 5: |
| 911 | memset(data->context, 0, sizeof(data->context)); |
| 912 | /* fall through */ |
| 913 | case 6: |
| 914 | if (data->flags & NFS_MOUNT_VER3) { |
| 915 | if (data->root.size > NFS3_FHSIZE || data->root.size == 0) |
| 916 | goto out_invalid_fh; |
| 917 | mntfh->size = data->root.size; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 918 | ctx->version = 3; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 919 | } else { |
| 920 | mntfh->size = NFS2_FHSIZE; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 921 | ctx->version = 2; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | |
| 925 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 926 | if (mntfh->size < sizeof(mntfh->data)) |
| 927 | memset(mntfh->data + mntfh->size, 0, |
| 928 | sizeof(mntfh->data) - mntfh->size); |
| 929 | |
| 930 | /* |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 931 | * Translate to nfs_fs_context, which nfs_fill_super |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 932 | * can deal with. |
| 933 | */ |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 934 | ctx->flags = data->flags & NFS_MOUNT_FLAGMASK; |
| 935 | ctx->flags |= extra_flags; |
| 936 | ctx->rsize = data->rsize; |
| 937 | ctx->wsize = data->wsize; |
| 938 | ctx->timeo = data->timeo; |
| 939 | ctx->retrans = data->retrans; |
| 940 | ctx->acregmin = data->acregmin; |
| 941 | ctx->acregmax = data->acregmax; |
| 942 | ctx->acdirmin = data->acdirmin; |
| 943 | ctx->acdirmax = data->acdirmax; |
| 944 | ctx->need_mount = false; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 945 | |
| 946 | memcpy(sap, &data->addr, sizeof(data->addr)); |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 947 | ctx->nfs_server.addrlen = sizeof(data->addr); |
| 948 | ctx->nfs_server.port = ntohs(data->addr.sin_port); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 949 | if (sap->sa_family != AF_INET || |
| 950 | !nfs_verify_server_address(sap)) |
| 951 | goto out_no_address; |
| 952 | |
| 953 | if (!(data->flags & NFS_MOUNT_TCP)) |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 954 | ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 955 | /* N.B. caller will free nfs_server.hostname in all cases */ |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 956 | ctx->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 957 | if (!ctx->nfs_server.hostname) |
| 958 | goto out_nomem; |
| 959 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 960 | ctx->namlen = data->namlen; |
| 961 | ctx->bsize = data->bsize; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 962 | |
| 963 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 964 | ctx->selected_flavor = data->pseudoflavor; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 965 | else |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 966 | ctx->selected_flavor = RPC_AUTH_UNIX; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 967 | |
| 968 | if (!(data->flags & NFS_MOUNT_NONLM)) |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 969 | ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK| |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 970 | NFS_MOUNT_LOCAL_FCNTL); |
| 971 | else |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 972 | ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK| |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 973 | NFS_MOUNT_LOCAL_FCNTL); |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 974 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 975 | /* |
| 976 | * The legacy version 6 binary mount data from userspace has a |
| 977 | * field used only to transport selinux information into the |
| 978 | * the kernel. To continue to support that functionality we |
| 979 | * have a touch of selinux knowledge here in the NFS code. The |
| 980 | * userspace code converted context=blah to just blah so we are |
| 981 | * converting back to the full string selinux understands. |
| 982 | */ |
| 983 | if (data->context[0]){ |
| 984 | #ifdef CONFIG_SECURITY_SELINUX |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 985 | int ret; |
| 986 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 987 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 988 | ret = vfs_parse_fs_string(fc, "context", |
| 989 | data->context, strlen(data->context)); |
| 990 | if (ret < 0) |
| 991 | return ret; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 992 | #else |
| 993 | return -EINVAL; |
| 994 | #endif |
| 995 | } |
| 996 | |
| 997 | break; |
| 998 | default: |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 999 | goto generic; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1000 | } |
| 1001 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1002 | ctx->skip_reconfig_option_check = true; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1003 | return 0; |
| 1004 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1005 | generic: |
| 1006 | return generic_parse_monolithic(fc, data); |
| 1007 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1008 | out_no_data: |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1009 | if (is_remount_fc(fc)) { |
| 1010 | ctx->skip_reconfig_option_check = true; |
| 1011 | return 0; |
| 1012 | } |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1013 | return nfs_invalf(fc, "NFS: mount program didn't pass any mount data"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1014 | |
| 1015 | out_no_v3: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1016 | return nfs_invalf(fc, "NFS: nfs_mount_data version does not support v3"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1017 | |
| 1018 | out_no_sec: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1019 | return nfs_invalf(fc, "NFS: nfs_mount_data version supports only AUTH_SYS"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1020 | |
| 1021 | out_nomem: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1022 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1023 | return -ENOMEM; |
| 1024 | |
| 1025 | out_no_address: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1026 | return nfs_invalf(fc, "NFS: mount program didn't pass remote address"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1027 | |
| 1028 | out_invalid_fh: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1029 | return nfs_invalf(fc, "NFS: invalid root filehandle"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | #if IS_ENABLED(CONFIG_NFS_V4) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1033 | /* |
| 1034 | * Validate NFSv4 mount options |
| 1035 | */ |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1036 | static int nfs4_parse_monolithic(struct fs_context *fc, |
| 1037 | struct nfs4_mount_data *data) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1038 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1039 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1040 | struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1041 | char *c; |
| 1042 | |
| 1043 | if (data == NULL) |
| 1044 | goto out_no_data; |
| 1045 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1046 | ctx->version = 4; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1047 | |
| 1048 | switch (data->version) { |
| 1049 | case 1: |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1050 | if (data->host_addrlen > sizeof(ctx->nfs_server.address)) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1051 | goto out_no_address; |
| 1052 | if (data->host_addrlen == 0) |
| 1053 | goto out_no_address; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1054 | ctx->nfs_server.addrlen = data->host_addrlen; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1055 | if (copy_from_user(sap, data->host_addr, data->host_addrlen)) |
| 1056 | return -EFAULT; |
| 1057 | if (!nfs_verify_server_address(sap)) |
| 1058 | goto out_no_address; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1059 | ctx->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1060 | |
| 1061 | if (data->auth_flavourlen) { |
| 1062 | rpc_authflavor_t pseudoflavor; |
| 1063 | if (data->auth_flavourlen > 1) |
| 1064 | goto out_inval_auth; |
| 1065 | if (copy_from_user(&pseudoflavor, |
| 1066 | data->auth_flavours, |
| 1067 | sizeof(pseudoflavor))) |
| 1068 | return -EFAULT; |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1069 | ctx->selected_flavor = pseudoflavor; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1070 | } else |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1071 | ctx->selected_flavor = RPC_AUTH_UNIX; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1072 | |
| 1073 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 1074 | if (IS_ERR(c)) |
| 1075 | return PTR_ERR(c); |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1076 | ctx->nfs_server.hostname = c; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1077 | |
| 1078 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 1079 | if (IS_ERR(c)) |
| 1080 | return PTR_ERR(c); |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1081 | ctx->nfs_server.export_path = c; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1082 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
| 1083 | |
| 1084 | c = strndup_user(data->client_addr.data, 16); |
| 1085 | if (IS_ERR(c)) |
| 1086 | return PTR_ERR(c); |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1087 | ctx->client_address = c; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1088 | |
| 1089 | /* |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1090 | * Translate to nfs_fs_context, which nfs_fill_super |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1091 | * can deal with. |
| 1092 | */ |
| 1093 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1094 | ctx->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 1095 | ctx->rsize = data->rsize; |
| 1096 | ctx->wsize = data->wsize; |
| 1097 | ctx->timeo = data->timeo; |
| 1098 | ctx->retrans = data->retrans; |
| 1099 | ctx->acregmin = data->acregmin; |
| 1100 | ctx->acregmax = data->acregmax; |
| 1101 | ctx->acdirmin = data->acdirmin; |
| 1102 | ctx->acdirmax = data->acdirmax; |
| 1103 | ctx->nfs_server.protocol = data->proto; |
| 1104 | nfs_validate_transport_protocol(ctx); |
| 1105 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1106 | goto out_invalid_transport_udp; |
| 1107 | |
| 1108 | break; |
| 1109 | default: |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1110 | goto generic; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1111 | } |
| 1112 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1113 | ctx->skip_reconfig_option_check = true; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1114 | return 0; |
| 1115 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1116 | generic: |
| 1117 | return generic_parse_monolithic(fc, data); |
| 1118 | |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1119 | out_no_data: |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1120 | if (is_remount_fc(fc)) { |
| 1121 | ctx->skip_reconfig_option_check = true; |
| 1122 | return 0; |
| 1123 | } |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1124 | return nfs_invalf(fc, "NFS4: mount program didn't pass any mount data"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1125 | |
| 1126 | out_inval_auth: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1127 | return nfs_invalf(fc, "NFS4: Invalid number of RPC auth flavours %d", |
| 1128 | data->auth_flavourlen); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1129 | |
| 1130 | out_no_address: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1131 | return nfs_invalf(fc, "NFS4: mount program didn't pass remote address"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1132 | |
| 1133 | out_invalid_transport_udp: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1134 | return nfs_invalf(fc, "NFSv4: Unsupported transport protocol udp"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1135 | } |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1136 | #endif |
| 1137 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1138 | /* |
| 1139 | * Parse a monolithic block of data from sys_mount(). |
| 1140 | */ |
| 1141 | static int nfs_fs_context_parse_monolithic(struct fs_context *fc, |
| 1142 | void *data) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1143 | { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1144 | if (fc->fs_type == &nfs_fs_type) |
| 1145 | return nfs23_parse_monolithic(fc, data); |
| 1146 | |
| 1147 | #if IS_ENABLED(CONFIG_NFS_V4) |
| 1148 | if (fc->fs_type == &nfs4_fs_type) |
| 1149 | return nfs4_parse_monolithic(fc, data); |
| 1150 | #endif |
| 1151 | |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1152 | return nfs_invalf(fc, "NFS: Unsupported monolithic data version"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | * Validate the preparsed information in the config. |
| 1157 | */ |
| 1158 | static int nfs_fs_context_validate(struct fs_context *fc) |
| 1159 | { |
| 1160 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 1161 | struct nfs_subversion *nfs_mod; |
| 1162 | struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1163 | int max_namelen = PAGE_SIZE; |
| 1164 | int max_pathlen = NFS_MAXPATHLEN; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1165 | int port = 0; |
| 1166 | int ret; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1167 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1168 | if (!fc->source) |
| 1169 | goto out_no_device_name; |
| 1170 | |
| 1171 | /* Check for sanity first. */ |
| 1172 | if (ctx->minorversion && ctx->version != 4) |
| 1173 | goto out_minorversion_mismatch; |
| 1174 | |
| 1175 | if (ctx->options & NFS_OPTION_MIGRATION && |
| 1176 | (ctx->version != 4 || ctx->minorversion != 0)) |
| 1177 | goto out_migration_misuse; |
| 1178 | |
| 1179 | /* Verify that any proto=/mountproto= options match the address |
| 1180 | * families in the addr=/mountaddr= options. |
| 1181 | */ |
| 1182 | if (ctx->protofamily != AF_UNSPEC && |
| 1183 | ctx->protofamily != ctx->nfs_server.address.sa_family) |
| 1184 | goto out_proto_mismatch; |
| 1185 | |
| 1186 | if (ctx->mountfamily != AF_UNSPEC) { |
| 1187 | if (ctx->mount_server.addrlen) { |
| 1188 | if (ctx->mountfamily != ctx->mount_server.address.sa_family) |
| 1189 | goto out_mountproto_mismatch; |
| 1190 | } else { |
| 1191 | if (ctx->mountfamily != ctx->nfs_server.address.sa_family) |
| 1192 | goto out_mountproto_mismatch; |
| 1193 | } |
| 1194 | } |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1195 | |
| 1196 | if (!nfs_verify_server_address(sap)) |
| 1197 | goto out_no_address; |
| 1198 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1199 | if (ctx->version == 4) { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1200 | if (IS_ENABLED(CONFIG_NFS_V4)) { |
| 1201 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_RDMA) |
| 1202 | port = NFS_RDMA_PORT; |
| 1203 | else |
| 1204 | port = NFS_PORT; |
| 1205 | max_namelen = NFS4_MAXNAMLEN; |
| 1206 | max_pathlen = NFS4_MAXPATHLEN; |
| 1207 | nfs_validate_transport_protocol(ctx); |
| 1208 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) |
| 1209 | goto out_invalid_transport_udp; |
| 1210 | ctx->flags &= ~(NFS_MOUNT_NONLM | NFS_MOUNT_NOACL | |
| 1211 | NFS_MOUNT_VER3 | NFS_MOUNT_LOCAL_FLOCK | |
| 1212 | NFS_MOUNT_LOCAL_FCNTL); |
| 1213 | } else { |
| 1214 | goto out_v4_not_compiled; |
| 1215 | } |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1216 | } else { |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1217 | nfs_set_mount_transport_protocol(ctx); |
| 1218 | if (ctx->nfs_server.protocol == XPRT_TRANSPORT_RDMA) |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1219 | port = NFS_RDMA_PORT; |
| 1220 | } |
| 1221 | |
David Howells | 5eb005c | 2019-12-10 07:31:06 -0500 | [diff] [blame] | 1222 | nfs_set_port(sap, &ctx->nfs_server.port, port); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1223 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1224 | ret = nfs_parse_source(fc, max_namelen, max_pathlen); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1225 | if (ret < 0) |
| 1226 | return ret; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1227 | |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1228 | /* Load the NFS protocol module if we haven't done so yet */ |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1229 | if (!ctx->nfs_mod) { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1230 | nfs_mod = get_nfs_version(ctx->version); |
| 1231 | if (IS_ERR(nfs_mod)) { |
| 1232 | ret = PTR_ERR(nfs_mod); |
| 1233 | goto out_version_unavailable; |
| 1234 | } |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1235 | ctx->nfs_mod = nfs_mod; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1236 | } |
| 1237 | return 0; |
| 1238 | |
| 1239 | out_no_device_name: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1240 | return nfs_invalf(fc, "NFS: Device name not specified"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1241 | out_v4_not_compiled: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1242 | nfs_errorf(fc, "NFS: NFSv4 is not compiled into kernel"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1243 | return -EPROTONOSUPPORT; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1244 | out_invalid_transport_udp: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1245 | return nfs_invalf(fc, "NFSv4: Unsupported transport protocol udp"); |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1246 | out_no_address: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1247 | return nfs_invalf(fc, "NFS: mount program didn't pass remote address"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1248 | out_mountproto_mismatch: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1249 | return nfs_invalf(fc, "NFS: Mount server address does not match mountproto= option"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1250 | out_proto_mismatch: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1251 | return nfs_invalf(fc, "NFS: Server address does not match proto= option"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1252 | out_minorversion_mismatch: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1253 | return nfs_invalf(fc, "NFS: Mount option vers=%u does not support minorversion=%u", |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1254 | ctx->version, ctx->minorversion); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1255 | out_migration_misuse: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1256 | return nfs_invalf(fc, "NFS: 'Migration' not supported for this NFS version"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1257 | out_version_unavailable: |
Scott Mayhew | ce8866f0 | 2019-12-10 07:31:15 -0500 | [diff] [blame] | 1258 | nfs_errorf(fc, "NFS: Version unavailable"); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1259 | return ret; |
David Howells | 9954bf9 | 2019-12-10 07:31:04 -0500 | [diff] [blame] | 1260 | } |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1261 | |
| 1262 | /* |
| 1263 | * Create an NFS superblock by the appropriate method. |
| 1264 | */ |
| 1265 | static int nfs_get_tree(struct fs_context *fc) |
| 1266 | { |
| 1267 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 1268 | int err = nfs_fs_context_validate(fc); |
| 1269 | |
| 1270 | if (err) |
| 1271 | return err; |
| 1272 | if (!ctx->internal) |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1273 | return ctx->nfs_mod->rpc_ops->try_get_tree(fc); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1274 | else |
| 1275 | return nfs_get_tree_common(fc); |
| 1276 | } |
| 1277 | |
| 1278 | /* |
| 1279 | * Handle duplication of a configuration. The caller copied *src into *sc, but |
| 1280 | * it can't deal with resource pointers in the filesystem context, so we have |
| 1281 | * to do that. We need to clear pointers, copy data or get extra refs as |
| 1282 | * appropriate. |
| 1283 | */ |
| 1284 | static int nfs_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc) |
| 1285 | { |
| 1286 | struct nfs_fs_context *src = nfs_fc2context(src_fc), *ctx; |
| 1287 | |
| 1288 | ctx = kmemdup(src, sizeof(struct nfs_fs_context), GFP_KERNEL); |
| 1289 | if (!ctx) |
| 1290 | return -ENOMEM; |
| 1291 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1292 | ctx->mntfh = nfs_alloc_fhandle(); |
| 1293 | if (!ctx->mntfh) { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1294 | kfree(ctx); |
| 1295 | return -ENOMEM; |
| 1296 | } |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1297 | nfs_copy_fh(ctx->mntfh, src->mntfh); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1298 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1299 | __module_get(ctx->nfs_mod->owner); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1300 | ctx->client_address = NULL; |
| 1301 | ctx->mount_server.hostname = NULL; |
| 1302 | ctx->nfs_server.export_path = NULL; |
| 1303 | ctx->nfs_server.hostname = NULL; |
| 1304 | ctx->fscache_uniq = NULL; |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1305 | ctx->clone_data.fattr = NULL; |
| 1306 | fc->fs_private = ctx; |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | static void nfs_fs_context_free(struct fs_context *fc) |
| 1311 | { |
| 1312 | struct nfs_fs_context *ctx = nfs_fc2context(fc); |
| 1313 | |
| 1314 | if (ctx) { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1315 | if (ctx->server) |
| 1316 | nfs_free_server(ctx->server); |
| 1317 | if (ctx->nfs_mod) |
| 1318 | put_nfs_version(ctx->nfs_mod); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1319 | kfree(ctx->client_address); |
| 1320 | kfree(ctx->mount_server.hostname); |
| 1321 | kfree(ctx->nfs_server.export_path); |
| 1322 | kfree(ctx->nfs_server.hostname); |
| 1323 | kfree(ctx->fscache_uniq); |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1324 | nfs_free_fhandle(ctx->mntfh); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1325 | nfs_free_fattr(ctx->clone_data.fattr); |
| 1326 | kfree(ctx); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static const struct fs_context_operations nfs_fs_context_ops = { |
| 1331 | .free = nfs_fs_context_free, |
| 1332 | .dup = nfs_fs_context_dup, |
| 1333 | .parse_param = nfs_fs_context_parse_param, |
| 1334 | .parse_monolithic = nfs_fs_context_parse_monolithic, |
| 1335 | .get_tree = nfs_get_tree, |
| 1336 | .reconfigure = nfs_reconfigure, |
| 1337 | }; |
| 1338 | |
| 1339 | /* |
| 1340 | * Prepare superblock configuration. We use the namespaces attached to the |
| 1341 | * context. This may be the current process's namespaces, or it may be a |
| 1342 | * container's namespaces. |
| 1343 | */ |
| 1344 | static int nfs_init_fs_context(struct fs_context *fc) |
| 1345 | { |
| 1346 | struct nfs_fs_context *ctx; |
| 1347 | |
| 1348 | ctx = kzalloc(sizeof(struct nfs_fs_context), GFP_KERNEL); |
| 1349 | if (unlikely(!ctx)) |
| 1350 | return -ENOMEM; |
| 1351 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1352 | ctx->mntfh = nfs_alloc_fhandle(); |
| 1353 | if (unlikely(!ctx->mntfh)) { |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1354 | kfree(ctx); |
| 1355 | return -ENOMEM; |
| 1356 | } |
| 1357 | |
| 1358 | ctx->protofamily = AF_UNSPEC; |
| 1359 | ctx->mountfamily = AF_UNSPEC; |
| 1360 | ctx->mount_server.port = NFS_UNSPEC_PORT; |
| 1361 | |
| 1362 | if (fc->root) { |
| 1363 | /* reconfigure, start with the current config */ |
| 1364 | struct nfs_server *nfss = fc->root->d_sb->s_fs_info; |
| 1365 | struct net *net = nfss->nfs_client->cl_net; |
| 1366 | |
| 1367 | ctx->flags = nfss->flags; |
| 1368 | ctx->rsize = nfss->rsize; |
| 1369 | ctx->wsize = nfss->wsize; |
| 1370 | ctx->retrans = nfss->client->cl_timeout->to_retries; |
| 1371 | ctx->selected_flavor = nfss->client->cl_auth->au_flavor; |
| 1372 | ctx->acregmin = nfss->acregmin / HZ; |
| 1373 | ctx->acregmax = nfss->acregmax / HZ; |
| 1374 | ctx->acdirmin = nfss->acdirmin / HZ; |
| 1375 | ctx->acdirmax = nfss->acdirmax / HZ; |
| 1376 | ctx->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; |
| 1377 | ctx->nfs_server.port = nfss->port; |
| 1378 | ctx->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; |
| 1379 | ctx->version = nfss->nfs_client->rpc_ops->version; |
| 1380 | ctx->minorversion = nfss->nfs_client->cl_minorversion; |
| 1381 | |
| 1382 | memcpy(&ctx->nfs_server.address, &nfss->nfs_client->cl_addr, |
| 1383 | ctx->nfs_server.addrlen); |
| 1384 | |
| 1385 | if (fc->net_ns != net) { |
| 1386 | put_net(fc->net_ns); |
| 1387 | fc->net_ns = get_net(net); |
| 1388 | } |
| 1389 | |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 1390 | ctx->nfs_mod = nfss->nfs_client->cl_nfs_mod; |
| 1391 | __module_get(ctx->nfs_mod->owner); |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1392 | } else { |
| 1393 | /* defaults */ |
| 1394 | ctx->timeo = NFS_UNSPEC_TIMEO; |
| 1395 | ctx->retrans = NFS_UNSPEC_RETRANS; |
| 1396 | ctx->acregmin = NFS_DEF_ACREGMIN; |
| 1397 | ctx->acregmax = NFS_DEF_ACREGMAX; |
| 1398 | ctx->acdirmin = NFS_DEF_ACDIRMIN; |
| 1399 | ctx->acdirmax = NFS_DEF_ACDIRMAX; |
| 1400 | ctx->nfs_server.port = NFS_UNSPEC_PORT; |
| 1401 | ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
| 1402 | ctx->selected_flavor = RPC_AUTH_MAXFLAVOR; |
| 1403 | ctx->minorversion = 0; |
| 1404 | ctx->need_mount = true; |
| 1405 | } |
David Howells | f2aedb7 | 2019-12-10 07:31:13 -0500 | [diff] [blame] | 1406 | fc->fs_private = ctx; |
| 1407 | fc->ops = &nfs_fs_context_ops; |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
| 1411 | struct file_system_type nfs_fs_type = { |
| 1412 | .owner = THIS_MODULE, |
| 1413 | .name = "nfs", |
| 1414 | .init_fs_context = nfs_init_fs_context, |
| 1415 | .parameters = &nfs_fs_parameters, |
| 1416 | .kill_sb = nfs_kill_super, |
| 1417 | .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA, |
| 1418 | }; |
| 1419 | MODULE_ALIAS_FS("nfs"); |
| 1420 | EXPORT_SYMBOL_GPL(nfs_fs_type); |
| 1421 | |
| 1422 | #if IS_ENABLED(CONFIG_NFS_V4) |
| 1423 | struct file_system_type nfs4_fs_type = { |
| 1424 | .owner = THIS_MODULE, |
| 1425 | .name = "nfs4", |
| 1426 | .init_fs_context = nfs_init_fs_context, |
| 1427 | .parameters = &nfs_fs_parameters, |
| 1428 | .kill_sb = nfs_kill_super, |
| 1429 | .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA, |
| 1430 | }; |
| 1431 | MODULE_ALIAS_FS("nfs4"); |
| 1432 | MODULE_ALIAS("nfs4"); |
| 1433 | EXPORT_SYMBOL_GPL(nfs4_fs_type); |
| 1434 | #endif /* CONFIG_NFS_V4 */ |