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