xref: /linux/fs/smb/client/fs_context.c (revision f5c31bcf604db54470868f3118a60dc4a9ba8813)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *   Copyright (C) 2020, Microsoft Corporation.
4  *
5  *   Author(s): Steve French <stfrench@microsoft.com>
6  *              David Howells <dhowells@redhat.com>
7  */
8 
9 /*
10 #include <linux/module.h>
11 #include <linux/nsproxy.h>
12 #include <linux/slab.h>
13 #include <linux/magic.h>
14 #include <linux/security.h>
15 #include <net/net_namespace.h>
16 #ifdef CONFIG_CIFS_DFS_UPCALL
17 #include "dfs_cache.h"
18 #endif
19 */
20 
21 #include <linux/ctype.h>
22 #include <linux/fs_context.h>
23 #include <linux/fs_parser.h>
24 #include <linux/fs.h>
25 #include <linux/mount.h>
26 #include <linux/parser.h>
27 #include <linux/utsname.h>
28 #include "cifsfs.h"
29 #include "cifspdu.h"
30 #include "cifsglob.h"
31 #include "cifsproto.h"
32 #include "cifs_unicode.h"
33 #include "cifs_debug.h"
34 #include "cifs_fs_sb.h"
35 #include "ntlmssp.h"
36 #include "nterr.h"
37 #include "rfc1002pdu.h"
38 #include "fs_context.h"
39 
40 static DEFINE_MUTEX(cifs_mount_mutex);
41 
42 static const match_table_t cifs_smb_version_tokens = {
43 	{ Smb_1, SMB1_VERSION_STRING },
44 	{ Smb_20, SMB20_VERSION_STRING},
45 	{ Smb_21, SMB21_VERSION_STRING },
46 	{ Smb_30, SMB30_VERSION_STRING },
47 	{ Smb_302, SMB302_VERSION_STRING },
48 	{ Smb_302, ALT_SMB302_VERSION_STRING },
49 	{ Smb_311, SMB311_VERSION_STRING },
50 	{ Smb_311, ALT_SMB311_VERSION_STRING },
51 	{ Smb_3any, SMB3ANY_VERSION_STRING },
52 	{ Smb_default, SMBDEFAULT_VERSION_STRING },
53 	{ Smb_version_err, NULL }
54 };
55 
56 static const match_table_t cifs_secflavor_tokens = {
57 	{ Opt_sec_krb5, "krb5" },
58 	{ Opt_sec_krb5i, "krb5i" },
59 	{ Opt_sec_krb5p, "krb5p" },
60 	{ Opt_sec_ntlmsspi, "ntlmsspi" },
61 	{ Opt_sec_ntlmssp, "ntlmssp" },
62 	{ Opt_sec_ntlmv2, "nontlm" },
63 	{ Opt_sec_ntlmv2, "ntlmv2" },
64 	{ Opt_sec_ntlmv2i, "ntlmv2i" },
65 	{ Opt_sec_none, "none" },
66 
67 	{ Opt_sec_err, NULL }
68 };
69 
70 const struct fs_parameter_spec smb3_fs_parameters[] = {
71 	/* Mount options that take no arguments */
72 	fsparam_flag_no("user_xattr", Opt_user_xattr),
73 	fsparam_flag_no("forceuid", Opt_forceuid),
74 	fsparam_flag_no("multichannel", Opt_multichannel),
75 	fsparam_flag_no("forcegid", Opt_forcegid),
76 	fsparam_flag("noblocksend", Opt_noblocksend),
77 	fsparam_flag("noautotune", Opt_noautotune),
78 	fsparam_flag("nolease", Opt_nolease),
79 	fsparam_flag_no("hard", Opt_hard),
80 	fsparam_flag_no("soft", Opt_soft),
81 	fsparam_flag_no("perm", Opt_perm),
82 	fsparam_flag("nodelete", Opt_nodelete),
83 	fsparam_flag_no("mapposix", Opt_mapposix),
84 	fsparam_flag("mapchars", Opt_mapchars),
85 	fsparam_flag("nomapchars", Opt_nomapchars),
86 	fsparam_flag_no("sfu", Opt_sfu),
87 	fsparam_flag("nodfs", Opt_nodfs),
88 	fsparam_flag_no("posixpaths", Opt_posixpaths),
89 	fsparam_flag_no("unix", Opt_unix),
90 	fsparam_flag_no("linux", Opt_unix),
91 	fsparam_flag_no("posix", Opt_unix),
92 	fsparam_flag("nocase", Opt_nocase),
93 	fsparam_flag("ignorecase", Opt_nocase),
94 	fsparam_flag_no("brl", Opt_brl),
95 	fsparam_flag_no("handlecache", Opt_handlecache),
96 	fsparam_flag("forcemandatorylock", Opt_forcemandatorylock),
97 	fsparam_flag("forcemand", Opt_forcemandatorylock),
98 	fsparam_flag("setuidfromacl", Opt_setuidfromacl),
99 	fsparam_flag("idsfromsid", Opt_setuidfromacl),
100 	fsparam_flag_no("setuids", Opt_setuids),
101 	fsparam_flag_no("dynperm", Opt_dynperm),
102 	fsparam_flag_no("intr", Opt_intr),
103 	fsparam_flag_no("strictsync", Opt_strictsync),
104 	fsparam_flag_no("serverino", Opt_serverino),
105 	fsparam_flag("rwpidforward", Opt_rwpidforward),
106 	fsparam_flag("cifsacl", Opt_cifsacl),
107 	fsparam_flag_no("acl", Opt_acl),
108 	fsparam_flag("locallease", Opt_locallease),
109 	fsparam_flag("sign", Opt_sign),
110 	fsparam_flag("ignore_signature", Opt_ignore_signature),
111 	fsparam_flag("signloosely", Opt_ignore_signature),
112 	fsparam_flag("seal", Opt_seal),
113 	fsparam_flag("noac", Opt_noac),
114 	fsparam_flag("fsc", Opt_fsc),
115 	fsparam_flag("mfsymlinks", Opt_mfsymlinks),
116 	fsparam_flag("multiuser", Opt_multiuser),
117 	fsparam_flag("sloppy", Opt_sloppy),
118 	fsparam_flag("nosharesock", Opt_nosharesock),
119 	fsparam_flag_no("persistenthandles", Opt_persistent),
120 	fsparam_flag_no("resilienthandles", Opt_resilient),
121 	fsparam_flag_no("tcpnodelay", Opt_tcp_nodelay),
122 	fsparam_flag("nosparse", Opt_nosparse),
123 	fsparam_flag("domainauto", Opt_domainauto),
124 	fsparam_flag("rdma", Opt_rdma),
125 	fsparam_flag("modesid", Opt_modesid),
126 	fsparam_flag("modefromsid", Opt_modesid),
127 	fsparam_flag("rootfs", Opt_rootfs),
128 	fsparam_flag("compress", Opt_compress),
129 	fsparam_flag("witness", Opt_witness),
130 
131 	/* Mount options which take numeric value */
132 	fsparam_u32("backupuid", Opt_backupuid),
133 	fsparam_u32("backupgid", Opt_backupgid),
134 	fsparam_u32("uid", Opt_uid),
135 	fsparam_u32("cruid", Opt_cruid),
136 	fsparam_u32("gid", Opt_gid),
137 	fsparam_u32("file_mode", Opt_file_mode),
138 	fsparam_u32("dirmode", Opt_dirmode),
139 	fsparam_u32("dir_mode", Opt_dirmode),
140 	fsparam_u32("port", Opt_port),
141 	fsparam_u32("min_enc_offload", Opt_min_enc_offload),
142 	fsparam_u32("retrans", Opt_retrans),
143 	fsparam_u32("esize", Opt_min_enc_offload),
144 	fsparam_u32("bsize", Opt_blocksize),
145 	fsparam_u32("rasize", Opt_rasize),
146 	fsparam_u32("rsize", Opt_rsize),
147 	fsparam_u32("wsize", Opt_wsize),
148 	fsparam_u32("actimeo", Opt_actimeo),
149 	fsparam_u32("acdirmax", Opt_acdirmax),
150 	fsparam_u32("acregmax", Opt_acregmax),
151 	fsparam_u32("closetimeo", Opt_closetimeo),
152 	fsparam_u32("echo_interval", Opt_echo_interval),
153 	fsparam_u32("max_credits", Opt_max_credits),
154 	fsparam_u32("max_cached_dirs", Opt_max_cached_dirs),
155 	fsparam_u32("handletimeout", Opt_handletimeout),
156 	fsparam_u64("snapshot", Opt_snapshot),
157 	fsparam_u32("max_channels", Opt_max_channels),
158 
159 	/* Mount options which take string value */
160 	fsparam_string("source", Opt_source),
161 	fsparam_string("user", Opt_user),
162 	fsparam_string("username", Opt_user),
163 	fsparam_string("pass", Opt_pass),
164 	fsparam_string("password", Opt_pass),
165 	fsparam_string("ip", Opt_ip),
166 	fsparam_string("addr", Opt_ip),
167 	fsparam_string("domain", Opt_domain),
168 	fsparam_string("dom", Opt_domain),
169 	fsparam_string("srcaddr", Opt_srcaddr),
170 	fsparam_string("iocharset", Opt_iocharset),
171 	fsparam_string("netbiosname", Opt_netbiosname),
172 	fsparam_string("servern", Opt_servern),
173 	fsparam_string("ver", Opt_ver),
174 	fsparam_string("vers", Opt_vers),
175 	fsparam_string("sec", Opt_sec),
176 	fsparam_string("cache", Opt_cache),
177 	fsparam_string("reparse", Opt_reparse),
178 
179 	/* Arguments that should be ignored */
180 	fsparam_flag("guest", Opt_ignore),
181 	fsparam_flag("noatime", Opt_ignore),
182 	fsparam_flag("relatime", Opt_ignore),
183 	fsparam_flag("_netdev", Opt_ignore),
184 	fsparam_flag_no("suid", Opt_ignore),
185 	fsparam_flag_no("exec", Opt_ignore),
186 	fsparam_flag_no("dev", Opt_ignore),
187 	fsparam_flag_no("mand", Opt_ignore),
188 	fsparam_flag_no("auto", Opt_ignore),
189 	fsparam_string("cred", Opt_ignore),
190 	fsparam_string("credentials", Opt_ignore),
191 	/*
192 	 * UNC and prefixpath is now extracted from Opt_source
193 	 * in the new mount API so we can just ignore them going forward.
194 	 */
195 	fsparam_string("unc", Opt_ignore),
196 	fsparam_string("prefixpath", Opt_ignore),
197 	{}
198 };
199 
200 static int
201 cifs_parse_security_flavors(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
202 {
203 
204 	substring_t args[MAX_OPT_ARGS];
205 
206 	/*
207 	 * With mount options, the last one should win. Reset any existing
208 	 * settings back to default.
209 	 */
210 	ctx->sectype = Unspecified;
211 	ctx->sign = false;
212 
213 	switch (match_token(value, cifs_secflavor_tokens, args)) {
214 	case Opt_sec_krb5p:
215 		cifs_errorf(fc, "sec=krb5p is not supported. Use sec=krb5,seal instead\n");
216 		return 1;
217 	case Opt_sec_krb5i:
218 		ctx->sign = true;
219 		fallthrough;
220 	case Opt_sec_krb5:
221 		ctx->sectype = Kerberos;
222 		break;
223 	case Opt_sec_ntlmsspi:
224 		ctx->sign = true;
225 		fallthrough;
226 	case Opt_sec_ntlmssp:
227 		ctx->sectype = RawNTLMSSP;
228 		break;
229 	case Opt_sec_ntlmv2i:
230 		ctx->sign = true;
231 		fallthrough;
232 	case Opt_sec_ntlmv2:
233 		ctx->sectype = NTLMv2;
234 		break;
235 	case Opt_sec_none:
236 		ctx->nullauth = 1;
237 		kfree(ctx->username);
238 		ctx->username = NULL;
239 		break;
240 	default:
241 		cifs_errorf(fc, "bad security option: %s\n", value);
242 		return 1;
243 	}
244 
245 	return 0;
246 }
247 
248 static const match_table_t cifs_cacheflavor_tokens = {
249 	{ Opt_cache_loose, "loose" },
250 	{ Opt_cache_strict, "strict" },
251 	{ Opt_cache_none, "none" },
252 	{ Opt_cache_ro, "ro" },
253 	{ Opt_cache_rw, "singleclient" },
254 	{ Opt_cache_err, NULL }
255 };
256 
257 static int
258 cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
259 {
260 	substring_t args[MAX_OPT_ARGS];
261 
262 	switch (match_token(value, cifs_cacheflavor_tokens, args)) {
263 	case Opt_cache_loose:
264 		ctx->direct_io = false;
265 		ctx->strict_io = false;
266 		ctx->cache_ro = false;
267 		ctx->cache_rw = false;
268 		break;
269 	case Opt_cache_strict:
270 		ctx->direct_io = false;
271 		ctx->strict_io = true;
272 		ctx->cache_ro = false;
273 		ctx->cache_rw = false;
274 		break;
275 	case Opt_cache_none:
276 		ctx->direct_io = true;
277 		ctx->strict_io = false;
278 		ctx->cache_ro = false;
279 		ctx->cache_rw = false;
280 		break;
281 	case Opt_cache_ro:
282 		ctx->direct_io = false;
283 		ctx->strict_io = false;
284 		ctx->cache_ro = true;
285 		ctx->cache_rw = false;
286 		break;
287 	case Opt_cache_rw:
288 		ctx->direct_io = false;
289 		ctx->strict_io = false;
290 		ctx->cache_ro = false;
291 		ctx->cache_rw = true;
292 		break;
293 	default:
294 		cifs_errorf(fc, "bad cache= option: %s\n", value);
295 		return 1;
296 	}
297 	return 0;
298 }
299 
300 static const match_table_t reparse_flavor_tokens = {
301 	{ Opt_reparse_default,	"default" },
302 	{ Opt_reparse_nfs,	"nfs" },
303 	{ Opt_reparse_wsl,	"wsl" },
304 	{ Opt_reparse_err,	NULL },
305 };
306 
307 static int parse_reparse_flavor(struct fs_context *fc, char *value,
308 				struct smb3_fs_context *ctx)
309 {
310 	substring_t args[MAX_OPT_ARGS];
311 
312 	switch (match_token(value, reparse_flavor_tokens, args)) {
313 	case Opt_reparse_default:
314 		ctx->reparse_type = CIFS_REPARSE_TYPE_DEFAULT;
315 		break;
316 	case Opt_reparse_nfs:
317 		ctx->reparse_type = CIFS_REPARSE_TYPE_NFS;
318 		break;
319 	case Opt_reparse_wsl:
320 		ctx->reparse_type = CIFS_REPARSE_TYPE_WSL;
321 		break;
322 	default:
323 		cifs_errorf(fc, "bad reparse= option: %s\n", value);
324 		return 1;
325 	}
326 	return 0;
327 }
328 
329 #define DUP_CTX_STR(field)						\
330 do {									\
331 	if (ctx->field) {						\
332 		new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC);	\
333 		if (new_ctx->field == NULL) {				\
334 			smb3_cleanup_fs_context_contents(new_ctx);	\
335 			return -ENOMEM;					\
336 		}							\
337 	}								\
338 } while (0)
339 
340 int
341 smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
342 {
343 	memcpy(new_ctx, ctx, sizeof(*ctx));
344 	new_ctx->prepath = NULL;
345 	new_ctx->nodename = NULL;
346 	new_ctx->username = NULL;
347 	new_ctx->password = NULL;
348 	new_ctx->server_hostname = NULL;
349 	new_ctx->domainname = NULL;
350 	new_ctx->UNC = NULL;
351 	new_ctx->source = NULL;
352 	new_ctx->iocharset = NULL;
353 	new_ctx->leaf_fullpath = NULL;
354 	/*
355 	 * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
356 	 */
357 	DUP_CTX_STR(prepath);
358 	DUP_CTX_STR(username);
359 	DUP_CTX_STR(password);
360 	DUP_CTX_STR(server_hostname);
361 	DUP_CTX_STR(UNC);
362 	DUP_CTX_STR(source);
363 	DUP_CTX_STR(domainname);
364 	DUP_CTX_STR(nodename);
365 	DUP_CTX_STR(iocharset);
366 	DUP_CTX_STR(leaf_fullpath);
367 
368 	return 0;
369 }
370 
371 static int
372 cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_context *ctx, bool is_smb3)
373 {
374 	substring_t args[MAX_OPT_ARGS];
375 
376 	switch (match_token(value, cifs_smb_version_tokens, args)) {
377 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
378 	case Smb_1:
379 		if (disable_legacy_dialects) {
380 			cifs_errorf(fc, "mount with legacy dialect disabled\n");
381 			return 1;
382 		}
383 		if (is_smb3) {
384 			cifs_errorf(fc, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
385 			return 1;
386 		}
387 		cifs_errorf(fc, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
388 		ctx->ops = &smb1_operations;
389 		ctx->vals = &smb1_values;
390 		break;
391 	case Smb_20:
392 		if (disable_legacy_dialects) {
393 			cifs_errorf(fc, "mount with legacy dialect disabled\n");
394 			return 1;
395 		}
396 		if (is_smb3) {
397 			cifs_errorf(fc, "vers=2.0 not permitted when mounting with smb3\n");
398 			return 1;
399 		}
400 		ctx->ops = &smb20_operations;
401 		ctx->vals = &smb20_values;
402 		break;
403 #else
404 	case Smb_1:
405 		cifs_errorf(fc, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
406 		return 1;
407 	case Smb_20:
408 		cifs_errorf(fc, "vers=2.0 mount not permitted when legacy dialects disabled\n");
409 		return 1;
410 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
411 	case Smb_21:
412 		ctx->ops = &smb21_operations;
413 		ctx->vals = &smb21_values;
414 		break;
415 	case Smb_30:
416 		ctx->ops = &smb30_operations;
417 		ctx->vals = &smb30_values;
418 		break;
419 	case Smb_302:
420 		ctx->ops = &smb30_operations; /* currently identical with 3.0 */
421 		ctx->vals = &smb302_values;
422 		break;
423 	case Smb_311:
424 		ctx->ops = &smb311_operations;
425 		ctx->vals = &smb311_values;
426 		break;
427 	case Smb_3any:
428 		ctx->ops = &smb30_operations; /* currently identical with 3.0 */
429 		ctx->vals = &smb3any_values;
430 		break;
431 	case Smb_default:
432 		ctx->ops = &smb30_operations;
433 		ctx->vals = &smbdefault_values;
434 		break;
435 	default:
436 		cifs_errorf(fc, "Unknown vers= option specified: %s\n", value);
437 		return 1;
438 	}
439 	return 0;
440 }
441 
442 int smb3_parse_opt(const char *options, const char *key, char **val)
443 {
444 	int rc = -ENOENT;
445 	char *opts, *orig, *p;
446 
447 	orig = opts = kstrdup(options, GFP_KERNEL);
448 	if (!opts)
449 		return -ENOMEM;
450 
451 	while ((p = strsep(&opts, ","))) {
452 		char *nval;
453 
454 		if (!*p)
455 			continue;
456 		if (strncasecmp(p, key, strlen(key)))
457 			continue;
458 		nval = strchr(p, '=');
459 		if (nval) {
460 			if (nval == p)
461 				continue;
462 			*nval++ = 0;
463 			*val = kstrdup(nval, GFP_KERNEL);
464 			rc = !*val ? -ENOMEM : 0;
465 			goto out;
466 		}
467 	}
468 out:
469 	kfree(orig);
470 	return rc;
471 }
472 
473 /*
474  * Remove duplicate path delimiters. Windows is supposed to do that
475  * but there are some bugs that prevent rename from working if there are
476  * multiple delimiters.
477  *
478  * Return a sanitized duplicate of @path or NULL for empty prefix paths.
479  * Otherwise, return ERR_PTR.
480  *
481  * @gfp indicates the GFP_* flags for kstrdup.
482  * The caller is responsible for freeing the original.
483  */
484 #define IS_DELIM(c) ((c) == '/' || (c) == '\\')
485 char *cifs_sanitize_prepath(char *prepath, gfp_t gfp)
486 {
487 	char *cursor1 = prepath, *cursor2 = prepath;
488 	char *s;
489 
490 	/* skip all prepended delimiters */
491 	while (IS_DELIM(*cursor1))
492 		cursor1++;
493 
494 	/* copy the first letter */
495 	*cursor2 = *cursor1;
496 
497 	/* copy the remainder... */
498 	while (*(cursor1++)) {
499 		/* ... skipping all duplicated delimiters */
500 		if (IS_DELIM(*cursor1) && IS_DELIM(*cursor2))
501 			continue;
502 		*(++cursor2) = *cursor1;
503 	}
504 
505 	/* if the last character is a delimiter, skip it */
506 	if (IS_DELIM(*(cursor2 - 1)))
507 		cursor2--;
508 
509 	*cursor2 = '\0';
510 	if (!*prepath)
511 		return NULL;
512 	s = kstrdup(prepath, gfp);
513 	if (!s)
514 		return ERR_PTR(-ENOMEM);
515 	return s;
516 }
517 
518 /*
519  * Return full path based on the values of @ctx->{UNC,prepath}.
520  *
521  * It is assumed that both values were already parsed by smb3_parse_devname().
522  */
523 char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx, char dirsep)
524 {
525 	size_t ulen, plen;
526 	char *s;
527 
528 	ulen = strlen(ctx->UNC);
529 	plen = ctx->prepath ? strlen(ctx->prepath) + 1 : 0;
530 
531 	s = kmalloc(ulen + plen + 1, GFP_KERNEL);
532 	if (!s)
533 		return ERR_PTR(-ENOMEM);
534 	memcpy(s, ctx->UNC, ulen);
535 	if (plen) {
536 		s[ulen] = dirsep;
537 		memcpy(s + ulen + 1, ctx->prepath, plen);
538 	}
539 	s[ulen + plen] = '\0';
540 	convert_delimiter(s, dirsep);
541 	return s;
542 }
543 
544 /*
545  * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
546  * fields with the result. Returns 0 on success and an error otherwise
547  * (e.g. ENOMEM or EINVAL)
548  */
549 int
550 smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
551 {
552 	char *pos;
553 	const char *delims = "/\\";
554 	size_t len;
555 	int rc;
556 
557 	if (unlikely(!devname || !*devname)) {
558 		cifs_dbg(VFS, "Device name not specified\n");
559 		return -EINVAL;
560 	}
561 
562 	/* make sure we have a valid UNC double delimiter prefix */
563 	len = strspn(devname, delims);
564 	if (len != 2)
565 		return -EINVAL;
566 
567 	/* find delimiter between host and sharename */
568 	pos = strpbrk(devname + 2, delims);
569 	if (!pos)
570 		return -EINVAL;
571 
572 	/* record the server hostname */
573 	kfree(ctx->server_hostname);
574 	ctx->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL);
575 	if (!ctx->server_hostname)
576 		return -ENOMEM;
577 
578 	/* skip past delimiter */
579 	++pos;
580 
581 	/* now go until next delimiter or end of string */
582 	len = strcspn(pos, delims);
583 	if (!len)
584 		return -EINVAL;
585 
586 	/* move "pos" up to delimiter or NULL */
587 	pos += len;
588 	kfree(ctx->UNC);
589 	ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
590 	if (!ctx->UNC)
591 		return -ENOMEM;
592 
593 	convert_delimiter(ctx->UNC, '\\');
594 
595 	/* skip any delimiter */
596 	if (*pos == '/' || *pos == '\\')
597 		pos++;
598 
599 	kfree(ctx->prepath);
600 	ctx->prepath = NULL;
601 
602 	/* If pos is NULL then no prepath */
603 	if (!*pos)
604 		return 0;
605 
606 	ctx->prepath = cifs_sanitize_prepath(pos, GFP_KERNEL);
607 	if (IS_ERR(ctx->prepath)) {
608 		rc = PTR_ERR(ctx->prepath);
609 		ctx->prepath = NULL;
610 		return rc;
611 	}
612 
613 	return 0;
614 }
615 
616 static void smb3_fs_context_free(struct fs_context *fc);
617 static int smb3_fs_context_parse_param(struct fs_context *fc,
618 				       struct fs_parameter *param);
619 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
620 					    void *data);
621 static int smb3_get_tree(struct fs_context *fc);
622 static int smb3_reconfigure(struct fs_context *fc);
623 
624 static const struct fs_context_operations smb3_fs_context_ops = {
625 	.free			= smb3_fs_context_free,
626 	.parse_param		= smb3_fs_context_parse_param,
627 	.parse_monolithic	= smb3_fs_context_parse_monolithic,
628 	.get_tree		= smb3_get_tree,
629 	.reconfigure		= smb3_reconfigure,
630 };
631 
632 /*
633  * Parse a monolithic block of data from sys_mount().
634  * smb3_fs_context_parse_monolithic - Parse key[=val][,key[=val]]* mount data
635  * @ctx: The superblock configuration to fill in.
636  * @data: The data to parse
637  *
638  * Parse a blob of data that's in key[=val][,key[=val]]* form.  This can be
639  * called from the ->monolithic_mount_data() fs_context operation.
640  *
641  * Returns 0 on success or the error returned by the ->parse_option() fs_context
642  * operation on failure.
643  */
644 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
645 					   void *data)
646 {
647 	char *options = data, *key;
648 	int ret = 0;
649 
650 	if (!options)
651 		return 0;
652 
653 	ret = security_sb_eat_lsm_opts(options, &fc->security);
654 	if (ret)
655 		return ret;
656 
657 	/* BB Need to add support for sep= here TBD */
658 	while ((key = strsep(&options, ",")) != NULL) {
659 		size_t len;
660 		char *value;
661 
662 		if (*key == 0)
663 			break;
664 
665 		/* Check if following character is the deliminator If yes,
666 		 * we have encountered a double deliminator reset the NULL
667 		 * character to the deliminator
668 		 */
669 		while (options && options[0] == ',') {
670 			len = strlen(key);
671 			strcpy(key + len, options);
672 			options = strchr(options, ',');
673 			if (options)
674 				*options++ = 0;
675 		}
676 
677 
678 		len = 0;
679 		value = strchr(key, '=');
680 		if (value) {
681 			if (value == key)
682 				continue;
683 			*value++ = 0;
684 			len = strlen(value);
685 		}
686 
687 		ret = vfs_parse_fs_string(fc, key, value, len);
688 		if (ret < 0)
689 			break;
690 	}
691 
692 	return ret;
693 }
694 
695 /*
696  * Validate the preparsed information in the config.
697  */
698 static int smb3_fs_context_validate(struct fs_context *fc)
699 {
700 	struct smb3_fs_context *ctx = smb3_fc2context(fc);
701 
702 	if (ctx->rdma && ctx->vals->protocol_id < SMB30_PROT_ID) {
703 		cifs_errorf(fc, "SMB Direct requires Version >=3.0\n");
704 		return -EOPNOTSUPP;
705 	}
706 
707 #ifndef CONFIG_KEYS
708 	/* Muliuser mounts require CONFIG_KEYS support */
709 	if (ctx->multiuser) {
710 		cifs_errorf(fc, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
711 		return -1;
712 	}
713 #endif
714 
715 	if (ctx->got_version == false)
716 		pr_warn_once("No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3.1.1), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3.1.1 (or even SMB3 or SMB2.1) specify vers=1.0 on mount.\n");
717 
718 
719 	if (!ctx->UNC) {
720 		cifs_errorf(fc, "CIFS mount error: No usable UNC path provided in device string!\n");
721 		return -1;
722 	}
723 
724 	/* make sure UNC has a share name */
725 	if (strlen(ctx->UNC) < 3 || !strchr(ctx->UNC + 3, '\\')) {
726 		cifs_errorf(fc, "Malformed UNC. Unable to find share name.\n");
727 		return -ENOENT;
728 	}
729 
730 	if (!ctx->got_ip) {
731 		int len;
732 		const char *slash;
733 
734 		/* No ip= option specified? Try to get it from UNC */
735 		/* Use the address part of the UNC. */
736 		slash = strchr(&ctx->UNC[2], '\\');
737 		len = slash - &ctx->UNC[2];
738 		if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
739 					  &ctx->UNC[2], len)) {
740 			pr_err("Unable to determine destination address\n");
741 			return -EHOSTUNREACH;
742 		}
743 	}
744 
745 	/* set the port that we got earlier */
746 	cifs_set_port((struct sockaddr *)&ctx->dstaddr, ctx->port);
747 
748 	if (ctx->override_uid && !ctx->uid_specified) {
749 		ctx->override_uid = 0;
750 		pr_notice("ignoring forceuid mount option specified with no uid= option\n");
751 	}
752 
753 	if (ctx->override_gid && !ctx->gid_specified) {
754 		ctx->override_gid = 0;
755 		pr_notice("ignoring forcegid mount option specified with no gid= option\n");
756 	}
757 
758 	return 0;
759 }
760 
761 static int smb3_get_tree_common(struct fs_context *fc)
762 {
763 	struct smb3_fs_context *ctx = smb3_fc2context(fc);
764 	struct dentry *root;
765 	int rc = 0;
766 
767 	root = cifs_smb3_do_mount(fc->fs_type, 0, ctx);
768 	if (IS_ERR(root))
769 		return PTR_ERR(root);
770 
771 	fc->root = root;
772 
773 	return rc;
774 }
775 
776 /*
777  * Create an SMB3 superblock from the parameters passed.
778  */
779 static int smb3_get_tree(struct fs_context *fc)
780 {
781 	int err = smb3_fs_context_validate(fc);
782 	int ret;
783 
784 	if (err)
785 		return err;
786 	mutex_lock(&cifs_mount_mutex);
787 	ret = smb3_get_tree_common(fc);
788 	mutex_unlock(&cifs_mount_mutex);
789 	return ret;
790 }
791 
792 static void smb3_fs_context_free(struct fs_context *fc)
793 {
794 	struct smb3_fs_context *ctx = smb3_fc2context(fc);
795 
796 	smb3_cleanup_fs_context(ctx);
797 }
798 
799 /*
800  * Compare the old and new proposed context during reconfigure
801  * and check if the changes are compatible.
802  */
803 static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
804 				       struct smb3_fs_context *new_ctx,
805 				       struct smb3_fs_context *old_ctx, bool need_recon)
806 {
807 	if (new_ctx->posix_paths != old_ctx->posix_paths) {
808 		cifs_errorf(fc, "can not change posixpaths during remount\n");
809 		return -EINVAL;
810 	}
811 	if (new_ctx->sectype != old_ctx->sectype) {
812 		cifs_errorf(fc, "can not change sec during remount\n");
813 		return -EINVAL;
814 	}
815 	if (new_ctx->multiuser != old_ctx->multiuser) {
816 		cifs_errorf(fc, "can not change multiuser during remount\n");
817 		return -EINVAL;
818 	}
819 	if (new_ctx->UNC &&
820 	    (!old_ctx->UNC || strcmp(new_ctx->UNC, old_ctx->UNC))) {
821 		cifs_errorf(fc, "can not change UNC during remount\n");
822 		return -EINVAL;
823 	}
824 	if (new_ctx->username &&
825 	    (!old_ctx->username || strcmp(new_ctx->username, old_ctx->username))) {
826 		cifs_errorf(fc, "can not change username during remount\n");
827 		return -EINVAL;
828 	}
829 	if (new_ctx->password &&
830 	    (!old_ctx->password || strcmp(new_ctx->password, old_ctx->password))) {
831 		if (need_recon == false) {
832 			cifs_errorf(fc,
833 				    "can not change password of active session during remount\n");
834 			return -EINVAL;
835 		} else if (old_ctx->sectype == Kerberos) {
836 			cifs_errorf(fc,
837 				    "can not change password for Kerberos via remount\n");
838 			return -EINVAL;
839 		}
840 	}
841 	if (new_ctx->domainname &&
842 	    (!old_ctx->domainname || strcmp(new_ctx->domainname, old_ctx->domainname))) {
843 		cifs_errorf(fc, "can not change domainname during remount\n");
844 		return -EINVAL;
845 	}
846 	if (strcmp(new_ctx->workstation_name, old_ctx->workstation_name)) {
847 		cifs_errorf(fc, "can not change workstation_name during remount\n");
848 		return -EINVAL;
849 	}
850 	if (new_ctx->nodename &&
851 	    (!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
852 		cifs_errorf(fc, "can not change nodename during remount\n");
853 		return -EINVAL;
854 	}
855 	if (new_ctx->iocharset &&
856 	    (!old_ctx->iocharset || strcmp(new_ctx->iocharset, old_ctx->iocharset))) {
857 		cifs_errorf(fc, "can not change iocharset during remount\n");
858 		return -EINVAL;
859 	}
860 
861 	return 0;
862 }
863 
864 #define STEAL_STRING(cifs_sb, ctx, field)				\
865 do {									\
866 	kfree(ctx->field);						\
867 	ctx->field = cifs_sb->ctx->field;				\
868 	cifs_sb->ctx->field = NULL;					\
869 } while (0)
870 
871 #define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field)			\
872 do {									\
873 	kfree_sensitive(ctx->field);					\
874 	ctx->field = cifs_sb->ctx->field;				\
875 	cifs_sb->ctx->field = NULL;					\
876 } while (0)
877 
878 static int smb3_reconfigure(struct fs_context *fc)
879 {
880 	struct smb3_fs_context *ctx = smb3_fc2context(fc);
881 	struct dentry *root = fc->root;
882 	struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
883 	struct cifs_ses *ses = cifs_sb_master_tcon(cifs_sb)->ses;
884 	bool need_recon = false;
885 	int rc;
886 
887 	if (ses->expired_pwd)
888 		need_recon = true;
889 
890 	rc = smb3_verify_reconfigure_ctx(fc, ctx, cifs_sb->ctx, need_recon);
891 	if (rc)
892 		return rc;
893 
894 	/*
895 	 * We can not change UNC/username/password/domainname/
896 	 * workstation_name/nodename/iocharset
897 	 * during reconnect so ignore what we have in the new context and
898 	 * just use what we already have in cifs_sb->ctx.
899 	 */
900 	STEAL_STRING(cifs_sb, ctx, UNC);
901 	STEAL_STRING(cifs_sb, ctx, source);
902 	STEAL_STRING(cifs_sb, ctx, username);
903 	if (need_recon == false)
904 		STEAL_STRING_SENSITIVE(cifs_sb, ctx, password);
905 	else  {
906 		kfree_sensitive(ses->password);
907 		ses->password = kstrdup(ctx->password, GFP_KERNEL);
908 	}
909 	STEAL_STRING(cifs_sb, ctx, domainname);
910 	STEAL_STRING(cifs_sb, ctx, nodename);
911 	STEAL_STRING(cifs_sb, ctx, iocharset);
912 
913 	/* if rsize or wsize not passed in on remount, use previous values */
914 	if (ctx->rsize == 0)
915 		ctx->rsize = cifs_sb->ctx->rsize;
916 	if (ctx->wsize == 0)
917 		ctx->wsize = cifs_sb->ctx->wsize;
918 
919 
920 	smb3_cleanup_fs_context_contents(cifs_sb->ctx);
921 	rc = smb3_fs_context_dup(cifs_sb->ctx, ctx);
922 	smb3_update_mnt_flags(cifs_sb);
923 #ifdef CONFIG_CIFS_DFS_UPCALL
924 	if (!rc)
925 		rc = dfs_cache_remount_fs(cifs_sb);
926 #endif
927 
928 	return rc;
929 }
930 
931 static int smb3_fs_context_parse_param(struct fs_context *fc,
932 				      struct fs_parameter *param)
933 {
934 	struct fs_parse_result result;
935 	struct smb3_fs_context *ctx = smb3_fc2context(fc);
936 	int i, opt;
937 	bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
938 	bool skip_parsing = false;
939 	kuid_t uid;
940 	kgid_t gid;
941 
942 	cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
943 
944 	/*
945 	 * fs_parse can not handle string options with an empty value so
946 	 * we will need special handling of them.
947 	 */
948 	if (param->type == fs_value_is_string && param->string[0] == 0) {
949 		if (!strcmp("pass", param->key) || !strcmp("password", param->key)) {
950 			skip_parsing = true;
951 			opt = Opt_pass;
952 		} else if (!strcmp("user", param->key) || !strcmp("username", param->key)) {
953 			skip_parsing = true;
954 			opt = Opt_user;
955 		}
956 	}
957 
958 	if (!skip_parsing) {
959 		opt = fs_parse(fc, smb3_fs_parameters, param, &result);
960 		if (opt < 0)
961 			return ctx->sloppy ? 1 : opt;
962 	}
963 
964 	switch (opt) {
965 	case Opt_compress:
966 		ctx->compress = true;
967 		cifs_dbg(VFS,
968 			"SMB3 compression support is experimental\n");
969 		break;
970 	case Opt_nodfs:
971 		ctx->nodfs = 1;
972 		break;
973 	case Opt_hard:
974 		if (result.negated) {
975 			if (ctx->retry == 1)
976 				cifs_dbg(VFS, "conflicting hard vs. soft mount options\n");
977 			ctx->retry = 0;
978 		} else
979 			ctx->retry = 1;
980 		break;
981 	case Opt_soft:
982 		if (result.negated)
983 			ctx->retry = 1;
984 		else {
985 			if (ctx->retry == 1)
986 				cifs_dbg(VFS, "conflicting hard vs soft mount options\n");
987 			ctx->retry = 0;
988 		}
989 		break;
990 	case Opt_mapposix:
991 		if (result.negated)
992 			ctx->remap = false;
993 		else {
994 			ctx->remap = true;
995 			ctx->sfu_remap = false; /* disable SFU mapping */
996 		}
997 		break;
998 	case Opt_mapchars:
999 		if (result.negated)
1000 			ctx->sfu_remap = false;
1001 		else {
1002 			ctx->sfu_remap = true;
1003 			ctx->remap = false; /* disable SFM (mapposix) mapping */
1004 		}
1005 		break;
1006 	case Opt_user_xattr:
1007 		if (result.negated)
1008 			ctx->no_xattr = 1;
1009 		else
1010 			ctx->no_xattr = 0;
1011 		break;
1012 	case Opt_forceuid:
1013 		if (result.negated)
1014 			ctx->override_uid = 0;
1015 		else
1016 			ctx->override_uid = 1;
1017 		break;
1018 	case Opt_forcegid:
1019 		if (result.negated)
1020 			ctx->override_gid = 0;
1021 		else
1022 			ctx->override_gid = 1;
1023 		break;
1024 	case Opt_perm:
1025 		if (result.negated)
1026 			ctx->noperm = 1;
1027 		else
1028 			ctx->noperm = 0;
1029 		break;
1030 	case Opt_dynperm:
1031 		if (result.negated)
1032 			ctx->dynperm = 0;
1033 		else
1034 			ctx->dynperm = 1;
1035 		break;
1036 	case Opt_sfu:
1037 		if (result.negated)
1038 			ctx->sfu_emul = 0;
1039 		else
1040 			ctx->sfu_emul = 1;
1041 		break;
1042 	case Opt_noblocksend:
1043 		ctx->noblocksnd = 1;
1044 		break;
1045 	case Opt_noautotune:
1046 		ctx->noautotune = 1;
1047 		break;
1048 	case Opt_nolease:
1049 		ctx->no_lease = 1;
1050 		break;
1051 	case Opt_nosparse:
1052 		ctx->no_sparse = 1;
1053 		break;
1054 	case Opt_nodelete:
1055 		ctx->nodelete = 1;
1056 		break;
1057 	case Opt_multichannel:
1058 		if (result.negated) {
1059 			ctx->multichannel = false;
1060 			ctx->max_channels = 1;
1061 		} else {
1062 			ctx->multichannel = true;
1063 			/* if number of channels not specified, default to 2 */
1064 			if (ctx->max_channels < 2)
1065 				ctx->max_channels = 2;
1066 		}
1067 		break;
1068 	case Opt_uid:
1069 		uid = make_kuid(current_user_ns(), result.uint_32);
1070 		if (!uid_valid(uid))
1071 			goto cifs_parse_mount_err;
1072 		ctx->linux_uid = uid;
1073 		ctx->uid_specified = true;
1074 		break;
1075 	case Opt_cruid:
1076 		uid = make_kuid(current_user_ns(), result.uint_32);
1077 		if (!uid_valid(uid))
1078 			goto cifs_parse_mount_err;
1079 		ctx->cred_uid = uid;
1080 		ctx->cruid_specified = true;
1081 		break;
1082 	case Opt_backupuid:
1083 		uid = make_kuid(current_user_ns(), result.uint_32);
1084 		if (!uid_valid(uid))
1085 			goto cifs_parse_mount_err;
1086 		ctx->backupuid = uid;
1087 		ctx->backupuid_specified = true;
1088 		break;
1089 	case Opt_backupgid:
1090 		gid = make_kgid(current_user_ns(), result.uint_32);
1091 		if (!gid_valid(gid))
1092 			goto cifs_parse_mount_err;
1093 		ctx->backupgid = gid;
1094 		ctx->backupgid_specified = true;
1095 		break;
1096 	case Opt_gid:
1097 		gid = make_kgid(current_user_ns(), result.uint_32);
1098 		if (!gid_valid(gid))
1099 			goto cifs_parse_mount_err;
1100 		ctx->linux_gid = gid;
1101 		ctx->gid_specified = true;
1102 		break;
1103 	case Opt_port:
1104 		ctx->port = result.uint_32;
1105 		break;
1106 	case Opt_file_mode:
1107 		ctx->file_mode = result.uint_32;
1108 		break;
1109 	case Opt_dirmode:
1110 		ctx->dir_mode = result.uint_32;
1111 		break;
1112 	case Opt_min_enc_offload:
1113 		ctx->min_offload = result.uint_32;
1114 		break;
1115 	case Opt_retrans:
1116 		ctx->retrans = result.uint_32;
1117 		break;
1118 	case Opt_blocksize:
1119 		/*
1120 		 * inode blocksize realistically should never need to be
1121 		 * less than 16K or greater than 16M and default is 1MB.
1122 		 * Note that small inode block sizes (e.g. 64K) can lead
1123 		 * to very poor performance of common tools like cp and scp
1124 		 */
1125 		if ((result.uint_32 < CIFS_MAX_MSGSIZE) ||
1126 		   (result.uint_32 > (4 * SMB3_DEFAULT_IOSIZE))) {
1127 			cifs_errorf(fc, "%s: Invalid blocksize\n",
1128 				__func__);
1129 			goto cifs_parse_mount_err;
1130 		}
1131 		ctx->bsize = result.uint_32;
1132 		ctx->got_bsize = true;
1133 		break;
1134 	case Opt_rasize:
1135 		/*
1136 		 * readahead size realistically should never need to be
1137 		 * less than 1M (CIFS_DEFAULT_IOSIZE) or greater than 32M
1138 		 * (perhaps an exception should be considered in the
1139 		 * for the case of a large number of channels
1140 		 * when multichannel is negotiated) since that would lead
1141 		 * to plenty of parallel I/O in flight to the server.
1142 		 * Note that smaller read ahead sizes would
1143 		 * hurt performance of common tools like cp and scp
1144 		 * which often trigger sequential i/o with read ahead
1145 		 */
1146 		if ((result.uint_32 > (8 * SMB3_DEFAULT_IOSIZE)) ||
1147 		    (result.uint_32 < CIFS_DEFAULT_IOSIZE)) {
1148 			cifs_errorf(fc, "%s: Invalid rasize %d vs. %d\n",
1149 				__func__, result.uint_32, SMB3_DEFAULT_IOSIZE);
1150 			goto cifs_parse_mount_err;
1151 		}
1152 		ctx->rasize = result.uint_32;
1153 		break;
1154 	case Opt_rsize:
1155 		ctx->rsize = result.uint_32;
1156 		ctx->got_rsize = true;
1157 		break;
1158 	case Opt_wsize:
1159 		ctx->wsize = result.uint_32;
1160 		ctx->got_wsize = true;
1161 		if (ctx->wsize % PAGE_SIZE != 0) {
1162 			ctx->wsize = round_down(ctx->wsize, PAGE_SIZE);
1163 			if (ctx->wsize == 0) {
1164 				ctx->wsize = PAGE_SIZE;
1165 				cifs_dbg(VFS, "wsize too small, reset to minimum %ld\n", PAGE_SIZE);
1166 			} else {
1167 				cifs_dbg(VFS,
1168 					 "wsize rounded down to %d to multiple of PAGE_SIZE %ld\n",
1169 					 ctx->wsize, PAGE_SIZE);
1170 			}
1171 		}
1172 		break;
1173 	case Opt_acregmax:
1174 		ctx->acregmax = HZ * result.uint_32;
1175 		if (ctx->acregmax > CIFS_MAX_ACTIMEO) {
1176 			cifs_errorf(fc, "acregmax too large\n");
1177 			goto cifs_parse_mount_err;
1178 		}
1179 		break;
1180 	case Opt_acdirmax:
1181 		ctx->acdirmax = HZ * result.uint_32;
1182 		if (ctx->acdirmax > CIFS_MAX_ACTIMEO) {
1183 			cifs_errorf(fc, "acdirmax too large\n");
1184 			goto cifs_parse_mount_err;
1185 		}
1186 		break;
1187 	case Opt_actimeo:
1188 		if (HZ * result.uint_32 > CIFS_MAX_ACTIMEO) {
1189 			cifs_errorf(fc, "timeout too large\n");
1190 			goto cifs_parse_mount_err;
1191 		}
1192 		if ((ctx->acdirmax != CIFS_DEF_ACTIMEO) ||
1193 		    (ctx->acregmax != CIFS_DEF_ACTIMEO)) {
1194 			cifs_errorf(fc, "actimeo ignored since acregmax or acdirmax specified\n");
1195 			break;
1196 		}
1197 		ctx->acdirmax = ctx->acregmax = HZ * result.uint_32;
1198 		break;
1199 	case Opt_closetimeo:
1200 		ctx->closetimeo = HZ * result.uint_32;
1201 		if (ctx->closetimeo > SMB3_MAX_DCLOSETIMEO) {
1202 			cifs_errorf(fc, "closetimeo too large\n");
1203 			goto cifs_parse_mount_err;
1204 		}
1205 		break;
1206 	case Opt_echo_interval:
1207 		ctx->echo_interval = result.uint_32;
1208 		break;
1209 	case Opt_snapshot:
1210 		ctx->snapshot_time = result.uint_64;
1211 		break;
1212 	case Opt_max_credits:
1213 		if (result.uint_32 < 20 || result.uint_32 > 60000) {
1214 			cifs_errorf(fc, "%s: Invalid max_credits value\n",
1215 				 __func__);
1216 			goto cifs_parse_mount_err;
1217 		}
1218 		ctx->max_credits = result.uint_32;
1219 		break;
1220 	case Opt_max_channels:
1221 		if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
1222 			cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
1223 				 __func__, CIFS_MAX_CHANNELS);
1224 			goto cifs_parse_mount_err;
1225 		}
1226 		ctx->max_channels = result.uint_32;
1227 		/* If more than one channel requested ... they want multichan */
1228 		if (result.uint_32 > 1)
1229 			ctx->multichannel = true;
1230 		break;
1231 	case Opt_max_cached_dirs:
1232 		if (result.uint_32 < 1) {
1233 			cifs_errorf(fc, "%s: Invalid max_cached_dirs, needs to be 1 or more\n",
1234 				    __func__);
1235 			goto cifs_parse_mount_err;
1236 		}
1237 		ctx->max_cached_dirs = result.uint_32;
1238 		break;
1239 	case Opt_handletimeout:
1240 		ctx->handle_timeout = result.uint_32;
1241 		if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
1242 			cifs_errorf(fc, "Invalid handle cache timeout, longer than 16 minutes\n");
1243 			goto cifs_parse_mount_err;
1244 		}
1245 		break;
1246 	case Opt_source:
1247 		kfree(ctx->UNC);
1248 		ctx->UNC = NULL;
1249 		switch (smb3_parse_devname(param->string, ctx)) {
1250 		case 0:
1251 			break;
1252 		case -ENOMEM:
1253 			cifs_errorf(fc, "Unable to allocate memory for devname\n");
1254 			goto cifs_parse_mount_err;
1255 		case -EINVAL:
1256 			cifs_errorf(fc, "Malformed UNC in devname\n");
1257 			goto cifs_parse_mount_err;
1258 		default:
1259 			cifs_errorf(fc, "Unknown error parsing devname\n");
1260 			goto cifs_parse_mount_err;
1261 		}
1262 		ctx->source = smb3_fs_context_fullpath(ctx, '/');
1263 		if (IS_ERR(ctx->source)) {
1264 			ctx->source = NULL;
1265 			cifs_errorf(fc, "OOM when copying UNC string\n");
1266 			goto cifs_parse_mount_err;
1267 		}
1268 		fc->source = kstrdup(ctx->source, GFP_KERNEL);
1269 		if (fc->source == NULL) {
1270 			cifs_errorf(fc, "OOM when copying UNC string\n");
1271 			goto cifs_parse_mount_err;
1272 		}
1273 		break;
1274 	case Opt_user:
1275 		kfree(ctx->username);
1276 		ctx->username = NULL;
1277 		if (ctx->nullauth)
1278 			break;
1279 		if (strlen(param->string) == 0) {
1280 			/* null user, ie. anonymous authentication */
1281 			ctx->nullauth = 1;
1282 			break;
1283 		}
1284 
1285 		if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
1286 		    CIFS_MAX_USERNAME_LEN) {
1287 			pr_warn("username too long\n");
1288 			goto cifs_parse_mount_err;
1289 		}
1290 		ctx->username = kstrdup(param->string, GFP_KERNEL);
1291 		if (ctx->username == NULL) {
1292 			cifs_errorf(fc, "OOM when copying username string\n");
1293 			goto cifs_parse_mount_err;
1294 		}
1295 		break;
1296 	case Opt_pass:
1297 		kfree_sensitive(ctx->password);
1298 		ctx->password = NULL;
1299 		if (strlen(param->string) == 0)
1300 			break;
1301 
1302 		ctx->password = kstrdup(param->string, GFP_KERNEL);
1303 		if (ctx->password == NULL) {
1304 			cifs_errorf(fc, "OOM when copying password string\n");
1305 			goto cifs_parse_mount_err;
1306 		}
1307 		break;
1308 	case Opt_ip:
1309 		if (strlen(param->string) == 0) {
1310 			ctx->got_ip = false;
1311 			break;
1312 		}
1313 		if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
1314 					  param->string,
1315 					  strlen(param->string))) {
1316 			pr_err("bad ip= option (%s)\n", param->string);
1317 			goto cifs_parse_mount_err;
1318 		}
1319 		ctx->got_ip = true;
1320 		break;
1321 	case Opt_domain:
1322 		if (strnlen(param->string, CIFS_MAX_DOMAINNAME_LEN)
1323 				== CIFS_MAX_DOMAINNAME_LEN) {
1324 			pr_warn("domain name too long\n");
1325 			goto cifs_parse_mount_err;
1326 		}
1327 
1328 		kfree(ctx->domainname);
1329 		ctx->domainname = kstrdup(param->string, GFP_KERNEL);
1330 		if (ctx->domainname == NULL) {
1331 			cifs_errorf(fc, "OOM when copying domainname string\n");
1332 			goto cifs_parse_mount_err;
1333 		}
1334 		cifs_dbg(FYI, "Domain name set\n");
1335 		break;
1336 	case Opt_srcaddr:
1337 		if (!cifs_convert_address(
1338 				(struct sockaddr *)&ctx->srcaddr,
1339 				param->string, strlen(param->string))) {
1340 			pr_warn("Could not parse srcaddr: %s\n",
1341 				param->string);
1342 			goto cifs_parse_mount_err;
1343 		}
1344 		break;
1345 	case Opt_iocharset:
1346 		if (strnlen(param->string, 1024) >= 65) {
1347 			pr_warn("iocharset name too long\n");
1348 			goto cifs_parse_mount_err;
1349 		}
1350 
1351 		if (strncasecmp(param->string, "default", 7) != 0) {
1352 			kfree(ctx->iocharset);
1353 			ctx->iocharset = kstrdup(param->string, GFP_KERNEL);
1354 			if (ctx->iocharset == NULL) {
1355 				cifs_errorf(fc, "OOM when copying iocharset string\n");
1356 				goto cifs_parse_mount_err;
1357 			}
1358 		}
1359 		/* if iocharset not set then load_nls_default
1360 		 * is used by caller
1361 		 */
1362 		cifs_dbg(FYI, "iocharset set to %s\n", ctx->iocharset);
1363 		break;
1364 	case Opt_netbiosname:
1365 		memset(ctx->source_rfc1001_name, 0x20,
1366 			RFC1001_NAME_LEN);
1367 		/*
1368 		 * FIXME: are there cases in which a comma can
1369 		 * be valid in workstation netbios name (and
1370 		 * need special handling)?
1371 		 */
1372 		for (i = 0; i < RFC1001_NAME_LEN; i++) {
1373 			/* don't ucase netbiosname for user */
1374 			if (param->string[i] == 0)
1375 				break;
1376 			ctx->source_rfc1001_name[i] = param->string[i];
1377 		}
1378 		/* The string has 16th byte zero still from
1379 		 * set at top of the function
1380 		 */
1381 		if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1382 			pr_warn("netbiosname longer than 15 truncated\n");
1383 		break;
1384 	case Opt_servern:
1385 		/* last byte, type, is 0x20 for servr type */
1386 		memset(ctx->target_rfc1001_name, 0x20,
1387 			RFC1001_NAME_LEN_WITH_NULL);
1388 		/*
1389 		 * BB are there cases in which a comma can be valid in this
1390 		 * workstation netbios name (and need special handling)?
1391 		 */
1392 
1393 		/* user or mount helper must uppercase the netbios name */
1394 		for (i = 0; i < 15; i++) {
1395 			if (param->string[i] == 0)
1396 				break;
1397 			ctx->target_rfc1001_name[i] = param->string[i];
1398 		}
1399 
1400 		/* The string has 16th byte zero still from set at top of function */
1401 		if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1402 			pr_warn("server netbiosname longer than 15 truncated\n");
1403 		break;
1404 	case Opt_ver:
1405 		/* version of mount userspace tools, not dialect */
1406 		/* If interface changes in mount.cifs bump to new ver */
1407 		if (strncasecmp(param->string, "1", 1) == 0) {
1408 			if (strlen(param->string) > 1) {
1409 				pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
1410 					param->string);
1411 				goto cifs_parse_mount_err;
1412 			}
1413 			/* This is the default */
1414 			break;
1415 		}
1416 		/* For all other value, error */
1417 		pr_warn("Invalid mount helper version specified\n");
1418 		goto cifs_parse_mount_err;
1419 	case Opt_vers:
1420 		/* protocol version (dialect) */
1421 		if (cifs_parse_smb_version(fc, param->string, ctx, is_smb3) != 0)
1422 			goto cifs_parse_mount_err;
1423 		ctx->got_version = true;
1424 		break;
1425 	case Opt_sec:
1426 		if (cifs_parse_security_flavors(fc, param->string, ctx) != 0)
1427 			goto cifs_parse_mount_err;
1428 		break;
1429 	case Opt_cache:
1430 		if (cifs_parse_cache_flavor(fc, param->string, ctx) != 0)
1431 			goto cifs_parse_mount_err;
1432 		break;
1433 	case Opt_witness:
1434 #ifndef CONFIG_CIFS_SWN_UPCALL
1435 		cifs_errorf(fc, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
1436 			goto cifs_parse_mount_err;
1437 #endif
1438 		ctx->witness = true;
1439 		pr_warn_once("Witness protocol support is experimental\n");
1440 		break;
1441 	case Opt_rootfs:
1442 #ifndef CONFIG_CIFS_ROOT
1443 		cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
1444 		goto cifs_parse_mount_err;
1445 #endif
1446 		ctx->rootfs = true;
1447 		break;
1448 	case Opt_posixpaths:
1449 		if (result.negated)
1450 			ctx->posix_paths = 0;
1451 		else
1452 			ctx->posix_paths = 1;
1453 		break;
1454 	case Opt_unix:
1455 		if (result.negated) {
1456 			if (ctx->linux_ext == 1)
1457 				pr_warn_once("conflicting posix mount options specified\n");
1458 			ctx->linux_ext = 0;
1459 			ctx->no_linux_ext = 1;
1460 		} else {
1461 			if (ctx->no_linux_ext == 1)
1462 				pr_warn_once("conflicting posix mount options specified\n");
1463 			ctx->linux_ext = 1;
1464 			ctx->no_linux_ext = 0;
1465 		}
1466 		break;
1467 	case Opt_nocase:
1468 		ctx->nocase = 1;
1469 		break;
1470 	case Opt_brl:
1471 		if (result.negated) {
1472 			/*
1473 			 * turn off mandatory locking in mode
1474 			 * if remote locking is turned off since the
1475 			 * local vfs will do advisory
1476 			 */
1477 			if (ctx->file_mode ==
1478 				(S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1479 				ctx->file_mode = S_IALLUGO;
1480 			ctx->nobrl =  1;
1481 		} else
1482 			ctx->nobrl =  0;
1483 		break;
1484 	case Opt_handlecache:
1485 		if (result.negated)
1486 			ctx->nohandlecache = 1;
1487 		else
1488 			ctx->nohandlecache = 0;
1489 		break;
1490 	case Opt_forcemandatorylock:
1491 		ctx->mand_lock = 1;
1492 		break;
1493 	case Opt_setuids:
1494 		ctx->setuids = result.negated;
1495 		break;
1496 	case Opt_intr:
1497 		ctx->intr = !result.negated;
1498 		break;
1499 	case Opt_setuidfromacl:
1500 		ctx->setuidfromacl = 1;
1501 		break;
1502 	case Opt_strictsync:
1503 		ctx->nostrictsync = result.negated;
1504 		break;
1505 	case Opt_serverino:
1506 		ctx->server_ino = !result.negated;
1507 		break;
1508 	case Opt_rwpidforward:
1509 		ctx->rwpidforward = 1;
1510 		break;
1511 	case Opt_modesid:
1512 		ctx->mode_ace = 1;
1513 		break;
1514 	case Opt_cifsacl:
1515 		ctx->cifs_acl = !result.negated;
1516 		break;
1517 	case Opt_acl:
1518 		ctx->no_psx_acl = result.negated;
1519 		break;
1520 	case Opt_locallease:
1521 		ctx->local_lease = 1;
1522 		break;
1523 	case Opt_sign:
1524 		ctx->sign = true;
1525 		break;
1526 	case Opt_ignore_signature:
1527 		ctx->sign = true;
1528 		ctx->ignore_signature = true;
1529 		break;
1530 	case Opt_seal:
1531 		/* we do not do the following in secFlags because seal
1532 		 * is a per tree connection (mount) not a per socket
1533 		 * or per-smb connection option in the protocol
1534 		 * vol->secFlg |= CIFSSEC_MUST_SEAL;
1535 		 */
1536 		ctx->seal = 1;
1537 		break;
1538 	case Opt_noac:
1539 		pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
1540 		break;
1541 	case Opt_fsc:
1542 #ifndef CONFIG_CIFS_FSCACHE
1543 		cifs_errorf(fc, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
1544 		goto cifs_parse_mount_err;
1545 #endif
1546 		ctx->fsc = true;
1547 		break;
1548 	case Opt_mfsymlinks:
1549 		ctx->mfsymlinks = true;
1550 		break;
1551 	case Opt_multiuser:
1552 		ctx->multiuser = true;
1553 		break;
1554 	case Opt_sloppy:
1555 		ctx->sloppy = true;
1556 		break;
1557 	case Opt_nosharesock:
1558 		ctx->nosharesock = true;
1559 		break;
1560 	case Opt_persistent:
1561 		if (result.negated) {
1562 			ctx->nopersistent = true;
1563 			if (ctx->persistent) {
1564 				cifs_errorf(fc, "persistenthandles mount options conflict\n");
1565 				goto cifs_parse_mount_err;
1566 			}
1567 		} else {
1568 			ctx->persistent = true;
1569 			if ((ctx->nopersistent) || (ctx->resilient)) {
1570 				cifs_errorf(fc, "persistenthandles mount options conflict\n");
1571 				goto cifs_parse_mount_err;
1572 			}
1573 		}
1574 		break;
1575 	case Opt_resilient:
1576 		if (result.negated) {
1577 			ctx->resilient = false; /* already the default */
1578 		} else {
1579 			ctx->resilient = true;
1580 			if (ctx->persistent) {
1581 				cifs_errorf(fc, "persistenthandles mount options conflict\n");
1582 				goto cifs_parse_mount_err;
1583 			}
1584 		}
1585 		break;
1586 	case Opt_tcp_nodelay:
1587 		/* tcp nodelay should not usually be needed since we CORK/UNCORK the socket */
1588 		if (result.negated)
1589 			ctx->sockopt_tcp_nodelay = false;
1590 		else
1591 			ctx->sockopt_tcp_nodelay = true;
1592 		break;
1593 	case Opt_domainauto:
1594 		ctx->domainauto = true;
1595 		break;
1596 	case Opt_rdma:
1597 		ctx->rdma = true;
1598 		break;
1599 	case Opt_reparse:
1600 		if (parse_reparse_flavor(fc, param->string, ctx))
1601 			goto cifs_parse_mount_err;
1602 		break;
1603 	}
1604 	/* case Opt_ignore: - is ignored as expected ... */
1605 
1606 	return 0;
1607 
1608  cifs_parse_mount_err:
1609 	kfree_sensitive(ctx->password);
1610 	ctx->password = NULL;
1611 	return -EINVAL;
1612 }
1613 
1614 int smb3_init_fs_context(struct fs_context *fc)
1615 {
1616 	struct smb3_fs_context *ctx;
1617 	char *nodename = utsname()->nodename;
1618 	int i;
1619 
1620 	ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
1621 	if (unlikely(!ctx))
1622 		return -ENOMEM;
1623 
1624 	strscpy(ctx->workstation_name, nodename, sizeof(ctx->workstation_name));
1625 
1626 	/*
1627 	 * does not have to be perfect mapping since field is
1628 	 * informational, only used for servers that do not support
1629 	 * port 445 and it can be overridden at mount time
1630 	 */
1631 	memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
1632 	for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
1633 		ctx->source_rfc1001_name[i] = toupper(nodename[i]);
1634 
1635 	ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
1636 	/*
1637 	 * null target name indicates to use *SMBSERVR default called name
1638 	 *  if we end up sending RFC1001 session initialize
1639 	 */
1640 	ctx->target_rfc1001_name[0] = 0;
1641 	ctx->cred_uid = current_uid();
1642 	ctx->linux_uid = current_uid();
1643 	ctx->linux_gid = current_gid();
1644 	/* By default 4MB read ahead size, 1MB block size */
1645 	ctx->bsize = CIFS_DEFAULT_IOSIZE; /* can improve cp performance significantly */
1646 	ctx->rasize = 0; /* 0 = use default (ie negotiated rsize) for read ahead pages */
1647 
1648 	/*
1649 	 * default to SFM style remapping of seven reserved characters
1650 	 * unless user overrides it or we negotiate CIFS POSIX where
1651 	 * it is unnecessary.  Can not simultaneously use more than one mapping
1652 	 * since then readdir could list files that open could not open
1653 	 */
1654 	ctx->remap = true;
1655 
1656 	/* default to only allowing write access to owner of the mount */
1657 	ctx->dir_mode = ctx->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
1658 
1659 	/* ctx->retry default is 0 (i.e. "soft" limited retry not hard retry) */
1660 	/* default is always to request posix paths. */
1661 	ctx->posix_paths = 1;
1662 	/* default to using server inode numbers where available */
1663 	ctx->server_ino = 1;
1664 
1665 	/* default is to use strict cifs caching semantics */
1666 	ctx->strict_io = true;
1667 
1668 	ctx->acregmax = CIFS_DEF_ACTIMEO;
1669 	ctx->acdirmax = CIFS_DEF_ACTIMEO;
1670 	ctx->closetimeo = SMB3_DEF_DCLOSETIMEO;
1671 	ctx->max_cached_dirs = MAX_CACHED_FIDS;
1672 	/* Most clients set timeout to 0, allows server to use its default */
1673 	ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
1674 
1675 	/* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
1676 	ctx->ops = &smb30_operations;
1677 	ctx->vals = &smbdefault_values;
1678 
1679 	ctx->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
1680 
1681 	/* default to no multichannel (single server connection) */
1682 	ctx->multichannel = false;
1683 	ctx->max_channels = 1;
1684 
1685 	ctx->backupuid_specified = false; /* no backup intent for a user */
1686 	ctx->backupgid_specified = false; /* no backup intent for a group */
1687 
1688 	ctx->retrans = 1;
1689 	ctx->reparse_type = CIFS_REPARSE_TYPE_DEFAULT;
1690 
1691 /*
1692  *	short int override_uid = -1;
1693  *	short int override_gid = -1;
1694  *	char *nodename = strdup(utsname()->nodename);
1695  *	struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
1696  */
1697 
1698 	fc->fs_private = ctx;
1699 	fc->ops = &smb3_fs_context_ops;
1700 	return 0;
1701 }
1702 
1703 void
1704 smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
1705 {
1706 	if (ctx == NULL)
1707 		return;
1708 
1709 	/*
1710 	 * Make sure this stays in sync with smb3_fs_context_dup()
1711 	 */
1712 	kfree(ctx->username);
1713 	ctx->username = NULL;
1714 	kfree_sensitive(ctx->password);
1715 	ctx->password = NULL;
1716 	kfree(ctx->server_hostname);
1717 	ctx->server_hostname = NULL;
1718 	kfree(ctx->UNC);
1719 	ctx->UNC = NULL;
1720 	kfree(ctx->source);
1721 	ctx->source = NULL;
1722 	kfree(ctx->domainname);
1723 	ctx->domainname = NULL;
1724 	kfree(ctx->nodename);
1725 	ctx->nodename = NULL;
1726 	kfree(ctx->iocharset);
1727 	ctx->iocharset = NULL;
1728 	kfree(ctx->prepath);
1729 	ctx->prepath = NULL;
1730 	kfree(ctx->leaf_fullpath);
1731 	ctx->leaf_fullpath = NULL;
1732 }
1733 
1734 void
1735 smb3_cleanup_fs_context(struct smb3_fs_context *ctx)
1736 {
1737 	if (!ctx)
1738 		return;
1739 	smb3_cleanup_fs_context_contents(ctx);
1740 	kfree(ctx);
1741 }
1742 
1743 void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
1744 {
1745 	struct smb3_fs_context *ctx = cifs_sb->ctx;
1746 
1747 	if (ctx->nodfs)
1748 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS;
1749 	else
1750 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_DFS;
1751 
1752 	if (ctx->noperm)
1753 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
1754 	else
1755 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_PERM;
1756 
1757 	if (ctx->setuids)
1758 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
1759 	else
1760 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SET_UID;
1761 
1762 	if (ctx->setuidfromacl)
1763 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL;
1764 	else
1765 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UID_FROM_ACL;
1766 
1767 	if (ctx->server_ino)
1768 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
1769 	else
1770 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
1771 
1772 	if (ctx->remap)
1773 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR;
1774 	else
1775 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SFM_CHR;
1776 
1777 	if (ctx->sfu_remap)
1778 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
1779 	else
1780 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SPECIAL_CHR;
1781 
1782 	if (ctx->no_xattr)
1783 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
1784 	else
1785 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_XATTR;
1786 
1787 	if (ctx->sfu_emul)
1788 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
1789 	else
1790 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UNX_EMUL;
1791 
1792 	if (ctx->nobrl)
1793 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
1794 	else
1795 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_BRL;
1796 
1797 	if (ctx->nohandlecache)
1798 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE;
1799 	else
1800 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_HANDLE_CACHE;
1801 
1802 	if (ctx->nostrictsync)
1803 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
1804 	else
1805 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOSSYNC;
1806 
1807 	if (ctx->mand_lock)
1808 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
1809 	else
1810 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOPOSIXBRL;
1811 
1812 	if (ctx->rwpidforward)
1813 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
1814 	else
1815 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_RWPIDFORWARD;
1816 
1817 	if (ctx->mode_ace)
1818 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MODE_FROM_SID;
1819 	else
1820 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MODE_FROM_SID;
1821 
1822 	if (ctx->cifs_acl)
1823 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
1824 	else
1825 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_ACL;
1826 
1827 	if (ctx->backupuid_specified)
1828 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
1829 	else
1830 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPUID;
1831 
1832 	if (ctx->backupgid_specified)
1833 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
1834 	else
1835 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPGID;
1836 
1837 	if (ctx->override_uid)
1838 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
1839 	else
1840 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_UID;
1841 
1842 	if (ctx->override_gid)
1843 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
1844 	else
1845 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_GID;
1846 
1847 	if (ctx->dynperm)
1848 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
1849 	else
1850 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DYNPERM;
1851 
1852 	if (ctx->fsc)
1853 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
1854 	else
1855 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_FSCACHE;
1856 
1857 	if (ctx->multiuser)
1858 		cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
1859 					    CIFS_MOUNT_NO_PERM);
1860 	else
1861 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MULTIUSER;
1862 
1863 
1864 	if (ctx->strict_io)
1865 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
1866 	else
1867 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_STRICT_IO;
1868 
1869 	if (ctx->direct_io)
1870 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
1871 	else
1872 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DIRECT_IO;
1873 
1874 	if (ctx->mfsymlinks)
1875 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
1876 	else
1877 		cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MF_SYMLINKS;
1878 	if (ctx->mfsymlinks) {
1879 		if (ctx->sfu_emul) {
1880 			/*
1881 			 * Our SFU ("Services for Unix" emulation does not allow
1882 			 * creating symlinks but does allow reading existing SFU
1883 			 * symlinks (it does allow both creating and reading SFU
1884 			 * style mknod and FIFOs though). When "mfsymlinks" and
1885 			 * "sfu" are both enabled at the same time, it allows
1886 			 * reading both types of symlinks, but will only create
1887 			 * them with mfsymlinks format. This allows better
1888 			 * Apple compatibility (probably better for Samba too)
1889 			 * while still recognizing old Windows style symlinks.
1890 			 */
1891 			cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
1892 		}
1893 	}
1894 	cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SHUTDOWN;
1895 
1896 	return;
1897 }
1898