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