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