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("handletimeout", Opt_handletimeout),
154 fsparam_u64("snapshot", Opt_snapshot),
155 fsparam_u32("max_channels", Opt_max_channels),
157 /* Mount options which take string value */
158 fsparam_string("source", Opt_source),
159 fsparam_string("user", Opt_user),
160 fsparam_string("username", Opt_user),
161 fsparam_string("pass", Opt_pass),
162 fsparam_string("password", Opt_pass),
163 fsparam_string("ip", Opt_ip),
164 fsparam_string("addr", Opt_ip),
165 fsparam_string("domain", Opt_domain),
166 fsparam_string("dom", Opt_domain),
167 fsparam_string("srcaddr", Opt_srcaddr),
168 fsparam_string("iocharset", Opt_iocharset),
169 fsparam_string("netbiosname", Opt_netbiosname),
170 fsparam_string("servern", Opt_servern),
171 fsparam_string("ver", Opt_ver),
172 fsparam_string("vers", Opt_vers),
173 fsparam_string("sec", Opt_sec),
174 fsparam_string("cache", Opt_cache),
176 /* Arguments that should be ignored */
177 fsparam_flag("guest", Opt_ignore),
178 fsparam_flag("noatime", Opt_ignore),
179 fsparam_flag("relatime", Opt_ignore),
180 fsparam_flag("_netdev", Opt_ignore),
181 fsparam_flag_no("suid", Opt_ignore),
182 fsparam_flag_no("exec", Opt_ignore),
183 fsparam_flag_no("dev", Opt_ignore),
184 fsparam_flag_no("mand", Opt_ignore),
185 fsparam_flag_no("auto", Opt_ignore),
186 fsparam_string("cred", Opt_ignore),
187 fsparam_string("credentials", Opt_ignore),
189 * UNC and prefixpath is now extracted from Opt_source
190 * in the new mount API so we can just ignore them going forward.
192 fsparam_string("unc", Opt_ignore),
193 fsparam_string("prefixpath", Opt_ignore),
198 cifs_parse_security_flavors(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
201 substring_t args[MAX_OPT_ARGS];
204 * With mount options, the last one should win. Reset any existing
205 * settings back to default.
207 ctx->sectype = Unspecified;
210 switch (match_token(value, cifs_secflavor_tokens, args)) {
212 cifs_errorf(fc, "sec=krb5p is not supported!\n");
218 ctx->sectype = Kerberos;
220 case Opt_sec_ntlmsspi:
223 case Opt_sec_ntlmssp:
224 ctx->sectype = RawNTLMSSP;
226 case Opt_sec_ntlmv2i:
230 ctx->sectype = NTLMv2;
234 kfree(ctx->username);
235 ctx->username = NULL;
238 cifs_errorf(fc, "bad security option: %s\n", value);
245 static const match_table_t cifs_cacheflavor_tokens = {
246 { Opt_cache_loose, "loose" },
247 { Opt_cache_strict, "strict" },
248 { Opt_cache_none, "none" },
249 { Opt_cache_ro, "ro" },
250 { Opt_cache_rw, "singleclient" },
251 { Opt_cache_err, NULL }
255 cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
257 substring_t args[MAX_OPT_ARGS];
259 switch (match_token(value, cifs_cacheflavor_tokens, args)) {
260 case Opt_cache_loose:
261 ctx->direct_io = false;
262 ctx->strict_io = false;
263 ctx->cache_ro = false;
264 ctx->cache_rw = false;
266 case Opt_cache_strict:
267 ctx->direct_io = false;
268 ctx->strict_io = true;
269 ctx->cache_ro = false;
270 ctx->cache_rw = false;
273 ctx->direct_io = true;
274 ctx->strict_io = false;
275 ctx->cache_ro = false;
276 ctx->cache_rw = false;
279 ctx->direct_io = false;
280 ctx->strict_io = false;
281 ctx->cache_ro = true;
282 ctx->cache_rw = false;
285 ctx->direct_io = false;
286 ctx->strict_io = false;
287 ctx->cache_ro = false;
288 ctx->cache_rw = true;
291 cifs_errorf(fc, "bad cache= option: %s\n", value);
297 #define DUP_CTX_STR(field) \
300 new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
301 if (new_ctx->field == NULL) { \
302 smb3_cleanup_fs_context_contents(new_ctx); \
309 smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
311 memcpy(new_ctx, ctx, sizeof(*ctx));
312 new_ctx->prepath = NULL;
313 new_ctx->nodename = NULL;
314 new_ctx->username = NULL;
315 new_ctx->password = NULL;
316 new_ctx->server_hostname = NULL;
317 new_ctx->domainname = NULL;
319 new_ctx->source = NULL;
320 new_ctx->iocharset = NULL;
321 new_ctx->leaf_fullpath = NULL;
323 * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
325 DUP_CTX_STR(prepath);
326 DUP_CTX_STR(username);
327 DUP_CTX_STR(password);
328 DUP_CTX_STR(server_hostname);
331 DUP_CTX_STR(domainname);
332 DUP_CTX_STR(nodename);
333 DUP_CTX_STR(iocharset);
334 DUP_CTX_STR(leaf_fullpath);
340 cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_context *ctx, bool is_smb3)
342 substring_t args[MAX_OPT_ARGS];
344 switch (match_token(value, cifs_smb_version_tokens, args)) {
345 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
347 if (disable_legacy_dialects) {
348 cifs_errorf(fc, "mount with legacy dialect disabled\n");
352 cifs_errorf(fc, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
355 cifs_errorf(fc, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
356 ctx->ops = &smb1_operations;
357 ctx->vals = &smb1_values;
360 if (disable_legacy_dialects) {
361 cifs_errorf(fc, "mount with legacy dialect disabled\n");
365 cifs_errorf(fc, "vers=2.0 not permitted when mounting with smb3\n");
368 ctx->ops = &smb20_operations;
369 ctx->vals = &smb20_values;
373 cifs_errorf(fc, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
376 cifs_errorf(fc, "vers=2.0 mount not permitted when legacy dialects disabled\n");
378 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
380 ctx->ops = &smb21_operations;
381 ctx->vals = &smb21_values;
384 ctx->ops = &smb30_operations;
385 ctx->vals = &smb30_values;
388 ctx->ops = &smb30_operations; /* currently identical with 3.0 */
389 ctx->vals = &smb302_values;
392 ctx->ops = &smb311_operations;
393 ctx->vals = &smb311_values;
396 ctx->ops = &smb30_operations; /* currently identical with 3.0 */
397 ctx->vals = &smb3any_values;
400 ctx->ops = &smb30_operations;
401 ctx->vals = &smbdefault_values;
404 cifs_errorf(fc, "Unknown vers= option specified: %s\n", value);
410 int smb3_parse_opt(const char *options, const char *key, char **val)
413 char *opts, *orig, *p;
415 orig = opts = kstrdup(options, GFP_KERNEL);
419 while ((p = strsep(&opts, ","))) {
424 if (strncasecmp(p, key, strlen(key)))
426 nval = strchr(p, '=');
431 *val = kstrdup(nval, GFP_KERNEL);
432 rc = !*val ? -ENOMEM : 0;
442 * Remove duplicate path delimiters. Windows is supposed to do that
443 * but there are some bugs that prevent rename from working if there are
444 * multiple delimiters.
446 * Return a sanitized duplicate of @path or NULL for empty prefix paths.
447 * Otherwise, return ERR_PTR.
449 * @gfp indicates the GFP_* flags for kstrdup.
450 * The caller is responsible for freeing the original.
452 #define IS_DELIM(c) ((c) == '/' || (c) == '\\')
453 char *cifs_sanitize_prepath(char *prepath, gfp_t gfp)
455 char *cursor1 = prepath, *cursor2 = prepath;
458 /* skip all prepended delimiters */
459 while (IS_DELIM(*cursor1))
462 /* copy the first letter */
465 /* copy the remainder... */
466 while (*(cursor1++)) {
467 /* ... skipping all duplicated delimiters */
468 if (IS_DELIM(*cursor1) && IS_DELIM(*cursor2))
470 *(++cursor2) = *cursor1;
473 /* if the last character is a delimiter, skip it */
474 if (IS_DELIM(*(cursor2 - 1)))
480 s = kstrdup(prepath, gfp);
482 return ERR_PTR(-ENOMEM);
487 * Return full path based on the values of @ctx->{UNC,prepath}.
489 * It is assumed that both values were already parsed by smb3_parse_devname().
491 char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx, char dirsep)
496 ulen = strlen(ctx->UNC);
497 plen = ctx->prepath ? strlen(ctx->prepath) + 1 : 0;
499 s = kmalloc(ulen + plen + 1, GFP_KERNEL);
501 return ERR_PTR(-ENOMEM);
502 memcpy(s, ctx->UNC, ulen);
505 memcpy(s + ulen + 1, ctx->prepath, plen);
507 s[ulen + plen] = '\0';
508 convert_delimiter(s, dirsep);
513 * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
514 * fields with the result. Returns 0 on success and an error otherwise
515 * (e.g. ENOMEM or EINVAL)
518 smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
521 const char *delims = "/\\";
525 if (unlikely(!devname || !*devname)) {
526 cifs_dbg(VFS, "Device name not specified\n");
530 /* make sure we have a valid UNC double delimiter prefix */
531 len = strspn(devname, delims);
535 /* find delimiter between host and sharename */
536 pos = strpbrk(devname + 2, delims);
540 /* record the server hostname */
541 kfree(ctx->server_hostname);
542 ctx->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL);
543 if (!ctx->server_hostname)
546 /* skip past delimiter */
549 /* now go until next delimiter or end of string */
550 len = strcspn(pos, delims);
554 /* move "pos" up to delimiter or NULL */
557 ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
561 convert_delimiter(ctx->UNC, '\\');
563 /* skip any delimiter */
564 if (*pos == '/' || *pos == '\\')
570 /* If pos is NULL then no prepath */
574 ctx->prepath = cifs_sanitize_prepath(pos, GFP_KERNEL);
575 if (IS_ERR(ctx->prepath)) {
576 rc = PTR_ERR(ctx->prepath);
584 static void smb3_fs_context_free(struct fs_context *fc);
585 static int smb3_fs_context_parse_param(struct fs_context *fc,
586 struct fs_parameter *param);
587 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
589 static int smb3_get_tree(struct fs_context *fc);
590 static int smb3_reconfigure(struct fs_context *fc);
592 static const struct fs_context_operations smb3_fs_context_ops = {
593 .free = smb3_fs_context_free,
594 .parse_param = smb3_fs_context_parse_param,
595 .parse_monolithic = smb3_fs_context_parse_monolithic,
596 .get_tree = smb3_get_tree,
597 .reconfigure = smb3_reconfigure,
601 * Parse a monolithic block of data from sys_mount().
602 * smb3_fs_context_parse_monolithic - Parse key[=val][,key[=val]]* mount data
603 * @ctx: The superblock configuration to fill in.
604 * @data: The data to parse
606 * Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
607 * called from the ->monolithic_mount_data() fs_context operation.
609 * Returns 0 on success or the error returned by the ->parse_option() fs_context
610 * operation on failure.
612 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
615 char *options = data, *key;
621 ret = security_sb_eat_lsm_opts(options, &fc->security);
625 /* BB Need to add support for sep= here TBD */
626 while ((key = strsep(&options, ",")) != NULL) {
633 /* Check if following character is the deliminator If yes,
634 * we have encountered a double deliminator reset the NULL
635 * character to the deliminator
637 while (options && options[0] == ',') {
639 strcpy(key + len, options);
640 options = strchr(options, ',');
647 value = strchr(key, '=');
655 ret = vfs_parse_fs_string(fc, key, value, len);
664 * Validate the preparsed information in the config.
666 static int smb3_fs_context_validate(struct fs_context *fc)
668 struct smb3_fs_context *ctx = smb3_fc2context(fc);
670 if (ctx->rdma && ctx->vals->protocol_id < SMB30_PROT_ID) {
671 cifs_errorf(fc, "SMB Direct requires Version >=3.0\n");
676 /* Muliuser mounts require CONFIG_KEYS support */
677 if (ctx->multiuser) {
678 cifs_errorf(fc, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
683 if (ctx->got_version == false)
684 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");
688 cifs_errorf(fc, "CIFS mount error: No usable UNC path provided in device string!\n");
692 /* make sure UNC has a share name */
693 if (strlen(ctx->UNC) < 3 || !strchr(ctx->UNC + 3, '\\')) {
694 cifs_errorf(fc, "Malformed UNC. Unable to find share name.\n");
702 /* No ip= option specified? Try to get it from UNC */
703 /* Use the address part of the UNC. */
704 slash = strchr(&ctx->UNC[2], '\\');
705 len = slash - &ctx->UNC[2];
706 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
707 &ctx->UNC[2], len)) {
708 pr_err("Unable to determine destination address\n");
709 return -EHOSTUNREACH;
713 /* set the port that we got earlier */
714 cifs_set_port((struct sockaddr *)&ctx->dstaddr, ctx->port);
716 if (ctx->override_uid && !ctx->uid_specified) {
717 ctx->override_uid = 0;
718 pr_notice("ignoring forceuid mount option specified with no uid= option\n");
721 if (ctx->override_gid && !ctx->gid_specified) {
722 ctx->override_gid = 0;
723 pr_notice("ignoring forcegid mount option specified with no gid= option\n");
729 static int smb3_get_tree_common(struct fs_context *fc)
731 struct smb3_fs_context *ctx = smb3_fc2context(fc);
735 root = cifs_smb3_do_mount(fc->fs_type, 0, ctx);
737 return PTR_ERR(root);
745 * Create an SMB3 superblock from the parameters passed.
747 static int smb3_get_tree(struct fs_context *fc)
749 int err = smb3_fs_context_validate(fc);
754 mutex_lock(&cifs_mount_mutex);
755 ret = smb3_get_tree_common(fc);
756 mutex_unlock(&cifs_mount_mutex);
760 static void smb3_fs_context_free(struct fs_context *fc)
762 struct smb3_fs_context *ctx = smb3_fc2context(fc);
764 smb3_cleanup_fs_context(ctx);
768 * Compare the old and new proposed context during reconfigure
769 * and check if the changes are compatible.
771 static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
772 struct smb3_fs_context *new_ctx,
773 struct smb3_fs_context *old_ctx)
775 if (new_ctx->posix_paths != old_ctx->posix_paths) {
776 cifs_errorf(fc, "can not change posixpaths during remount\n");
779 if (new_ctx->sectype != old_ctx->sectype) {
780 cifs_errorf(fc, "can not change sec during remount\n");
783 if (new_ctx->multiuser != old_ctx->multiuser) {
784 cifs_errorf(fc, "can not change multiuser during remount\n");
788 (!old_ctx->UNC || strcmp(new_ctx->UNC, old_ctx->UNC))) {
789 cifs_errorf(fc, "can not change UNC during remount\n");
792 if (new_ctx->username &&
793 (!old_ctx->username || strcmp(new_ctx->username, old_ctx->username))) {
794 cifs_errorf(fc, "can not change username during remount\n");
797 if (new_ctx->password &&
798 (!old_ctx->password || strcmp(new_ctx->password, old_ctx->password))) {
799 cifs_errorf(fc, "can not change password during remount\n");
802 if (new_ctx->domainname &&
803 (!old_ctx->domainname || strcmp(new_ctx->domainname, old_ctx->domainname))) {
804 cifs_errorf(fc, "can not change domainname during remount\n");
807 if (strcmp(new_ctx->workstation_name, old_ctx->workstation_name)) {
808 cifs_errorf(fc, "can not change workstation_name during remount\n");
811 if (new_ctx->nodename &&
812 (!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
813 cifs_errorf(fc, "can not change nodename during remount\n");
816 if (new_ctx->iocharset &&
817 (!old_ctx->iocharset || strcmp(new_ctx->iocharset, old_ctx->iocharset))) {
818 cifs_errorf(fc, "can not change iocharset during remount\n");
825 #define STEAL_STRING(cifs_sb, ctx, field) \
828 ctx->field = cifs_sb->ctx->field; \
829 cifs_sb->ctx->field = NULL; \
832 #define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field) \
834 kfree_sensitive(ctx->field); \
835 ctx->field = cifs_sb->ctx->field; \
836 cifs_sb->ctx->field = NULL; \
839 static int smb3_reconfigure(struct fs_context *fc)
841 struct smb3_fs_context *ctx = smb3_fc2context(fc);
842 struct dentry *root = fc->root;
843 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
846 rc = smb3_verify_reconfigure_ctx(fc, ctx, cifs_sb->ctx);
851 * We can not change UNC/username/password/domainname/
852 * workstation_name/nodename/iocharset
853 * during reconnect so ignore what we have in the new context and
854 * just use what we already have in cifs_sb->ctx.
856 STEAL_STRING(cifs_sb, ctx, UNC);
857 STEAL_STRING(cifs_sb, ctx, source);
858 STEAL_STRING(cifs_sb, ctx, username);
859 STEAL_STRING_SENSITIVE(cifs_sb, ctx, password);
860 STEAL_STRING(cifs_sb, ctx, domainname);
861 STEAL_STRING(cifs_sb, ctx, nodename);
862 STEAL_STRING(cifs_sb, ctx, iocharset);
864 /* if rsize or wsize not passed in on remount, use previous values */
866 ctx->rsize = cifs_sb->ctx->rsize;
868 ctx->wsize = cifs_sb->ctx->wsize;
871 smb3_cleanup_fs_context_contents(cifs_sb->ctx);
872 rc = smb3_fs_context_dup(cifs_sb->ctx, ctx);
873 smb3_update_mnt_flags(cifs_sb);
874 #ifdef CONFIG_CIFS_DFS_UPCALL
876 rc = dfs_cache_remount_fs(cifs_sb);
882 static int smb3_fs_context_parse_param(struct fs_context *fc,
883 struct fs_parameter *param)
885 struct fs_parse_result result;
886 struct smb3_fs_context *ctx = smb3_fc2context(fc);
888 bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
889 bool skip_parsing = false;
893 cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
896 * fs_parse can not handle string options with an empty value so
897 * we will need special handling of them.
899 if (param->type == fs_value_is_string && param->string[0] == 0) {
900 if (!strcmp("pass", param->key) || !strcmp("password", param->key)) {
903 } else if (!strcmp("user", param->key) || !strcmp("username", param->key)) {
910 opt = fs_parse(fc, smb3_fs_parameters, param, &result);
912 return ctx->sloppy ? 1 : opt;
917 ctx->compression = UNKNOWN_TYPE;
919 "SMB3 compression support is experimental\n");
925 if (result.negated) {
927 cifs_dbg(VFS, "conflicting hard vs. soft mount options\n");
937 cifs_dbg(VFS, "conflicting hard vs soft mount options\n");
946 ctx->sfu_remap = false; /* disable SFU mapping */
951 ctx->sfu_remap = false;
953 ctx->sfu_remap = true;
954 ctx->remap = false; /* disable SFM (mapposix) mapping */
965 ctx->override_uid = 0;
967 ctx->override_uid = 1;
971 ctx->override_gid = 0;
973 ctx->override_gid = 1;
993 case Opt_noblocksend:
1008 case Opt_multichannel:
1009 if (result.negated) {
1010 ctx->multichannel = false;
1011 ctx->max_channels = 1;
1013 ctx->multichannel = true;
1014 /* if number of channels not specified, default to 2 */
1015 if (ctx->max_channels < 2)
1016 ctx->max_channels = 2;
1020 uid = make_kuid(current_user_ns(), result.uint_32);
1021 if (!uid_valid(uid))
1022 goto cifs_parse_mount_err;
1023 ctx->linux_uid = uid;
1024 ctx->uid_specified = true;
1027 uid = make_kuid(current_user_ns(), result.uint_32);
1028 if (!uid_valid(uid))
1029 goto cifs_parse_mount_err;
1030 ctx->cred_uid = uid;
1031 ctx->cruid_specified = true;
1034 uid = make_kuid(current_user_ns(), result.uint_32);
1035 if (!uid_valid(uid))
1036 goto cifs_parse_mount_err;
1037 ctx->backupuid = uid;
1038 ctx->backupuid_specified = true;
1041 gid = make_kgid(current_user_ns(), result.uint_32);
1042 if (!gid_valid(gid))
1043 goto cifs_parse_mount_err;
1044 ctx->backupgid = gid;
1045 ctx->backupgid_specified = true;
1048 gid = make_kgid(current_user_ns(), result.uint_32);
1049 if (!gid_valid(gid))
1050 goto cifs_parse_mount_err;
1051 ctx->linux_gid = gid;
1052 ctx->gid_specified = true;
1055 ctx->port = result.uint_32;
1058 ctx->file_mode = result.uint_32;
1061 ctx->dir_mode = result.uint_32;
1063 case Opt_min_enc_offload:
1064 ctx->min_offload = result.uint_32;
1068 * inode blocksize realistically should never need to be
1069 * less than 16K or greater than 16M and default is 1MB.
1070 * Note that small inode block sizes (e.g. 64K) can lead
1071 * to very poor performance of common tools like cp and scp
1073 if ((result.uint_32 < CIFS_MAX_MSGSIZE) ||
1074 (result.uint_32 > (4 * SMB3_DEFAULT_IOSIZE))) {
1075 cifs_errorf(fc, "%s: Invalid blocksize\n",
1077 goto cifs_parse_mount_err;
1079 ctx->bsize = result.uint_32;
1080 ctx->got_bsize = true;
1084 * readahead size realistically should never need to be
1085 * less than 1M (CIFS_DEFAULT_IOSIZE) or greater than 32M
1086 * (perhaps an exception should be considered in the
1087 * for the case of a large number of channels
1088 * when multichannel is negotiated) since that would lead
1089 * to plenty of parallel I/O in flight to the server.
1090 * Note that smaller read ahead sizes would
1091 * hurt performance of common tools like cp and scp
1092 * which often trigger sequential i/o with read ahead
1094 if ((result.uint_32 > (8 * SMB3_DEFAULT_IOSIZE)) ||
1095 (result.uint_32 < CIFS_DEFAULT_IOSIZE)) {
1096 cifs_errorf(fc, "%s: Invalid rasize %d vs. %d\n",
1097 __func__, result.uint_32, SMB3_DEFAULT_IOSIZE);
1098 goto cifs_parse_mount_err;
1100 ctx->rasize = result.uint_32;
1103 ctx->rsize = result.uint_32;
1104 ctx->got_rsize = true;
1107 ctx->wsize = result.uint_32;
1108 ctx->got_wsize = true;
1111 ctx->acregmax = HZ * result.uint_32;
1112 if (ctx->acregmax > CIFS_MAX_ACTIMEO) {
1113 cifs_errorf(fc, "acregmax too large\n");
1114 goto cifs_parse_mount_err;
1118 ctx->acdirmax = HZ * result.uint_32;
1119 if (ctx->acdirmax > CIFS_MAX_ACTIMEO) {
1120 cifs_errorf(fc, "acdirmax too large\n");
1121 goto cifs_parse_mount_err;
1125 if (HZ * result.uint_32 > CIFS_MAX_ACTIMEO) {
1126 cifs_errorf(fc, "timeout too large\n");
1127 goto cifs_parse_mount_err;
1129 if ((ctx->acdirmax != CIFS_DEF_ACTIMEO) ||
1130 (ctx->acregmax != CIFS_DEF_ACTIMEO)) {
1131 cifs_errorf(fc, "actimeo ignored since acregmax or acdirmax specified\n");
1134 ctx->acdirmax = ctx->acregmax = HZ * result.uint_32;
1136 case Opt_closetimeo:
1137 ctx->closetimeo = HZ * result.uint_32;
1138 if (ctx->closetimeo > SMB3_MAX_DCLOSETIMEO) {
1139 cifs_errorf(fc, "closetimeo too large\n");
1140 goto cifs_parse_mount_err;
1143 case Opt_echo_interval:
1144 ctx->echo_interval = result.uint_32;
1147 ctx->snapshot_time = result.uint_64;
1149 case Opt_max_credits:
1150 if (result.uint_32 < 20 || result.uint_32 > 60000) {
1151 cifs_errorf(fc, "%s: Invalid max_credits value\n",
1153 goto cifs_parse_mount_err;
1155 ctx->max_credits = result.uint_32;
1157 case Opt_max_channels:
1158 if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
1159 cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
1160 __func__, CIFS_MAX_CHANNELS);
1161 goto cifs_parse_mount_err;
1163 ctx->max_channels = result.uint_32;
1164 /* If more than one channel requested ... they want multichan */
1165 if (result.uint_32 > 1)
1166 ctx->multichannel = true;
1168 case Opt_handletimeout:
1169 ctx->handle_timeout = result.uint_32;
1170 if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
1171 cifs_errorf(fc, "Invalid handle cache timeout, longer than 16 minutes\n");
1172 goto cifs_parse_mount_err;
1178 switch (smb3_parse_devname(param->string, ctx)) {
1182 cifs_errorf(fc, "Unable to allocate memory for devname\n");
1183 goto cifs_parse_mount_err;
1185 cifs_errorf(fc, "Malformed UNC in devname\n");
1186 goto cifs_parse_mount_err;
1188 cifs_errorf(fc, "Unknown error parsing devname\n");
1189 goto cifs_parse_mount_err;
1191 ctx->source = smb3_fs_context_fullpath(ctx, '/');
1192 if (IS_ERR(ctx->source)) {
1194 cifs_errorf(fc, "OOM when copying UNC string\n");
1195 goto cifs_parse_mount_err;
1197 fc->source = kstrdup(ctx->source, GFP_KERNEL);
1198 if (fc->source == NULL) {
1199 cifs_errorf(fc, "OOM when copying UNC string\n");
1200 goto cifs_parse_mount_err;
1204 kfree(ctx->username);
1205 ctx->username = NULL;
1208 if (strlen(param->string) == 0) {
1209 /* null user, ie. anonymous authentication */
1214 if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
1215 CIFS_MAX_USERNAME_LEN) {
1216 pr_warn("username too long\n");
1217 goto cifs_parse_mount_err;
1219 ctx->username = kstrdup(param->string, GFP_KERNEL);
1220 if (ctx->username == NULL) {
1221 cifs_errorf(fc, "OOM when copying username string\n");
1222 goto cifs_parse_mount_err;
1226 kfree_sensitive(ctx->password);
1227 ctx->password = NULL;
1228 if (strlen(param->string) == 0)
1231 ctx->password = kstrdup(param->string, GFP_KERNEL);
1232 if (ctx->password == NULL) {
1233 cifs_errorf(fc, "OOM when copying password string\n");
1234 goto cifs_parse_mount_err;
1238 if (strlen(param->string) == 0) {
1239 ctx->got_ip = false;
1242 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
1244 strlen(param->string))) {
1245 pr_err("bad ip= option (%s)\n", param->string);
1246 goto cifs_parse_mount_err;
1251 if (strnlen(param->string, CIFS_MAX_DOMAINNAME_LEN)
1252 == CIFS_MAX_DOMAINNAME_LEN) {
1253 pr_warn("domain name too long\n");
1254 goto cifs_parse_mount_err;
1257 kfree(ctx->domainname);
1258 ctx->domainname = kstrdup(param->string, GFP_KERNEL);
1259 if (ctx->domainname == NULL) {
1260 cifs_errorf(fc, "OOM when copying domainname string\n");
1261 goto cifs_parse_mount_err;
1263 cifs_dbg(FYI, "Domain name set\n");
1266 if (!cifs_convert_address(
1267 (struct sockaddr *)&ctx->srcaddr,
1268 param->string, strlen(param->string))) {
1269 pr_warn("Could not parse srcaddr: %s\n",
1271 goto cifs_parse_mount_err;
1275 if (strnlen(param->string, 1024) >= 65) {
1276 pr_warn("iocharset name too long\n");
1277 goto cifs_parse_mount_err;
1280 if (strncasecmp(param->string, "default", 7) != 0) {
1281 kfree(ctx->iocharset);
1282 ctx->iocharset = kstrdup(param->string, GFP_KERNEL);
1283 if (ctx->iocharset == NULL) {
1284 cifs_errorf(fc, "OOM when copying iocharset string\n");
1285 goto cifs_parse_mount_err;
1288 /* if iocharset not set then load_nls_default
1291 cifs_dbg(FYI, "iocharset set to %s\n", ctx->iocharset);
1293 case Opt_netbiosname:
1294 memset(ctx->source_rfc1001_name, 0x20,
1297 * FIXME: are there cases in which a comma can
1298 * be valid in workstation netbios name (and
1299 * need special handling)?
1301 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1302 /* don't ucase netbiosname for user */
1303 if (param->string[i] == 0)
1305 ctx->source_rfc1001_name[i] = param->string[i];
1307 /* The string has 16th byte zero still from
1308 * set at top of the function
1310 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1311 pr_warn("netbiosname longer than 15 truncated\n");
1314 /* last byte, type, is 0x20 for servr type */
1315 memset(ctx->target_rfc1001_name, 0x20,
1316 RFC1001_NAME_LEN_WITH_NULL);
1318 * BB are there cases in which a comma can be valid in this
1319 * workstation netbios name (and need special handling)?
1322 /* user or mount helper must uppercase the netbios name */
1323 for (i = 0; i < 15; i++) {
1324 if (param->string[i] == 0)
1326 ctx->target_rfc1001_name[i] = param->string[i];
1329 /* The string has 16th byte zero still from set at top of function */
1330 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1331 pr_warn("server netbiosname longer than 15 truncated\n");
1334 /* version of mount userspace tools, not dialect */
1335 /* If interface changes in mount.cifs bump to new ver */
1336 if (strncasecmp(param->string, "1", 1) == 0) {
1337 if (strlen(param->string) > 1) {
1338 pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
1340 goto cifs_parse_mount_err;
1342 /* This is the default */
1345 /* For all other value, error */
1346 pr_warn("Invalid mount helper version specified\n");
1347 goto cifs_parse_mount_err;
1349 /* protocol version (dialect) */
1350 if (cifs_parse_smb_version(fc, param->string, ctx, is_smb3) != 0)
1351 goto cifs_parse_mount_err;
1352 ctx->got_version = true;
1355 if (cifs_parse_security_flavors(fc, param->string, ctx) != 0)
1356 goto cifs_parse_mount_err;
1359 if (cifs_parse_cache_flavor(fc, param->string, ctx) != 0)
1360 goto cifs_parse_mount_err;
1363 #ifndef CONFIG_CIFS_SWN_UPCALL
1364 cifs_errorf(fc, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
1365 goto cifs_parse_mount_err;
1367 ctx->witness = true;
1368 pr_warn_once("Witness protocol support is experimental\n");
1371 #ifndef CONFIG_CIFS_ROOT
1372 cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
1373 goto cifs_parse_mount_err;
1377 case Opt_posixpaths:
1379 ctx->posix_paths = 0;
1381 ctx->posix_paths = 1;
1384 if (result.negated) {
1385 if (ctx->linux_ext == 1)
1386 pr_warn_once("conflicting posix mount options specified\n");
1388 ctx->no_linux_ext = 1;
1390 if (ctx->no_linux_ext == 1)
1391 pr_warn_once("conflicting posix mount options specified\n");
1393 ctx->no_linux_ext = 0;
1400 if (result.negated) {
1402 * turn off mandatory locking in mode
1403 * if remote locking is turned off since the
1404 * local vfs will do advisory
1406 if (ctx->file_mode ==
1407 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1408 ctx->file_mode = S_IALLUGO;
1413 case Opt_handlecache:
1415 ctx->nohandlecache = 1;
1417 ctx->nohandlecache = 0;
1419 case Opt_forcemandatorylock:
1423 ctx->setuids = result.negated;
1426 ctx->intr = !result.negated;
1428 case Opt_setuidfromacl:
1429 ctx->setuidfromacl = 1;
1431 case Opt_strictsync:
1432 ctx->nostrictsync = result.negated;
1435 ctx->server_ino = !result.negated;
1437 case Opt_rwpidforward:
1438 ctx->rwpidforward = 1;
1444 ctx->cifs_acl = !result.negated;
1447 ctx->no_psx_acl = result.negated;
1449 case Opt_locallease:
1450 ctx->local_lease = 1;
1455 case Opt_ignore_signature:
1457 ctx->ignore_signature = true;
1460 /* we do not do the following in secFlags because seal
1461 * is a per tree connection (mount) not a per socket
1462 * or per-smb connection option in the protocol
1463 * vol->secFlg |= CIFSSEC_MUST_SEAL;
1468 pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
1471 #ifndef CONFIG_CIFS_FSCACHE
1472 cifs_errorf(fc, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
1473 goto cifs_parse_mount_err;
1477 case Opt_mfsymlinks:
1478 ctx->mfsymlinks = true;
1481 ctx->multiuser = true;
1486 case Opt_nosharesock:
1487 ctx->nosharesock = true;
1489 case Opt_persistent:
1490 if (result.negated) {
1491 ctx->nopersistent = true;
1492 if (ctx->persistent) {
1493 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1494 goto cifs_parse_mount_err;
1497 ctx->persistent = true;
1498 if ((ctx->nopersistent) || (ctx->resilient)) {
1499 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1500 goto cifs_parse_mount_err;
1505 if (result.negated) {
1506 ctx->resilient = false; /* already the default */
1508 ctx->resilient = true;
1509 if (ctx->persistent) {
1510 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1511 goto cifs_parse_mount_err;
1515 case Opt_tcp_nodelay:
1516 /* tcp nodelay should not usually be needed since we CORK/UNCORK the socket */
1518 ctx->sockopt_tcp_nodelay = false;
1520 ctx->sockopt_tcp_nodelay = true;
1522 case Opt_domainauto:
1523 ctx->domainauto = true;
1529 /* case Opt_ignore: - is ignored as expected ... */
1533 cifs_parse_mount_err:
1534 kfree_sensitive(ctx->password);
1538 int smb3_init_fs_context(struct fs_context *fc)
1540 struct smb3_fs_context *ctx;
1541 char *nodename = utsname()->nodename;
1544 ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
1548 strscpy(ctx->workstation_name, nodename, sizeof(ctx->workstation_name));
1551 * does not have to be perfect mapping since field is
1552 * informational, only used for servers that do not support
1553 * port 445 and it can be overridden at mount time
1555 memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
1556 for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
1557 ctx->source_rfc1001_name[i] = toupper(nodename[i]);
1559 ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
1561 * null target name indicates to use *SMBSERVR default called name
1562 * if we end up sending RFC1001 session initialize
1564 ctx->target_rfc1001_name[0] = 0;
1565 ctx->cred_uid = current_uid();
1566 ctx->linux_uid = current_uid();
1567 ctx->linux_gid = current_gid();
1568 /* By default 4MB read ahead size, 1MB block size */
1569 ctx->bsize = CIFS_DEFAULT_IOSIZE; /* can improve cp performance significantly */
1570 ctx->rasize = 0; /* 0 = use default (ie negotiated rsize) for read ahead pages */
1573 * default to SFM style remapping of seven reserved characters
1574 * unless user overrides it or we negotiate CIFS POSIX where
1575 * it is unnecessary. Can not simultaneously use more than one mapping
1576 * since then readdir could list files that open could not open
1580 /* default to only allowing write access to owner of the mount */
1581 ctx->dir_mode = ctx->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
1583 /* ctx->retry default is 0 (i.e. "soft" limited retry not hard retry) */
1584 /* default is always to request posix paths. */
1585 ctx->posix_paths = 1;
1586 /* default to using server inode numbers where available */
1587 ctx->server_ino = 1;
1589 /* default is to use strict cifs caching semantics */
1590 ctx->strict_io = true;
1592 ctx->acregmax = CIFS_DEF_ACTIMEO;
1593 ctx->acdirmax = CIFS_DEF_ACTIMEO;
1594 ctx->closetimeo = SMB3_DEF_DCLOSETIMEO;
1596 /* Most clients set timeout to 0, allows server to use its default */
1597 ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
1599 /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
1600 ctx->ops = &smb30_operations;
1601 ctx->vals = &smbdefault_values;
1603 ctx->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
1605 /* default to no multichannel (single server connection) */
1606 ctx->multichannel = false;
1607 ctx->max_channels = 1;
1609 ctx->backupuid_specified = false; /* no backup intent for a user */
1610 ctx->backupgid_specified = false; /* no backup intent for a group */
1613 * short int override_uid = -1;
1614 * short int override_gid = -1;
1615 * char *nodename = strdup(utsname()->nodename);
1616 * struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
1619 fc->fs_private = ctx;
1620 fc->ops = &smb3_fs_context_ops;
1625 smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
1631 * Make sure this stays in sync with smb3_fs_context_dup()
1633 kfree(ctx->username);
1634 ctx->username = NULL;
1635 kfree_sensitive(ctx->password);
1636 ctx->password = NULL;
1637 kfree(ctx->server_hostname);
1638 ctx->server_hostname = NULL;
1643 kfree(ctx->domainname);
1644 ctx->domainname = NULL;
1645 kfree(ctx->nodename);
1646 ctx->nodename = NULL;
1647 kfree(ctx->iocharset);
1648 ctx->iocharset = NULL;
1649 kfree(ctx->prepath);
1650 ctx->prepath = NULL;
1651 kfree(ctx->leaf_fullpath);
1652 ctx->leaf_fullpath = NULL;
1656 smb3_cleanup_fs_context(struct smb3_fs_context *ctx)
1660 smb3_cleanup_fs_context_contents(ctx);
1664 void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
1666 struct smb3_fs_context *ctx = cifs_sb->ctx;
1669 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS;
1671 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_DFS;
1674 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
1676 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_PERM;
1679 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
1681 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SET_UID;
1683 if (ctx->setuidfromacl)
1684 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL;
1686 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UID_FROM_ACL;
1688 if (ctx->server_ino)
1689 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
1691 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
1694 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR;
1696 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SFM_CHR;
1699 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
1701 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SPECIAL_CHR;
1704 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
1706 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_XATTR;
1709 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
1711 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UNX_EMUL;
1714 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
1716 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_BRL;
1718 if (ctx->nohandlecache)
1719 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE;
1721 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_HANDLE_CACHE;
1723 if (ctx->nostrictsync)
1724 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
1726 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOSSYNC;
1729 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
1731 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOPOSIXBRL;
1733 if (ctx->rwpidforward)
1734 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
1736 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_RWPIDFORWARD;
1739 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MODE_FROM_SID;
1741 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MODE_FROM_SID;
1744 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
1746 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_ACL;
1748 if (ctx->backupuid_specified)
1749 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
1751 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPUID;
1753 if (ctx->backupgid_specified)
1754 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
1756 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPGID;
1758 if (ctx->override_uid)
1759 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
1761 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_UID;
1763 if (ctx->override_gid)
1764 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
1766 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_GID;
1769 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
1771 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DYNPERM;
1774 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
1776 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_FSCACHE;
1779 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
1780 CIFS_MOUNT_NO_PERM);
1782 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MULTIUSER;
1786 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
1788 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_STRICT_IO;
1791 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
1793 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DIRECT_IO;
1795 if (ctx->mfsymlinks)
1796 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
1798 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MF_SYMLINKS;
1799 if (ctx->mfsymlinks) {
1800 if (ctx->sfu_emul) {
1802 * Our SFU ("Services for Unix" emulation does not allow
1803 * creating symlinks but does allow reading existing SFU
1804 * symlinks (it does allow both creating and reading SFU
1805 * style mknod and FIFOs though). When "mfsymlinks" and
1806 * "sfu" are both enabled at the same time, it allows
1807 * reading both types of symlinks, but will only create
1808 * them with mfsymlinks format. This allows better
1809 * Apple compatibility (probably better for Samba too)
1810 * while still recognizing old Windows style symlinks.
1812 cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
1815 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SHUTDOWN;