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