1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020, Microsoft Corporation.
5 * Author(s): Steve French <stfrench@microsoft.com>
6 * David Howells <dhowells@redhat.com>
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"
21 #include <linux/ctype.h>
22 #include <linux/fs_context.h>
23 #include <linux/fs_parser.h>
25 #include <linux/mount.h>
26 #include <linux/parser.h>
27 #include <linux/utsname.h>
31 #include "cifsproto.h"
32 #include "cifs_unicode.h"
33 #include "cifs_debug.h"
34 #include "cifs_fs_sb.h"
37 #include "rfc1002pdu.h"
38 #include "fs_context.h"
40 static DEFINE_MUTEX(cifs_mount_mutex);
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 }
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" },
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),
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("esize", Opt_min_enc_offload),
143 fsparam_u32("bsize", Opt_blocksize),
144 fsparam_u32("rasize", Opt_rasize),
145 fsparam_u32("rsize", Opt_rsize),
146 fsparam_u32("wsize", Opt_wsize),
147 fsparam_u32("actimeo", Opt_actimeo),
148 fsparam_u32("acdirmax", Opt_acdirmax),
149 fsparam_u32("acregmax", Opt_acregmax),
150 fsparam_u32("closetimeo", Opt_closetimeo),
151 fsparam_u32("echo_interval", Opt_echo_interval),
152 fsparam_u32("max_credits", Opt_max_credits),
153 fsparam_u32("max_cached_dirs", Opt_max_cached_dirs),
154 fsparam_u32("handletimeout", Opt_handletimeout),
155 fsparam_u64("snapshot", Opt_snapshot),
156 fsparam_u32("max_channels", Opt_max_channels),
158 /* Mount options which take string value */
159 fsparam_string("source", Opt_source),
160 fsparam_string("user", Opt_user),
161 fsparam_string("username", Opt_user),
162 fsparam_string("pass", Opt_pass),
163 fsparam_string("password", Opt_pass),
164 fsparam_string("ip", Opt_ip),
165 fsparam_string("addr", Opt_ip),
166 fsparam_string("domain", Opt_domain),
167 fsparam_string("dom", Opt_domain),
168 fsparam_string("srcaddr", Opt_srcaddr),
169 fsparam_string("iocharset", Opt_iocharset),
170 fsparam_string("netbiosname", Opt_netbiosname),
171 fsparam_string("servern", Opt_servern),
172 fsparam_string("ver", Opt_ver),
173 fsparam_string("vers", Opt_vers),
174 fsparam_string("sec", Opt_sec),
175 fsparam_string("cache", Opt_cache),
177 /* Arguments that should be ignored */
178 fsparam_flag("guest", Opt_ignore),
179 fsparam_flag("noatime", Opt_ignore),
180 fsparam_flag("relatime", Opt_ignore),
181 fsparam_flag("_netdev", Opt_ignore),
182 fsparam_flag_no("suid", Opt_ignore),
183 fsparam_flag_no("exec", Opt_ignore),
184 fsparam_flag_no("dev", Opt_ignore),
185 fsparam_flag_no("mand", Opt_ignore),
186 fsparam_flag_no("auto", Opt_ignore),
187 fsparam_string("cred", Opt_ignore),
188 fsparam_string("credentials", Opt_ignore),
190 * UNC and prefixpath is now extracted from Opt_source
191 * in the new mount API so we can just ignore them going forward.
193 fsparam_string("unc", Opt_ignore),
194 fsparam_string("prefixpath", Opt_ignore),
199 cifs_parse_security_flavors(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
202 substring_t args[MAX_OPT_ARGS];
205 * With mount options, the last one should win. Reset any existing
206 * settings back to default.
208 ctx->sectype = Unspecified;
211 switch (match_token(value, cifs_secflavor_tokens, args)) {
213 cifs_errorf(fc, "sec=krb5p is not supported!\n");
219 ctx->sectype = Kerberos;
221 case Opt_sec_ntlmsspi:
224 case Opt_sec_ntlmssp:
225 ctx->sectype = RawNTLMSSP;
227 case Opt_sec_ntlmv2i:
231 ctx->sectype = NTLMv2;
235 kfree(ctx->username);
236 ctx->username = NULL;
239 cifs_errorf(fc, "bad security option: %s\n", value);
246 static const match_table_t cifs_cacheflavor_tokens = {
247 { Opt_cache_loose, "loose" },
248 { Opt_cache_strict, "strict" },
249 { Opt_cache_none, "none" },
250 { Opt_cache_ro, "ro" },
251 { Opt_cache_rw, "singleclient" },
252 { Opt_cache_err, NULL }
256 cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
258 substring_t args[MAX_OPT_ARGS];
260 switch (match_token(value, cifs_cacheflavor_tokens, args)) {
261 case Opt_cache_loose:
262 ctx->direct_io = false;
263 ctx->strict_io = false;
264 ctx->cache_ro = false;
265 ctx->cache_rw = false;
267 case Opt_cache_strict:
268 ctx->direct_io = false;
269 ctx->strict_io = true;
270 ctx->cache_ro = false;
271 ctx->cache_rw = false;
274 ctx->direct_io = true;
275 ctx->strict_io = false;
276 ctx->cache_ro = false;
277 ctx->cache_rw = false;
280 ctx->direct_io = false;
281 ctx->strict_io = false;
282 ctx->cache_ro = true;
283 ctx->cache_rw = false;
286 ctx->direct_io = false;
287 ctx->strict_io = false;
288 ctx->cache_ro = false;
289 ctx->cache_rw = true;
292 cifs_errorf(fc, "bad cache= option: %s\n", value);
298 #define DUP_CTX_STR(field) \
301 new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
302 if (new_ctx->field == NULL) { \
303 smb3_cleanup_fs_context_contents(new_ctx); \
310 smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
312 memcpy(new_ctx, ctx, sizeof(*ctx));
313 new_ctx->prepath = NULL;
314 new_ctx->nodename = NULL;
315 new_ctx->username = NULL;
316 new_ctx->password = NULL;
317 new_ctx->server_hostname = NULL;
318 new_ctx->domainname = NULL;
320 new_ctx->source = NULL;
321 new_ctx->iocharset = NULL;
322 new_ctx->leaf_fullpath = NULL;
324 * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
326 DUP_CTX_STR(prepath);
327 DUP_CTX_STR(username);
328 DUP_CTX_STR(password);
329 DUP_CTX_STR(server_hostname);
332 DUP_CTX_STR(domainname);
333 DUP_CTX_STR(nodename);
334 DUP_CTX_STR(iocharset);
335 DUP_CTX_STR(leaf_fullpath);
341 cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_context *ctx, bool is_smb3)
343 substring_t args[MAX_OPT_ARGS];
345 switch (match_token(value, cifs_smb_version_tokens, args)) {
346 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
348 if (disable_legacy_dialects) {
349 cifs_errorf(fc, "mount with legacy dialect disabled\n");
353 cifs_errorf(fc, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
356 cifs_errorf(fc, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
357 ctx->ops = &smb1_operations;
358 ctx->vals = &smb1_values;
361 if (disable_legacy_dialects) {
362 cifs_errorf(fc, "mount with legacy dialect disabled\n");
366 cifs_errorf(fc, "vers=2.0 not permitted when mounting with smb3\n");
369 ctx->ops = &smb20_operations;
370 ctx->vals = &smb20_values;
374 cifs_errorf(fc, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
377 cifs_errorf(fc, "vers=2.0 mount not permitted when legacy dialects disabled\n");
379 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
381 ctx->ops = &smb21_operations;
382 ctx->vals = &smb21_values;
385 ctx->ops = &smb30_operations;
386 ctx->vals = &smb30_values;
389 ctx->ops = &smb30_operations; /* currently identical with 3.0 */
390 ctx->vals = &smb302_values;
393 ctx->ops = &smb311_operations;
394 ctx->vals = &smb311_values;
397 ctx->ops = &smb30_operations; /* currently identical with 3.0 */
398 ctx->vals = &smb3any_values;
401 ctx->ops = &smb30_operations;
402 ctx->vals = &smbdefault_values;
405 cifs_errorf(fc, "Unknown vers= option specified: %s\n", value);
411 int smb3_parse_opt(const char *options, const char *key, char **val)
414 char *opts, *orig, *p;
416 orig = opts = kstrdup(options, GFP_KERNEL);
420 while ((p = strsep(&opts, ","))) {
425 if (strncasecmp(p, key, strlen(key)))
427 nval = strchr(p, '=');
432 *val = kstrdup(nval, GFP_KERNEL);
433 rc = !*val ? -ENOMEM : 0;
443 * Remove duplicate path delimiters. Windows is supposed to do that
444 * but there are some bugs that prevent rename from working if there are
445 * multiple delimiters.
447 * Return a sanitized duplicate of @path or NULL for empty prefix paths.
448 * Otherwise, return ERR_PTR.
450 * @gfp indicates the GFP_* flags for kstrdup.
451 * The caller is responsible for freeing the original.
453 #define IS_DELIM(c) ((c) == '/' || (c) == '\\')
454 char *cifs_sanitize_prepath(char *prepath, gfp_t gfp)
456 char *cursor1 = prepath, *cursor2 = prepath;
459 /* skip all prepended delimiters */
460 while (IS_DELIM(*cursor1))
463 /* copy the first letter */
466 /* copy the remainder... */
467 while (*(cursor1++)) {
468 /* ... skipping all duplicated delimiters */
469 if (IS_DELIM(*cursor1) && IS_DELIM(*cursor2))
471 *(++cursor2) = *cursor1;
474 /* if the last character is a delimiter, skip it */
475 if (IS_DELIM(*(cursor2 - 1)))
481 s = kstrdup(prepath, gfp);
483 return ERR_PTR(-ENOMEM);
488 * Return full path based on the values of @ctx->{UNC,prepath}.
490 * It is assumed that both values were already parsed by smb3_parse_devname().
492 char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx, char dirsep)
497 ulen = strlen(ctx->UNC);
498 plen = ctx->prepath ? strlen(ctx->prepath) + 1 : 0;
500 s = kmalloc(ulen + plen + 1, GFP_KERNEL);
502 return ERR_PTR(-ENOMEM);
503 memcpy(s, ctx->UNC, ulen);
506 memcpy(s + ulen + 1, ctx->prepath, plen);
508 s[ulen + plen] = '\0';
509 convert_delimiter(s, dirsep);
514 * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
515 * fields with the result. Returns 0 on success and an error otherwise
516 * (e.g. ENOMEM or EINVAL)
519 smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
522 const char *delims = "/\\";
526 if (unlikely(!devname || !*devname)) {
527 cifs_dbg(VFS, "Device name not specified\n");
531 /* make sure we have a valid UNC double delimiter prefix */
532 len = strspn(devname, delims);
536 /* find delimiter between host and sharename */
537 pos = strpbrk(devname + 2, delims);
541 /* record the server hostname */
542 kfree(ctx->server_hostname);
543 ctx->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL);
544 if (!ctx->server_hostname)
547 /* skip past delimiter */
550 /* now go until next delimiter or end of string */
551 len = strcspn(pos, delims);
555 /* move "pos" up to delimiter or NULL */
558 ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
562 convert_delimiter(ctx->UNC, '\\');
564 /* skip any delimiter */
565 if (*pos == '/' || *pos == '\\')
571 /* If pos is NULL then no prepath */
575 ctx->prepath = cifs_sanitize_prepath(pos, GFP_KERNEL);
576 if (IS_ERR(ctx->prepath)) {
577 rc = PTR_ERR(ctx->prepath);
585 static void smb3_fs_context_free(struct fs_context *fc);
586 static int smb3_fs_context_parse_param(struct fs_context *fc,
587 struct fs_parameter *param);
588 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
590 static int smb3_get_tree(struct fs_context *fc);
591 static int smb3_reconfigure(struct fs_context *fc);
593 static const struct fs_context_operations smb3_fs_context_ops = {
594 .free = smb3_fs_context_free,
595 .parse_param = smb3_fs_context_parse_param,
596 .parse_monolithic = smb3_fs_context_parse_monolithic,
597 .get_tree = smb3_get_tree,
598 .reconfigure = smb3_reconfigure,
602 * Parse a monolithic block of data from sys_mount().
603 * smb3_fs_context_parse_monolithic - Parse key[=val][,key[=val]]* mount data
604 * @ctx: The superblock configuration to fill in.
605 * @data: The data to parse
607 * Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
608 * called from the ->monolithic_mount_data() fs_context operation.
610 * Returns 0 on success or the error returned by the ->parse_option() fs_context
611 * operation on failure.
613 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
616 char *options = data, *key;
622 ret = security_sb_eat_lsm_opts(options, &fc->security);
626 /* BB Need to add support for sep= here TBD */
627 while ((key = strsep(&options, ",")) != NULL) {
634 /* Check if following character is the deliminator If yes,
635 * we have encountered a double deliminator reset the NULL
636 * character to the deliminator
638 while (options && options[0] == ',') {
640 strcpy(key + len, options);
641 options = strchr(options, ',');
648 value = strchr(key, '=');
656 ret = vfs_parse_fs_string(fc, key, value, len);
665 * Validate the preparsed information in the config.
667 static int smb3_fs_context_validate(struct fs_context *fc)
669 struct smb3_fs_context *ctx = smb3_fc2context(fc);
671 if (ctx->rdma && ctx->vals->protocol_id < SMB30_PROT_ID) {
672 cifs_errorf(fc, "SMB Direct requires Version >=3.0\n");
677 /* Muliuser mounts require CONFIG_KEYS support */
678 if (ctx->multiuser) {
679 cifs_errorf(fc, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
684 if (ctx->got_version == false)
685 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");
689 cifs_errorf(fc, "CIFS mount error: No usable UNC path provided in device string!\n");
693 /* make sure UNC has a share name */
694 if (strlen(ctx->UNC) < 3 || !strchr(ctx->UNC + 3, '\\')) {
695 cifs_errorf(fc, "Malformed UNC. Unable to find share name.\n");
703 /* No ip= option specified? Try to get it from UNC */
704 /* Use the address part of the UNC. */
705 slash = strchr(&ctx->UNC[2], '\\');
706 len = slash - &ctx->UNC[2];
707 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
708 &ctx->UNC[2], len)) {
709 pr_err("Unable to determine destination address\n");
710 return -EHOSTUNREACH;
714 /* set the port that we got earlier */
715 cifs_set_port((struct sockaddr *)&ctx->dstaddr, ctx->port);
717 if (ctx->override_uid && !ctx->uid_specified) {
718 ctx->override_uid = 0;
719 pr_notice("ignoring forceuid mount option specified with no uid= option\n");
722 if (ctx->override_gid && !ctx->gid_specified) {
723 ctx->override_gid = 0;
724 pr_notice("ignoring forcegid mount option specified with no gid= option\n");
730 static int smb3_get_tree_common(struct fs_context *fc)
732 struct smb3_fs_context *ctx = smb3_fc2context(fc);
736 root = cifs_smb3_do_mount(fc->fs_type, 0, ctx);
738 return PTR_ERR(root);
746 * Create an SMB3 superblock from the parameters passed.
748 static int smb3_get_tree(struct fs_context *fc)
750 int err = smb3_fs_context_validate(fc);
755 mutex_lock(&cifs_mount_mutex);
756 ret = smb3_get_tree_common(fc);
757 mutex_unlock(&cifs_mount_mutex);
761 static void smb3_fs_context_free(struct fs_context *fc)
763 struct smb3_fs_context *ctx = smb3_fc2context(fc);
765 smb3_cleanup_fs_context(ctx);
769 * Compare the old and new proposed context during reconfigure
770 * and check if the changes are compatible.
772 static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
773 struct smb3_fs_context *new_ctx,
774 struct smb3_fs_context *old_ctx)
776 if (new_ctx->posix_paths != old_ctx->posix_paths) {
777 cifs_errorf(fc, "can not change posixpaths during remount\n");
780 if (new_ctx->sectype != old_ctx->sectype) {
781 cifs_errorf(fc, "can not change sec during remount\n");
784 if (new_ctx->multiuser != old_ctx->multiuser) {
785 cifs_errorf(fc, "can not change multiuser during remount\n");
789 (!old_ctx->UNC || strcmp(new_ctx->UNC, old_ctx->UNC))) {
790 cifs_errorf(fc, "can not change UNC during remount\n");
793 if (new_ctx->username &&
794 (!old_ctx->username || strcmp(new_ctx->username, old_ctx->username))) {
795 cifs_errorf(fc, "can not change username during remount\n");
798 if (new_ctx->password &&
799 (!old_ctx->password || strcmp(new_ctx->password, old_ctx->password))) {
800 cifs_errorf(fc, "can not change password during remount\n");
803 if (new_ctx->domainname &&
804 (!old_ctx->domainname || strcmp(new_ctx->domainname, old_ctx->domainname))) {
805 cifs_errorf(fc, "can not change domainname during remount\n");
808 if (strcmp(new_ctx->workstation_name, old_ctx->workstation_name)) {
809 cifs_errorf(fc, "can not change workstation_name during remount\n");
812 if (new_ctx->nodename &&
813 (!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
814 cifs_errorf(fc, "can not change nodename during remount\n");
817 if (new_ctx->iocharset &&
818 (!old_ctx->iocharset || strcmp(new_ctx->iocharset, old_ctx->iocharset))) {
819 cifs_errorf(fc, "can not change iocharset during remount\n");
826 #define STEAL_STRING(cifs_sb, ctx, field) \
829 ctx->field = cifs_sb->ctx->field; \
830 cifs_sb->ctx->field = NULL; \
833 #define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field) \
835 kfree_sensitive(ctx->field); \
836 ctx->field = cifs_sb->ctx->field; \
837 cifs_sb->ctx->field = NULL; \
840 static int smb3_reconfigure(struct fs_context *fc)
842 struct smb3_fs_context *ctx = smb3_fc2context(fc);
843 struct dentry *root = fc->root;
844 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
847 rc = smb3_verify_reconfigure_ctx(fc, ctx, cifs_sb->ctx);
852 * We can not change UNC/username/password/domainname/
853 * workstation_name/nodename/iocharset
854 * during reconnect so ignore what we have in the new context and
855 * just use what we already have in cifs_sb->ctx.
857 STEAL_STRING(cifs_sb, ctx, UNC);
858 STEAL_STRING(cifs_sb, ctx, source);
859 STEAL_STRING(cifs_sb, ctx, username);
860 STEAL_STRING_SENSITIVE(cifs_sb, ctx, password);
861 STEAL_STRING(cifs_sb, ctx, domainname);
862 STEAL_STRING(cifs_sb, ctx, nodename);
863 STEAL_STRING(cifs_sb, ctx, iocharset);
865 /* if rsize or wsize not passed in on remount, use previous values */
867 ctx->rsize = cifs_sb->ctx->rsize;
869 ctx->wsize = cifs_sb->ctx->wsize;
872 smb3_cleanup_fs_context_contents(cifs_sb->ctx);
873 rc = smb3_fs_context_dup(cifs_sb->ctx, ctx);
874 smb3_update_mnt_flags(cifs_sb);
875 #ifdef CONFIG_CIFS_DFS_UPCALL
877 rc = dfs_cache_remount_fs(cifs_sb);
883 static int smb3_fs_context_parse_param(struct fs_context *fc,
884 struct fs_parameter *param)
886 struct fs_parse_result result;
887 struct smb3_fs_context *ctx = smb3_fc2context(fc);
889 bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
890 bool skip_parsing = false;
894 cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
897 * fs_parse can not handle string options with an empty value so
898 * we will need special handling of them.
900 if (param->type == fs_value_is_string && param->string[0] == 0) {
901 if (!strcmp("pass", param->key) || !strcmp("password", param->key)) {
904 } else if (!strcmp("user", param->key) || !strcmp("username", param->key)) {
911 opt = fs_parse(fc, smb3_fs_parameters, param, &result);
913 return ctx->sloppy ? 1 : opt;
918 ctx->compression = UNKNOWN_TYPE;
920 "SMB3 compression support is experimental\n");
926 if (result.negated) {
928 cifs_dbg(VFS, "conflicting hard vs. soft mount options\n");
938 cifs_dbg(VFS, "conflicting hard vs soft mount options\n");
947 ctx->sfu_remap = false; /* disable SFU mapping */
952 ctx->sfu_remap = false;
954 ctx->sfu_remap = true;
955 ctx->remap = false; /* disable SFM (mapposix) mapping */
966 ctx->override_uid = 0;
968 ctx->override_uid = 1;
972 ctx->override_gid = 0;
974 ctx->override_gid = 1;
994 case Opt_noblocksend:
1009 case Opt_multichannel:
1010 if (result.negated) {
1011 ctx->multichannel = false;
1012 ctx->max_channels = 1;
1014 ctx->multichannel = true;
1015 /* if number of channels not specified, default to 2 */
1016 if (ctx->max_channels < 2)
1017 ctx->max_channels = 2;
1021 uid = make_kuid(current_user_ns(), result.uint_32);
1022 if (!uid_valid(uid))
1023 goto cifs_parse_mount_err;
1024 ctx->linux_uid = uid;
1025 ctx->uid_specified = true;
1028 uid = make_kuid(current_user_ns(), result.uint_32);
1029 if (!uid_valid(uid))
1030 goto cifs_parse_mount_err;
1031 ctx->cred_uid = uid;
1032 ctx->cruid_specified = true;
1035 uid = make_kuid(current_user_ns(), result.uint_32);
1036 if (!uid_valid(uid))
1037 goto cifs_parse_mount_err;
1038 ctx->backupuid = uid;
1039 ctx->backupuid_specified = true;
1042 gid = make_kgid(current_user_ns(), result.uint_32);
1043 if (!gid_valid(gid))
1044 goto cifs_parse_mount_err;
1045 ctx->backupgid = gid;
1046 ctx->backupgid_specified = true;
1049 gid = make_kgid(current_user_ns(), result.uint_32);
1050 if (!gid_valid(gid))
1051 goto cifs_parse_mount_err;
1052 ctx->linux_gid = gid;
1053 ctx->gid_specified = true;
1056 ctx->port = result.uint_32;
1059 ctx->file_mode = result.uint_32;
1062 ctx->dir_mode = result.uint_32;
1064 case Opt_min_enc_offload:
1065 ctx->min_offload = result.uint_32;
1069 * inode blocksize realistically should never need to be
1070 * less than 16K or greater than 16M and default is 1MB.
1071 * Note that small inode block sizes (e.g. 64K) can lead
1072 * to very poor performance of common tools like cp and scp
1074 if ((result.uint_32 < CIFS_MAX_MSGSIZE) ||
1075 (result.uint_32 > (4 * SMB3_DEFAULT_IOSIZE))) {
1076 cifs_errorf(fc, "%s: Invalid blocksize\n",
1078 goto cifs_parse_mount_err;
1080 ctx->bsize = result.uint_32;
1081 ctx->got_bsize = true;
1085 * readahead size realistically should never need to be
1086 * less than 1M (CIFS_DEFAULT_IOSIZE) or greater than 32M
1087 * (perhaps an exception should be considered in the
1088 * for the case of a large number of channels
1089 * when multichannel is negotiated) since that would lead
1090 * to plenty of parallel I/O in flight to the server.
1091 * Note that smaller read ahead sizes would
1092 * hurt performance of common tools like cp and scp
1093 * which often trigger sequential i/o with read ahead
1095 if ((result.uint_32 > (8 * SMB3_DEFAULT_IOSIZE)) ||
1096 (result.uint_32 < CIFS_DEFAULT_IOSIZE)) {
1097 cifs_errorf(fc, "%s: Invalid rasize %d vs. %d\n",
1098 __func__, result.uint_32, SMB3_DEFAULT_IOSIZE);
1099 goto cifs_parse_mount_err;
1101 ctx->rasize = result.uint_32;
1104 ctx->rsize = result.uint_32;
1105 ctx->got_rsize = true;
1108 ctx->wsize = result.uint_32;
1109 ctx->got_wsize = true;
1112 ctx->acregmax = HZ * result.uint_32;
1113 if (ctx->acregmax > CIFS_MAX_ACTIMEO) {
1114 cifs_errorf(fc, "acregmax too large\n");
1115 goto cifs_parse_mount_err;
1119 ctx->acdirmax = HZ * result.uint_32;
1120 if (ctx->acdirmax > CIFS_MAX_ACTIMEO) {
1121 cifs_errorf(fc, "acdirmax too large\n");
1122 goto cifs_parse_mount_err;
1126 if (HZ * result.uint_32 > CIFS_MAX_ACTIMEO) {
1127 cifs_errorf(fc, "timeout too large\n");
1128 goto cifs_parse_mount_err;
1130 if ((ctx->acdirmax != CIFS_DEF_ACTIMEO) ||
1131 (ctx->acregmax != CIFS_DEF_ACTIMEO)) {
1132 cifs_errorf(fc, "actimeo ignored since acregmax or acdirmax specified\n");
1135 ctx->acdirmax = ctx->acregmax = HZ * result.uint_32;
1137 case Opt_closetimeo:
1138 ctx->closetimeo = HZ * result.uint_32;
1139 if (ctx->closetimeo > SMB3_MAX_DCLOSETIMEO) {
1140 cifs_errorf(fc, "closetimeo too large\n");
1141 goto cifs_parse_mount_err;
1144 case Opt_echo_interval:
1145 ctx->echo_interval = result.uint_32;
1148 ctx->snapshot_time = result.uint_64;
1150 case Opt_max_credits:
1151 if (result.uint_32 < 20 || result.uint_32 > 60000) {
1152 cifs_errorf(fc, "%s: Invalid max_credits value\n",
1154 goto cifs_parse_mount_err;
1156 ctx->max_credits = result.uint_32;
1158 case Opt_max_channels:
1159 if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
1160 cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
1161 __func__, CIFS_MAX_CHANNELS);
1162 goto cifs_parse_mount_err;
1164 ctx->max_channels = result.uint_32;
1165 /* If more than one channel requested ... they want multichan */
1166 if (result.uint_32 > 1)
1167 ctx->multichannel = true;
1169 case Opt_max_cached_dirs:
1170 if (result.uint_32 < 1) {
1171 cifs_errorf(fc, "%s: Invalid max_cached_dirs, needs to be 1 or more\n",
1173 goto cifs_parse_mount_err;
1175 ctx->max_cached_dirs = result.uint_32;
1177 case Opt_handletimeout:
1178 ctx->handle_timeout = result.uint_32;
1179 if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
1180 cifs_errorf(fc, "Invalid handle cache timeout, longer than 16 minutes\n");
1181 goto cifs_parse_mount_err;
1187 switch (smb3_parse_devname(param->string, ctx)) {
1191 cifs_errorf(fc, "Unable to allocate memory for devname\n");
1192 goto cifs_parse_mount_err;
1194 cifs_errorf(fc, "Malformed UNC in devname\n");
1195 goto cifs_parse_mount_err;
1197 cifs_errorf(fc, "Unknown error parsing devname\n");
1198 goto cifs_parse_mount_err;
1200 ctx->source = smb3_fs_context_fullpath(ctx, '/');
1201 if (IS_ERR(ctx->source)) {
1203 cifs_errorf(fc, "OOM when copying UNC string\n");
1204 goto cifs_parse_mount_err;
1206 fc->source = kstrdup(ctx->source, GFP_KERNEL);
1207 if (fc->source == NULL) {
1208 cifs_errorf(fc, "OOM when copying UNC string\n");
1209 goto cifs_parse_mount_err;
1213 kfree(ctx->username);
1214 ctx->username = NULL;
1217 if (strlen(param->string) == 0) {
1218 /* null user, ie. anonymous authentication */
1223 if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
1224 CIFS_MAX_USERNAME_LEN) {
1225 pr_warn("username too long\n");
1226 goto cifs_parse_mount_err;
1228 ctx->username = kstrdup(param->string, GFP_KERNEL);
1229 if (ctx->username == NULL) {
1230 cifs_errorf(fc, "OOM when copying username string\n");
1231 goto cifs_parse_mount_err;
1235 kfree_sensitive(ctx->password);
1236 ctx->password = NULL;
1237 if (strlen(param->string) == 0)
1240 ctx->password = kstrdup(param->string, GFP_KERNEL);
1241 if (ctx->password == NULL) {
1242 cifs_errorf(fc, "OOM when copying password string\n");
1243 goto cifs_parse_mount_err;
1247 if (strlen(param->string) == 0) {
1248 ctx->got_ip = false;
1251 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
1253 strlen(param->string))) {
1254 pr_err("bad ip= option (%s)\n", param->string);
1255 goto cifs_parse_mount_err;
1260 if (strnlen(param->string, CIFS_MAX_DOMAINNAME_LEN)
1261 == CIFS_MAX_DOMAINNAME_LEN) {
1262 pr_warn("domain name too long\n");
1263 goto cifs_parse_mount_err;
1266 kfree(ctx->domainname);
1267 ctx->domainname = kstrdup(param->string, GFP_KERNEL);
1268 if (ctx->domainname == NULL) {
1269 cifs_errorf(fc, "OOM when copying domainname string\n");
1270 goto cifs_parse_mount_err;
1272 cifs_dbg(FYI, "Domain name set\n");
1275 if (!cifs_convert_address(
1276 (struct sockaddr *)&ctx->srcaddr,
1277 param->string, strlen(param->string))) {
1278 pr_warn("Could not parse srcaddr: %s\n",
1280 goto cifs_parse_mount_err;
1284 if (strnlen(param->string, 1024) >= 65) {
1285 pr_warn("iocharset name too long\n");
1286 goto cifs_parse_mount_err;
1289 if (strncasecmp(param->string, "default", 7) != 0) {
1290 kfree(ctx->iocharset);
1291 ctx->iocharset = kstrdup(param->string, GFP_KERNEL);
1292 if (ctx->iocharset == NULL) {
1293 cifs_errorf(fc, "OOM when copying iocharset string\n");
1294 goto cifs_parse_mount_err;
1297 /* if iocharset not set then load_nls_default
1300 cifs_dbg(FYI, "iocharset set to %s\n", ctx->iocharset);
1302 case Opt_netbiosname:
1303 memset(ctx->source_rfc1001_name, 0x20,
1306 * FIXME: are there cases in which a comma can
1307 * be valid in workstation netbios name (and
1308 * need special handling)?
1310 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1311 /* don't ucase netbiosname for user */
1312 if (param->string[i] == 0)
1314 ctx->source_rfc1001_name[i] = param->string[i];
1316 /* The string has 16th byte zero still from
1317 * set at top of the function
1319 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1320 pr_warn("netbiosname longer than 15 truncated\n");
1323 /* last byte, type, is 0x20 for servr type */
1324 memset(ctx->target_rfc1001_name, 0x20,
1325 RFC1001_NAME_LEN_WITH_NULL);
1327 * BB are there cases in which a comma can be valid in this
1328 * workstation netbios name (and need special handling)?
1331 /* user or mount helper must uppercase the netbios name */
1332 for (i = 0; i < 15; i++) {
1333 if (param->string[i] == 0)
1335 ctx->target_rfc1001_name[i] = param->string[i];
1338 /* The string has 16th byte zero still from set at top of function */
1339 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1340 pr_warn("server netbiosname longer than 15 truncated\n");
1343 /* version of mount userspace tools, not dialect */
1344 /* If interface changes in mount.cifs bump to new ver */
1345 if (strncasecmp(param->string, "1", 1) == 0) {
1346 if (strlen(param->string) > 1) {
1347 pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
1349 goto cifs_parse_mount_err;
1351 /* This is the default */
1354 /* For all other value, error */
1355 pr_warn("Invalid mount helper version specified\n");
1356 goto cifs_parse_mount_err;
1358 /* protocol version (dialect) */
1359 if (cifs_parse_smb_version(fc, param->string, ctx, is_smb3) != 0)
1360 goto cifs_parse_mount_err;
1361 ctx->got_version = true;
1364 if (cifs_parse_security_flavors(fc, param->string, ctx) != 0)
1365 goto cifs_parse_mount_err;
1368 if (cifs_parse_cache_flavor(fc, param->string, ctx) != 0)
1369 goto cifs_parse_mount_err;
1372 #ifndef CONFIG_CIFS_SWN_UPCALL
1373 cifs_errorf(fc, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
1374 goto cifs_parse_mount_err;
1376 ctx->witness = true;
1377 pr_warn_once("Witness protocol support is experimental\n");
1380 #ifndef CONFIG_CIFS_ROOT
1381 cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
1382 goto cifs_parse_mount_err;
1386 case Opt_posixpaths:
1388 ctx->posix_paths = 0;
1390 ctx->posix_paths = 1;
1393 if (result.negated) {
1394 if (ctx->linux_ext == 1)
1395 pr_warn_once("conflicting posix mount options specified\n");
1397 ctx->no_linux_ext = 1;
1399 if (ctx->no_linux_ext == 1)
1400 pr_warn_once("conflicting posix mount options specified\n");
1402 ctx->no_linux_ext = 0;
1409 if (result.negated) {
1411 * turn off mandatory locking in mode
1412 * if remote locking is turned off since the
1413 * local vfs will do advisory
1415 if (ctx->file_mode ==
1416 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1417 ctx->file_mode = S_IALLUGO;
1422 case Opt_handlecache:
1424 ctx->nohandlecache = 1;
1426 ctx->nohandlecache = 0;
1428 case Opt_forcemandatorylock:
1432 ctx->setuids = result.negated;
1435 ctx->intr = !result.negated;
1437 case Opt_setuidfromacl:
1438 ctx->setuidfromacl = 1;
1440 case Opt_strictsync:
1441 ctx->nostrictsync = result.negated;
1444 ctx->server_ino = !result.negated;
1446 case Opt_rwpidforward:
1447 ctx->rwpidforward = 1;
1453 ctx->cifs_acl = !result.negated;
1456 ctx->no_psx_acl = result.negated;
1458 case Opt_locallease:
1459 ctx->local_lease = 1;
1464 case Opt_ignore_signature:
1466 ctx->ignore_signature = true;
1469 /* we do not do the following in secFlags because seal
1470 * is a per tree connection (mount) not a per socket
1471 * or per-smb connection option in the protocol
1472 * vol->secFlg |= CIFSSEC_MUST_SEAL;
1477 pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
1480 #ifndef CONFIG_CIFS_FSCACHE
1481 cifs_errorf(fc, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
1482 goto cifs_parse_mount_err;
1486 case Opt_mfsymlinks:
1487 ctx->mfsymlinks = true;
1490 ctx->multiuser = true;
1495 case Opt_nosharesock:
1496 ctx->nosharesock = true;
1498 case Opt_persistent:
1499 if (result.negated) {
1500 ctx->nopersistent = true;
1501 if (ctx->persistent) {
1502 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1503 goto cifs_parse_mount_err;
1506 ctx->persistent = true;
1507 if ((ctx->nopersistent) || (ctx->resilient)) {
1508 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1509 goto cifs_parse_mount_err;
1514 if (result.negated) {
1515 ctx->resilient = false; /* already the default */
1517 ctx->resilient = true;
1518 if (ctx->persistent) {
1519 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1520 goto cifs_parse_mount_err;
1524 case Opt_tcp_nodelay:
1525 /* tcp nodelay should not usually be needed since we CORK/UNCORK the socket */
1527 ctx->sockopt_tcp_nodelay = false;
1529 ctx->sockopt_tcp_nodelay = true;
1531 case Opt_domainauto:
1532 ctx->domainauto = true;
1538 /* case Opt_ignore: - is ignored as expected ... */
1542 cifs_parse_mount_err:
1543 kfree_sensitive(ctx->password);
1544 ctx->password = NULL;
1548 int smb3_init_fs_context(struct fs_context *fc)
1550 struct smb3_fs_context *ctx;
1551 char *nodename = utsname()->nodename;
1554 ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
1558 strscpy(ctx->workstation_name, nodename, sizeof(ctx->workstation_name));
1561 * does not have to be perfect mapping since field is
1562 * informational, only used for servers that do not support
1563 * port 445 and it can be overridden at mount time
1565 memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
1566 for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
1567 ctx->source_rfc1001_name[i] = toupper(nodename[i]);
1569 ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
1571 * null target name indicates to use *SMBSERVR default called name
1572 * if we end up sending RFC1001 session initialize
1574 ctx->target_rfc1001_name[0] = 0;
1575 ctx->cred_uid = current_uid();
1576 ctx->linux_uid = current_uid();
1577 ctx->linux_gid = current_gid();
1578 /* By default 4MB read ahead size, 1MB block size */
1579 ctx->bsize = CIFS_DEFAULT_IOSIZE; /* can improve cp performance significantly */
1580 ctx->rasize = 0; /* 0 = use default (ie negotiated rsize) for read ahead pages */
1583 * default to SFM style remapping of seven reserved characters
1584 * unless user overrides it or we negotiate CIFS POSIX where
1585 * it is unnecessary. Can not simultaneously use more than one mapping
1586 * since then readdir could list files that open could not open
1590 /* default to only allowing write access to owner of the mount */
1591 ctx->dir_mode = ctx->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
1593 /* ctx->retry default is 0 (i.e. "soft" limited retry not hard retry) */
1594 /* default is always to request posix paths. */
1595 ctx->posix_paths = 1;
1596 /* default to using server inode numbers where available */
1597 ctx->server_ino = 1;
1599 /* default is to use strict cifs caching semantics */
1600 ctx->strict_io = true;
1602 ctx->acregmax = CIFS_DEF_ACTIMEO;
1603 ctx->acdirmax = CIFS_DEF_ACTIMEO;
1604 ctx->closetimeo = SMB3_DEF_DCLOSETIMEO;
1605 ctx->max_cached_dirs = MAX_CACHED_FIDS;
1606 /* Most clients set timeout to 0, allows server to use its default */
1607 ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
1609 /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
1610 ctx->ops = &smb30_operations;
1611 ctx->vals = &smbdefault_values;
1613 ctx->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
1615 /* default to no multichannel (single server connection) */
1616 ctx->multichannel = false;
1617 ctx->max_channels = 1;
1619 ctx->backupuid_specified = false; /* no backup intent for a user */
1620 ctx->backupgid_specified = false; /* no backup intent for a group */
1623 * short int override_uid = -1;
1624 * short int override_gid = -1;
1625 * char *nodename = strdup(utsname()->nodename);
1626 * struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
1629 fc->fs_private = ctx;
1630 fc->ops = &smb3_fs_context_ops;
1635 smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
1641 * Make sure this stays in sync with smb3_fs_context_dup()
1643 kfree(ctx->username);
1644 ctx->username = NULL;
1645 kfree_sensitive(ctx->password);
1646 ctx->password = NULL;
1647 kfree(ctx->server_hostname);
1648 ctx->server_hostname = NULL;
1653 kfree(ctx->domainname);
1654 ctx->domainname = NULL;
1655 kfree(ctx->nodename);
1656 ctx->nodename = NULL;
1657 kfree(ctx->iocharset);
1658 ctx->iocharset = NULL;
1659 kfree(ctx->prepath);
1660 ctx->prepath = NULL;
1661 kfree(ctx->leaf_fullpath);
1662 ctx->leaf_fullpath = NULL;
1666 smb3_cleanup_fs_context(struct smb3_fs_context *ctx)
1670 smb3_cleanup_fs_context_contents(ctx);
1674 void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
1676 struct smb3_fs_context *ctx = cifs_sb->ctx;
1679 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS;
1681 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_DFS;
1684 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
1686 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_PERM;
1689 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
1691 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SET_UID;
1693 if (ctx->setuidfromacl)
1694 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL;
1696 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UID_FROM_ACL;
1698 if (ctx->server_ino)
1699 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
1701 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
1704 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR;
1706 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SFM_CHR;
1709 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
1711 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SPECIAL_CHR;
1714 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
1716 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_XATTR;
1719 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
1721 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UNX_EMUL;
1724 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
1726 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_BRL;
1728 if (ctx->nohandlecache)
1729 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE;
1731 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_HANDLE_CACHE;
1733 if (ctx->nostrictsync)
1734 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
1736 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOSSYNC;
1739 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
1741 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOPOSIXBRL;
1743 if (ctx->rwpidforward)
1744 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
1746 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_RWPIDFORWARD;
1749 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MODE_FROM_SID;
1751 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MODE_FROM_SID;
1754 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
1756 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_ACL;
1758 if (ctx->backupuid_specified)
1759 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
1761 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPUID;
1763 if (ctx->backupgid_specified)
1764 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
1766 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPGID;
1768 if (ctx->override_uid)
1769 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
1771 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_UID;
1773 if (ctx->override_gid)
1774 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
1776 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_GID;
1779 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
1781 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DYNPERM;
1784 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
1786 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_FSCACHE;
1789 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
1790 CIFS_MOUNT_NO_PERM);
1792 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MULTIUSER;
1796 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
1798 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_STRICT_IO;
1801 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
1803 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DIRECT_IO;
1805 if (ctx->mfsymlinks)
1806 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
1808 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MF_SYMLINKS;
1809 if (ctx->mfsymlinks) {
1810 if (ctx->sfu_emul) {
1812 * Our SFU ("Services for Unix" emulation does not allow
1813 * creating symlinks but does allow reading existing SFU
1814 * symlinks (it does allow both creating and reading SFU
1815 * style mknod and FIFOs though). When "mfsymlinks" and
1816 * "sfu" are both enabled at the same time, it allows
1817 * reading both types of symlinks, but will only create
1818 * them with mfsymlinks format. This allows better
1819 * Apple compatibility (probably better for Samba too)
1820 * while still recognizing old Windows style symlinks.
1822 cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
1825 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SHUTDOWN;