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 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("retrans", Opt_retrans),
143 fsparam_u32("esize", Opt_min_enc_offload),
144 fsparam_u32("bsize", Opt_blocksize),
145 fsparam_u32("rasize", Opt_rasize),
146 fsparam_u32("rsize", Opt_rsize),
147 fsparam_u32("wsize", Opt_wsize),
148 fsparam_u32("actimeo", Opt_actimeo),
149 fsparam_u32("acdirmax", Opt_acdirmax),
150 fsparam_u32("acregmax", Opt_acregmax),
151 fsparam_u32("closetimeo", Opt_closetimeo),
152 fsparam_u32("echo_interval", Opt_echo_interval),
153 fsparam_u32("max_credits", Opt_max_credits),
154 fsparam_u32("max_cached_dirs", Opt_max_cached_dirs),
155 fsparam_u32("handletimeout", Opt_handletimeout),
156 fsparam_u64("snapshot", Opt_snapshot),
157 fsparam_u32("max_channels", Opt_max_channels),
159 /* Mount options which take string value */
160 fsparam_string("source", Opt_source),
161 fsparam_string("user", Opt_user),
162 fsparam_string("username", Opt_user),
163 fsparam_string("pass", Opt_pass),
164 fsparam_string("password", Opt_pass),
165 fsparam_string("ip", Opt_ip),
166 fsparam_string("addr", Opt_ip),
167 fsparam_string("domain", Opt_domain),
168 fsparam_string("dom", Opt_domain),
169 fsparam_string("srcaddr", Opt_srcaddr),
170 fsparam_string("iocharset", Opt_iocharset),
171 fsparam_string("netbiosname", Opt_netbiosname),
172 fsparam_string("servern", Opt_servern),
173 fsparam_string("ver", Opt_ver),
174 fsparam_string("vers", Opt_vers),
175 fsparam_string("sec", Opt_sec),
176 fsparam_string("cache", Opt_cache),
178 /* Arguments that should be ignored */
179 fsparam_flag("guest", Opt_ignore),
180 fsparam_flag("noatime", Opt_ignore),
181 fsparam_flag("relatime", Opt_ignore),
182 fsparam_flag("_netdev", Opt_ignore),
183 fsparam_flag_no("suid", Opt_ignore),
184 fsparam_flag_no("exec", Opt_ignore),
185 fsparam_flag_no("dev", Opt_ignore),
186 fsparam_flag_no("mand", Opt_ignore),
187 fsparam_flag_no("auto", Opt_ignore),
188 fsparam_string("cred", Opt_ignore),
189 fsparam_string("credentials", Opt_ignore),
191 * UNC and prefixpath is now extracted from Opt_source
192 * in the new mount API so we can just ignore them going forward.
194 fsparam_string("unc", Opt_ignore),
195 fsparam_string("prefixpath", Opt_ignore),
200 cifs_parse_security_flavors(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
203 substring_t args[MAX_OPT_ARGS];
206 * With mount options, the last one should win. Reset any existing
207 * settings back to default.
209 ctx->sectype = Unspecified;
212 switch (match_token(value, cifs_secflavor_tokens, args)) {
214 cifs_errorf(fc, "sec=krb5p is not supported. Use sec=krb5,seal instead\n");
220 ctx->sectype = Kerberos;
222 case Opt_sec_ntlmsspi:
225 case Opt_sec_ntlmssp:
226 ctx->sectype = RawNTLMSSP;
228 case Opt_sec_ntlmv2i:
232 ctx->sectype = NTLMv2;
236 kfree(ctx->username);
237 ctx->username = NULL;
240 cifs_errorf(fc, "bad security option: %s\n", value);
247 static const match_table_t cifs_cacheflavor_tokens = {
248 { Opt_cache_loose, "loose" },
249 { Opt_cache_strict, "strict" },
250 { Opt_cache_none, "none" },
251 { Opt_cache_ro, "ro" },
252 { Opt_cache_rw, "singleclient" },
253 { Opt_cache_err, NULL }
257 cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
259 substring_t args[MAX_OPT_ARGS];
261 switch (match_token(value, cifs_cacheflavor_tokens, args)) {
262 case Opt_cache_loose:
263 ctx->direct_io = false;
264 ctx->strict_io = false;
265 ctx->cache_ro = false;
266 ctx->cache_rw = false;
268 case Opt_cache_strict:
269 ctx->direct_io = false;
270 ctx->strict_io = true;
271 ctx->cache_ro = false;
272 ctx->cache_rw = false;
275 ctx->direct_io = true;
276 ctx->strict_io = false;
277 ctx->cache_ro = false;
278 ctx->cache_rw = false;
281 ctx->direct_io = false;
282 ctx->strict_io = false;
283 ctx->cache_ro = true;
284 ctx->cache_rw = false;
287 ctx->direct_io = false;
288 ctx->strict_io = false;
289 ctx->cache_ro = false;
290 ctx->cache_rw = true;
293 cifs_errorf(fc, "bad cache= option: %s\n", value);
299 #define DUP_CTX_STR(field) \
302 new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
303 if (new_ctx->field == NULL) { \
304 smb3_cleanup_fs_context_contents(new_ctx); \
311 smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
313 memcpy(new_ctx, ctx, sizeof(*ctx));
314 new_ctx->prepath = NULL;
315 new_ctx->nodename = NULL;
316 new_ctx->username = NULL;
317 new_ctx->password = NULL;
318 new_ctx->server_hostname = NULL;
319 new_ctx->domainname = NULL;
321 new_ctx->source = NULL;
322 new_ctx->iocharset = NULL;
323 new_ctx->leaf_fullpath = NULL;
325 * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
327 DUP_CTX_STR(prepath);
328 DUP_CTX_STR(username);
329 DUP_CTX_STR(password);
330 DUP_CTX_STR(server_hostname);
333 DUP_CTX_STR(domainname);
334 DUP_CTX_STR(nodename);
335 DUP_CTX_STR(iocharset);
336 DUP_CTX_STR(leaf_fullpath);
342 cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_context *ctx, bool is_smb3)
344 substring_t args[MAX_OPT_ARGS];
346 switch (match_token(value, cifs_smb_version_tokens, args)) {
347 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
349 if (disable_legacy_dialects) {
350 cifs_errorf(fc, "mount with legacy dialect disabled\n");
354 cifs_errorf(fc, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
357 cifs_errorf(fc, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
358 ctx->ops = &smb1_operations;
359 ctx->vals = &smb1_values;
362 if (disable_legacy_dialects) {
363 cifs_errorf(fc, "mount with legacy dialect disabled\n");
367 cifs_errorf(fc, "vers=2.0 not permitted when mounting with smb3\n");
370 ctx->ops = &smb20_operations;
371 ctx->vals = &smb20_values;
375 cifs_errorf(fc, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
378 cifs_errorf(fc, "vers=2.0 mount not permitted when legacy dialects disabled\n");
380 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
382 ctx->ops = &smb21_operations;
383 ctx->vals = &smb21_values;
386 ctx->ops = &smb30_operations;
387 ctx->vals = &smb30_values;
390 ctx->ops = &smb30_operations; /* currently identical with 3.0 */
391 ctx->vals = &smb302_values;
394 ctx->ops = &smb311_operations;
395 ctx->vals = &smb311_values;
398 ctx->ops = &smb30_operations; /* currently identical with 3.0 */
399 ctx->vals = &smb3any_values;
402 ctx->ops = &smb30_operations;
403 ctx->vals = &smbdefault_values;
406 cifs_errorf(fc, "Unknown vers= option specified: %s\n", value);
412 int smb3_parse_opt(const char *options, const char *key, char **val)
415 char *opts, *orig, *p;
417 orig = opts = kstrdup(options, GFP_KERNEL);
421 while ((p = strsep(&opts, ","))) {
426 if (strncasecmp(p, key, strlen(key)))
428 nval = strchr(p, '=');
433 *val = kstrdup(nval, GFP_KERNEL);
434 rc = !*val ? -ENOMEM : 0;
444 * Remove duplicate path delimiters. Windows is supposed to do that
445 * but there are some bugs that prevent rename from working if there are
446 * multiple delimiters.
448 * Return a sanitized duplicate of @path or NULL for empty prefix paths.
449 * Otherwise, return ERR_PTR.
451 * @gfp indicates the GFP_* flags for kstrdup.
452 * The caller is responsible for freeing the original.
454 #define IS_DELIM(c) ((c) == '/' || (c) == '\\')
455 char *cifs_sanitize_prepath(char *prepath, gfp_t gfp)
457 char *cursor1 = prepath, *cursor2 = prepath;
460 /* skip all prepended delimiters */
461 while (IS_DELIM(*cursor1))
464 /* copy the first letter */
467 /* copy the remainder... */
468 while (*(cursor1++)) {
469 /* ... skipping all duplicated delimiters */
470 if (IS_DELIM(*cursor1) && IS_DELIM(*cursor2))
472 *(++cursor2) = *cursor1;
475 /* if the last character is a delimiter, skip it */
476 if (IS_DELIM(*(cursor2 - 1)))
482 s = kstrdup(prepath, gfp);
484 return ERR_PTR(-ENOMEM);
489 * Return full path based on the values of @ctx->{UNC,prepath}.
491 * It is assumed that both values were already parsed by smb3_parse_devname().
493 char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx, char dirsep)
498 ulen = strlen(ctx->UNC);
499 plen = ctx->prepath ? strlen(ctx->prepath) + 1 : 0;
501 s = kmalloc(ulen + plen + 1, GFP_KERNEL);
503 return ERR_PTR(-ENOMEM);
504 memcpy(s, ctx->UNC, ulen);
507 memcpy(s + ulen + 1, ctx->prepath, plen);
509 s[ulen + plen] = '\0';
510 convert_delimiter(s, dirsep);
515 * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
516 * fields with the result. Returns 0 on success and an error otherwise
517 * (e.g. ENOMEM or EINVAL)
520 smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
523 const char *delims = "/\\";
527 if (unlikely(!devname || !*devname)) {
528 cifs_dbg(VFS, "Device name not specified\n");
532 /* make sure we have a valid UNC double delimiter prefix */
533 len = strspn(devname, delims);
537 /* find delimiter between host and sharename */
538 pos = strpbrk(devname + 2, delims);
542 /* record the server hostname */
543 kfree(ctx->server_hostname);
544 ctx->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL);
545 if (!ctx->server_hostname)
548 /* skip past delimiter */
551 /* now go until next delimiter or end of string */
552 len = strcspn(pos, delims);
556 /* move "pos" up to delimiter or NULL */
559 ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
563 convert_delimiter(ctx->UNC, '\\');
565 /* skip any delimiter */
566 if (*pos == '/' || *pos == '\\')
572 /* If pos is NULL then no prepath */
576 ctx->prepath = cifs_sanitize_prepath(pos, GFP_KERNEL);
577 if (IS_ERR(ctx->prepath)) {
578 rc = PTR_ERR(ctx->prepath);
586 static void smb3_fs_context_free(struct fs_context *fc);
587 static int smb3_fs_context_parse_param(struct fs_context *fc,
588 struct fs_parameter *param);
589 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
591 static int smb3_get_tree(struct fs_context *fc);
592 static int smb3_reconfigure(struct fs_context *fc);
594 static const struct fs_context_operations smb3_fs_context_ops = {
595 .free = smb3_fs_context_free,
596 .parse_param = smb3_fs_context_parse_param,
597 .parse_monolithic = smb3_fs_context_parse_monolithic,
598 .get_tree = smb3_get_tree,
599 .reconfigure = smb3_reconfigure,
603 * Parse a monolithic block of data from sys_mount().
604 * smb3_fs_context_parse_monolithic - Parse key[=val][,key[=val]]* mount data
605 * @ctx: The superblock configuration to fill in.
606 * @data: The data to parse
608 * Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
609 * called from the ->monolithic_mount_data() fs_context operation.
611 * Returns 0 on success or the error returned by the ->parse_option() fs_context
612 * operation on failure.
614 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
617 char *options = data, *key;
623 ret = security_sb_eat_lsm_opts(options, &fc->security);
627 /* BB Need to add support for sep= here TBD */
628 while ((key = strsep(&options, ",")) != NULL) {
635 /* Check if following character is the deliminator If yes,
636 * we have encountered a double deliminator reset the NULL
637 * character to the deliminator
639 while (options && options[0] == ',') {
641 strcpy(key + len, options);
642 options = strchr(options, ',');
649 value = strchr(key, '=');
657 ret = vfs_parse_fs_string(fc, key, value, len);
666 * Validate the preparsed information in the config.
668 static int smb3_fs_context_validate(struct fs_context *fc)
670 struct smb3_fs_context *ctx = smb3_fc2context(fc);
672 if (ctx->rdma && ctx->vals->protocol_id < SMB30_PROT_ID) {
673 cifs_errorf(fc, "SMB Direct requires Version >=3.0\n");
678 /* Muliuser mounts require CONFIG_KEYS support */
679 if (ctx->multiuser) {
680 cifs_errorf(fc, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
685 if (ctx->got_version == false)
686 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");
690 cifs_errorf(fc, "CIFS mount error: No usable UNC path provided in device string!\n");
694 /* make sure UNC has a share name */
695 if (strlen(ctx->UNC) < 3 || !strchr(ctx->UNC + 3, '\\')) {
696 cifs_errorf(fc, "Malformed UNC. Unable to find share name.\n");
704 /* No ip= option specified? Try to get it from UNC */
705 /* Use the address part of the UNC. */
706 slash = strchr(&ctx->UNC[2], '\\');
707 len = slash - &ctx->UNC[2];
708 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
709 &ctx->UNC[2], len)) {
710 pr_err("Unable to determine destination address\n");
711 return -EHOSTUNREACH;
715 /* set the port that we got earlier */
716 cifs_set_port((struct sockaddr *)&ctx->dstaddr, ctx->port);
718 if (ctx->override_uid && !ctx->uid_specified) {
719 ctx->override_uid = 0;
720 pr_notice("ignoring forceuid mount option specified with no uid= option\n");
723 if (ctx->override_gid && !ctx->gid_specified) {
724 ctx->override_gid = 0;
725 pr_notice("ignoring forcegid mount option specified with no gid= option\n");
731 static int smb3_get_tree_common(struct fs_context *fc)
733 struct smb3_fs_context *ctx = smb3_fc2context(fc);
737 root = cifs_smb3_do_mount(fc->fs_type, 0, ctx);
739 return PTR_ERR(root);
747 * Create an SMB3 superblock from the parameters passed.
749 static int smb3_get_tree(struct fs_context *fc)
751 int err = smb3_fs_context_validate(fc);
757 ret = smb3_get_tree_common(fc);
762 static void smb3_fs_context_free(struct fs_context *fc)
764 struct smb3_fs_context *ctx = smb3_fc2context(fc);
766 smb3_cleanup_fs_context(ctx);
770 * Compare the old and new proposed context during reconfigure
771 * and check if the changes are compatible.
773 static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
774 struct smb3_fs_context *new_ctx,
775 struct smb3_fs_context *old_ctx, bool need_recon)
777 if (new_ctx->posix_paths != old_ctx->posix_paths) {
778 cifs_errorf(fc, "can not change posixpaths during remount\n");
781 if (new_ctx->sectype != old_ctx->sectype) {
782 cifs_errorf(fc, "can not change sec during remount\n");
785 if (new_ctx->multiuser != old_ctx->multiuser) {
786 cifs_errorf(fc, "can not change multiuser during remount\n");
790 (!old_ctx->UNC || strcmp(new_ctx->UNC, old_ctx->UNC))) {
791 cifs_errorf(fc, "can not change UNC during remount\n");
794 if (new_ctx->username &&
795 (!old_ctx->username || strcmp(new_ctx->username, old_ctx->username))) {
796 cifs_errorf(fc, "can not change username during remount\n");
799 if (new_ctx->password &&
800 (!old_ctx->password || strcmp(new_ctx->password, old_ctx->password))) {
801 if (need_recon == false) {
803 "can not change password of active session during remount\n");
805 } else if (old_ctx->sectype == Kerberos) {
807 "can not change password for Kerberos via remount\n");
811 if (new_ctx->domainname &&
812 (!old_ctx->domainname || strcmp(new_ctx->domainname, old_ctx->domainname))) {
813 cifs_errorf(fc, "can not change domainname during remount\n");
816 if (strcmp(new_ctx->workstation_name, old_ctx->workstation_name)) {
817 cifs_errorf(fc, "can not change workstation_name during remount\n");
820 if (new_ctx->nodename &&
821 (!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
822 cifs_errorf(fc, "can not change nodename during remount\n");
825 if (new_ctx->iocharset &&
826 (!old_ctx->iocharset || strcmp(new_ctx->iocharset, old_ctx->iocharset))) {
827 cifs_errorf(fc, "can not change iocharset during remount\n");
834 #define STEAL_STRING(cifs_sb, ctx, field) \
837 ctx->field = cifs_sb->ctx->field; \
838 cifs_sb->ctx->field = NULL; \
841 #define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field) \
843 kfree_sensitive(ctx->field); \
844 ctx->field = cifs_sb->ctx->field; \
845 cifs_sb->ctx->field = NULL; \
848 static int smb3_reconfigure(struct fs_context *fc)
850 struct smb3_fs_context *ctx = smb3_fc2context(fc);
851 struct dentry *root = fc->root;
852 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
853 struct cifs_ses *ses = cifs_sb_master_tcon(cifs_sb)->ses;
854 bool need_recon = false;
857 if (ses->expired_pwd)
860 rc = smb3_verify_reconfigure_ctx(fc, ctx, cifs_sb->ctx, need_recon);
865 * We can not change UNC/username/password/domainname/
866 * workstation_name/nodename/iocharset
867 * during reconnect so ignore what we have in the new context and
868 * just use what we already have in cifs_sb->ctx.
870 STEAL_STRING(cifs_sb, ctx, UNC);
871 STEAL_STRING(cifs_sb, ctx, source);
872 STEAL_STRING(cifs_sb, ctx, username);
873 if (need_recon == false)
874 STEAL_STRING_SENSITIVE(cifs_sb, ctx, password);
876 kfree_sensitive(ses->password);
877 ses->password = kstrdup(ctx->password, GFP_KERNEL);
879 STEAL_STRING(cifs_sb, ctx, domainname);
880 STEAL_STRING(cifs_sb, ctx, nodename);
881 STEAL_STRING(cifs_sb, ctx, iocharset);
883 /* if rsize or wsize not passed in on remount, use previous values */
885 ctx->rsize = cifs_sb->ctx->rsize;
887 ctx->wsize = cifs_sb->ctx->wsize;
890 smb3_cleanup_fs_context_contents(cifs_sb->ctx);
891 rc = smb3_fs_context_dup(cifs_sb->ctx, ctx);
892 smb3_update_mnt_flags(cifs_sb);
893 #ifdef CONFIG_CIFS_DFS_UPCALL
895 rc = dfs_cache_remount_fs(cifs_sb);
901 static int smb3_fs_context_parse_param(struct fs_context *fc,
902 struct fs_parameter *param)
904 struct fs_parse_result result;
905 struct smb3_fs_context *ctx = smb3_fc2context(fc);
907 bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
908 bool skip_parsing = false;
912 cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
915 * fs_parse can not handle string options with an empty value so
916 * we will need special handling of them.
918 if (param->type == fs_value_is_string && param->string[0] == 0) {
919 if (!strcmp("pass", param->key) || !strcmp("password", param->key)) {
922 } else if (!strcmp("user", param->key) || !strcmp("username", param->key)) {
929 opt = fs_parse(fc, smb3_fs_parameters, param, &result);
931 return ctx->sloppy ? 1 : opt;
936 ctx->compression = UNKNOWN_TYPE;
938 "SMB3 compression support is experimental\n");
944 if (result.negated) {
946 cifs_dbg(VFS, "conflicting hard vs. soft mount options\n");
956 cifs_dbg(VFS, "conflicting hard vs soft mount options\n");
965 ctx->sfu_remap = false; /* disable SFU mapping */
970 ctx->sfu_remap = false;
972 ctx->sfu_remap = true;
973 ctx->remap = false; /* disable SFM (mapposix) mapping */
984 ctx->override_uid = 0;
986 ctx->override_uid = 1;
990 ctx->override_gid = 0;
992 ctx->override_gid = 1;
1012 case Opt_noblocksend:
1013 ctx->noblocksnd = 1;
1015 case Opt_noautotune:
1016 ctx->noautotune = 1;
1027 case Opt_multichannel:
1028 if (result.negated) {
1029 ctx->multichannel = false;
1030 ctx->max_channels = 1;
1032 ctx->multichannel = true;
1033 /* if number of channels not specified, default to 2 */
1034 if (ctx->max_channels < 2)
1035 ctx->max_channels = 2;
1039 uid = make_kuid(current_user_ns(), result.uint_32);
1040 if (!uid_valid(uid))
1041 goto cifs_parse_mount_err;
1042 ctx->linux_uid = uid;
1043 ctx->uid_specified = true;
1046 uid = make_kuid(current_user_ns(), result.uint_32);
1047 if (!uid_valid(uid))
1048 goto cifs_parse_mount_err;
1049 ctx->cred_uid = uid;
1050 ctx->cruid_specified = true;
1053 uid = make_kuid(current_user_ns(), result.uint_32);
1054 if (!uid_valid(uid))
1055 goto cifs_parse_mount_err;
1056 ctx->backupuid = uid;
1057 ctx->backupuid_specified = true;
1060 gid = make_kgid(current_user_ns(), result.uint_32);
1061 if (!gid_valid(gid))
1062 goto cifs_parse_mount_err;
1063 ctx->backupgid = gid;
1064 ctx->backupgid_specified = true;
1067 gid = make_kgid(current_user_ns(), result.uint_32);
1068 if (!gid_valid(gid))
1069 goto cifs_parse_mount_err;
1070 ctx->linux_gid = gid;
1071 ctx->gid_specified = true;
1074 ctx->port = result.uint_32;
1077 ctx->file_mode = result.uint_32;
1080 ctx->dir_mode = result.uint_32;
1082 case Opt_min_enc_offload:
1083 ctx->min_offload = result.uint_32;
1086 ctx->retrans = result.uint_32;
1090 * inode blocksize realistically should never need to be
1091 * less than 16K or greater than 16M and default is 1MB.
1092 * Note that small inode block sizes (e.g. 64K) can lead
1093 * to very poor performance of common tools like cp and scp
1095 if ((result.uint_32 < CIFS_MAX_MSGSIZE) ||
1096 (result.uint_32 > (4 * SMB3_DEFAULT_IOSIZE))) {
1097 cifs_errorf(fc, "%s: Invalid blocksize\n",
1099 goto cifs_parse_mount_err;
1101 ctx->bsize = result.uint_32;
1102 ctx->got_bsize = true;
1106 * readahead size realistically should never need to be
1107 * less than 1M (CIFS_DEFAULT_IOSIZE) or greater than 32M
1108 * (perhaps an exception should be considered in the
1109 * for the case of a large number of channels
1110 * when multichannel is negotiated) since that would lead
1111 * to plenty of parallel I/O in flight to the server.
1112 * Note that smaller read ahead sizes would
1113 * hurt performance of common tools like cp and scp
1114 * which often trigger sequential i/o with read ahead
1116 if ((result.uint_32 > (8 * SMB3_DEFAULT_IOSIZE)) ||
1117 (result.uint_32 < CIFS_DEFAULT_IOSIZE)) {
1118 cifs_errorf(fc, "%s: Invalid rasize %d vs. %d\n",
1119 __func__, result.uint_32, SMB3_DEFAULT_IOSIZE);
1120 goto cifs_parse_mount_err;
1122 ctx->rasize = result.uint_32;
1125 ctx->rsize = result.uint_32;
1126 ctx->got_rsize = true;
1129 ctx->wsize = result.uint_32;
1130 ctx->got_wsize = true;
1131 if (ctx->wsize % PAGE_SIZE != 0) {
1132 ctx->wsize = round_down(ctx->wsize, PAGE_SIZE);
1133 if (ctx->wsize == 0) {
1134 ctx->wsize = PAGE_SIZE;
1135 cifs_dbg(VFS, "wsize too small, reset to minimum %ld\n", PAGE_SIZE);
1138 "wsize rounded down to %d to multiple of PAGE_SIZE %ld\n",
1139 ctx->wsize, PAGE_SIZE);
1144 ctx->acregmax = HZ * result.uint_32;
1145 if (ctx->acregmax > CIFS_MAX_ACTIMEO) {
1146 cifs_errorf(fc, "acregmax too large\n");
1147 goto cifs_parse_mount_err;
1151 ctx->acdirmax = HZ * result.uint_32;
1152 if (ctx->acdirmax > CIFS_MAX_ACTIMEO) {
1153 cifs_errorf(fc, "acdirmax too large\n");
1154 goto cifs_parse_mount_err;
1158 if (HZ * result.uint_32 > CIFS_MAX_ACTIMEO) {
1159 cifs_errorf(fc, "timeout too large\n");
1160 goto cifs_parse_mount_err;
1162 if ((ctx->acdirmax != CIFS_DEF_ACTIMEO) ||
1163 (ctx->acregmax != CIFS_DEF_ACTIMEO)) {
1164 cifs_errorf(fc, "actimeo ignored since acregmax or acdirmax specified\n");
1167 ctx->acdirmax = ctx->acregmax = HZ * result.uint_32;
1169 case Opt_closetimeo:
1170 ctx->closetimeo = HZ * result.uint_32;
1171 if (ctx->closetimeo > SMB3_MAX_DCLOSETIMEO) {
1172 cifs_errorf(fc, "closetimeo too large\n");
1173 goto cifs_parse_mount_err;
1176 case Opt_echo_interval:
1177 ctx->echo_interval = result.uint_32;
1180 ctx->snapshot_time = result.uint_64;
1182 case Opt_max_credits:
1183 if (result.uint_32 < 20 || result.uint_32 > 60000) {
1184 cifs_errorf(fc, "%s: Invalid max_credits value\n",
1186 goto cifs_parse_mount_err;
1188 ctx->max_credits = result.uint_32;
1190 case Opt_max_channels:
1191 if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
1192 cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
1193 __func__, CIFS_MAX_CHANNELS);
1194 goto cifs_parse_mount_err;
1196 ctx->max_channels = result.uint_32;
1197 /* If more than one channel requested ... they want multichan */
1198 if (result.uint_32 > 1)
1199 ctx->multichannel = true;
1201 case Opt_max_cached_dirs:
1202 if (result.uint_32 < 1) {
1203 cifs_errorf(fc, "%s: Invalid max_cached_dirs, needs to be 1 or more\n",
1205 goto cifs_parse_mount_err;
1207 ctx->max_cached_dirs = result.uint_32;
1209 case Opt_handletimeout:
1210 ctx->handle_timeout = result.uint_32;
1211 if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
1212 cifs_errorf(fc, "Invalid handle cache timeout, longer than 16 minutes\n");
1213 goto cifs_parse_mount_err;
1219 switch (smb3_parse_devname(param->string, ctx)) {
1223 cifs_errorf(fc, "Unable to allocate memory for devname\n");
1224 goto cifs_parse_mount_err;
1226 cifs_errorf(fc, "Malformed UNC in devname\n");
1227 goto cifs_parse_mount_err;
1229 cifs_errorf(fc, "Unknown error parsing devname\n");
1230 goto cifs_parse_mount_err;
1232 ctx->source = smb3_fs_context_fullpath(ctx, '/');
1233 if (IS_ERR(ctx->source)) {
1235 cifs_errorf(fc, "OOM when copying UNC string\n");
1236 goto cifs_parse_mount_err;
1238 fc->source = kstrdup(ctx->source, GFP_KERNEL);
1239 if (fc->source == NULL) {
1240 cifs_errorf(fc, "OOM when copying UNC string\n");
1241 goto cifs_parse_mount_err;
1245 kfree(ctx->username);
1246 ctx->username = NULL;
1249 if (strlen(param->string) == 0) {
1250 /* null user, ie. anonymous authentication */
1255 if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
1256 CIFS_MAX_USERNAME_LEN) {
1257 pr_warn("username too long\n");
1258 goto cifs_parse_mount_err;
1260 ctx->username = kstrdup(param->string, GFP_KERNEL);
1261 if (ctx->username == NULL) {
1262 cifs_errorf(fc, "OOM when copying username string\n");
1263 goto cifs_parse_mount_err;
1267 kfree_sensitive(ctx->password);
1268 ctx->password = NULL;
1269 if (strlen(param->string) == 0)
1272 ctx->password = kstrdup(param->string, GFP_KERNEL);
1273 if (ctx->password == NULL) {
1274 cifs_errorf(fc, "OOM when copying password string\n");
1275 goto cifs_parse_mount_err;
1279 if (strlen(param->string) == 0) {
1280 ctx->got_ip = false;
1283 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
1285 strlen(param->string))) {
1286 pr_err("bad ip= option (%s)\n", param->string);
1287 goto cifs_parse_mount_err;
1292 if (strnlen(param->string, CIFS_MAX_DOMAINNAME_LEN)
1293 == CIFS_MAX_DOMAINNAME_LEN) {
1294 pr_warn("domain name too long\n");
1295 goto cifs_parse_mount_err;
1298 kfree(ctx->domainname);
1299 ctx->domainname = kstrdup(param->string, GFP_KERNEL);
1300 if (ctx->domainname == NULL) {
1301 cifs_errorf(fc, "OOM when copying domainname string\n");
1302 goto cifs_parse_mount_err;
1304 cifs_dbg(FYI, "Domain name set\n");
1307 if (!cifs_convert_address(
1308 (struct sockaddr *)&ctx->srcaddr,
1309 param->string, strlen(param->string))) {
1310 pr_warn("Could not parse srcaddr: %s\n",
1312 goto cifs_parse_mount_err;
1316 if (strnlen(param->string, 1024) >= 65) {
1317 pr_warn("iocharset name too long\n");
1318 goto cifs_parse_mount_err;
1321 if (strncasecmp(param->string, "default", 7) != 0) {
1322 kfree(ctx->iocharset);
1323 ctx->iocharset = kstrdup(param->string, GFP_KERNEL);
1324 if (ctx->iocharset == NULL) {
1325 cifs_errorf(fc, "OOM when copying iocharset string\n");
1326 goto cifs_parse_mount_err;
1329 /* if iocharset not set then load_nls_default
1332 cifs_dbg(FYI, "iocharset set to %s\n", ctx->iocharset);
1334 case Opt_netbiosname:
1335 memset(ctx->source_rfc1001_name, 0x20,
1338 * FIXME: are there cases in which a comma can
1339 * be valid in workstation netbios name (and
1340 * need special handling)?
1342 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1343 /* don't ucase netbiosname for user */
1344 if (param->string[i] == 0)
1346 ctx->source_rfc1001_name[i] = param->string[i];
1348 /* The string has 16th byte zero still from
1349 * set at top of the function
1351 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1352 pr_warn("netbiosname longer than 15 truncated\n");
1355 /* last byte, type, is 0x20 for servr type */
1356 memset(ctx->target_rfc1001_name, 0x20,
1357 RFC1001_NAME_LEN_WITH_NULL);
1359 * BB are there cases in which a comma can be valid in this
1360 * workstation netbios name (and need special handling)?
1363 /* user or mount helper must uppercase the netbios name */
1364 for (i = 0; i < 15; i++) {
1365 if (param->string[i] == 0)
1367 ctx->target_rfc1001_name[i] = param->string[i];
1370 /* The string has 16th byte zero still from set at top of function */
1371 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1372 pr_warn("server netbiosname longer than 15 truncated\n");
1375 /* version of mount userspace tools, not dialect */
1376 /* If interface changes in mount.cifs bump to new ver */
1377 if (strncasecmp(param->string, "1", 1) == 0) {
1378 if (strlen(param->string) > 1) {
1379 pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
1381 goto cifs_parse_mount_err;
1383 /* This is the default */
1386 /* For all other value, error */
1387 pr_warn("Invalid mount helper version specified\n");
1388 goto cifs_parse_mount_err;
1390 /* protocol version (dialect) */
1391 if (cifs_parse_smb_version(fc, param->string, ctx, is_smb3) != 0)
1392 goto cifs_parse_mount_err;
1393 ctx->got_version = true;
1396 if (cifs_parse_security_flavors(fc, param->string, ctx) != 0)
1397 goto cifs_parse_mount_err;
1400 if (cifs_parse_cache_flavor(fc, param->string, ctx) != 0)
1401 goto cifs_parse_mount_err;
1404 #ifndef CONFIG_CIFS_SWN_UPCALL
1405 cifs_errorf(fc, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
1406 goto cifs_parse_mount_err;
1408 ctx->witness = true;
1409 pr_warn_once("Witness protocol support is experimental\n");
1412 #ifndef CONFIG_CIFS_ROOT
1413 cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
1414 goto cifs_parse_mount_err;
1418 case Opt_posixpaths:
1420 ctx->posix_paths = 0;
1422 ctx->posix_paths = 1;
1425 if (result.negated) {
1426 if (ctx->linux_ext == 1)
1427 pr_warn_once("conflicting posix mount options specified\n");
1429 ctx->no_linux_ext = 1;
1431 if (ctx->no_linux_ext == 1)
1432 pr_warn_once("conflicting posix mount options specified\n");
1434 ctx->no_linux_ext = 0;
1441 if (result.negated) {
1443 * turn off mandatory locking in mode
1444 * if remote locking is turned off since the
1445 * local vfs will do advisory
1447 if (ctx->file_mode ==
1448 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1449 ctx->file_mode = S_IALLUGO;
1454 case Opt_handlecache:
1456 ctx->nohandlecache = 1;
1458 ctx->nohandlecache = 0;
1460 case Opt_forcemandatorylock:
1464 ctx->setuids = result.negated;
1467 ctx->intr = !result.negated;
1469 case Opt_setuidfromacl:
1470 ctx->setuidfromacl = 1;
1472 case Opt_strictsync:
1473 ctx->nostrictsync = result.negated;
1476 ctx->server_ino = !result.negated;
1478 case Opt_rwpidforward:
1479 ctx->rwpidforward = 1;
1485 ctx->cifs_acl = !result.negated;
1488 ctx->no_psx_acl = result.negated;
1490 case Opt_locallease:
1491 ctx->local_lease = 1;
1496 case Opt_ignore_signature:
1498 ctx->ignore_signature = true;
1501 /* we do not do the following in secFlags because seal
1502 * is a per tree connection (mount) not a per socket
1503 * or per-smb connection option in the protocol
1504 * vol->secFlg |= CIFSSEC_MUST_SEAL;
1509 pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
1512 #ifndef CONFIG_CIFS_FSCACHE
1513 cifs_errorf(fc, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
1514 goto cifs_parse_mount_err;
1518 case Opt_mfsymlinks:
1519 ctx->mfsymlinks = true;
1522 ctx->multiuser = true;
1527 case Opt_nosharesock:
1528 ctx->nosharesock = true;
1530 case Opt_persistent:
1531 if (result.negated) {
1532 ctx->nopersistent = true;
1533 if (ctx->persistent) {
1534 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1535 goto cifs_parse_mount_err;
1538 ctx->persistent = true;
1539 if ((ctx->nopersistent) || (ctx->resilient)) {
1540 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1541 goto cifs_parse_mount_err;
1546 if (result.negated) {
1547 ctx->resilient = false; /* already the default */
1549 ctx->resilient = true;
1550 if (ctx->persistent) {
1551 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1552 goto cifs_parse_mount_err;
1556 case Opt_tcp_nodelay:
1557 /* tcp nodelay should not usually be needed since we CORK/UNCORK the socket */
1559 ctx->sockopt_tcp_nodelay = false;
1561 ctx->sockopt_tcp_nodelay = true;
1563 case Opt_domainauto:
1564 ctx->domainauto = true;
1570 /* case Opt_ignore: - is ignored as expected ... */
1574 cifs_parse_mount_err:
1575 kfree_sensitive(ctx->password);
1576 ctx->password = NULL;
1580 int smb3_init_fs_context(struct fs_context *fc)
1582 struct smb3_fs_context *ctx;
1583 char *nodename = utsname()->nodename;
1586 ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
1590 strscpy(ctx->workstation_name, nodename, sizeof(ctx->workstation_name));
1593 * does not have to be perfect mapping since field is
1594 * informational, only used for servers that do not support
1595 * port 445 and it can be overridden at mount time
1597 memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
1598 for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
1599 ctx->source_rfc1001_name[i] = toupper(nodename[i]);
1601 ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
1603 * null target name indicates to use *SMBSERVR default called name
1604 * if we end up sending RFC1001 session initialize
1606 ctx->target_rfc1001_name[0] = 0;
1607 ctx->cred_uid = current_uid();
1608 ctx->linux_uid = current_uid();
1609 ctx->linux_gid = current_gid();
1610 /* By default 4MB read ahead size, 1MB block size */
1611 ctx->bsize = CIFS_DEFAULT_IOSIZE; /* can improve cp performance significantly */
1612 ctx->rasize = 0; /* 0 = use default (ie negotiated rsize) for read ahead pages */
1615 * default to SFM style remapping of seven reserved characters
1616 * unless user overrides it or we negotiate CIFS POSIX where
1617 * it is unnecessary. Can not simultaneously use more than one mapping
1618 * since then readdir could list files that open could not open
1622 /* default to only allowing write access to owner of the mount */
1623 ctx->dir_mode = ctx->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
1625 /* ctx->retry default is 0 (i.e. "soft" limited retry not hard retry) */
1626 /* default is always to request posix paths. */
1627 ctx->posix_paths = 1;
1628 /* default to using server inode numbers where available */
1629 ctx->server_ino = 1;
1631 /* default is to use strict cifs caching semantics */
1632 ctx->strict_io = true;
1634 ctx->acregmax = CIFS_DEF_ACTIMEO;
1635 ctx->acdirmax = CIFS_DEF_ACTIMEO;
1636 ctx->closetimeo = SMB3_DEF_DCLOSETIMEO;
1637 ctx->max_cached_dirs = MAX_CACHED_FIDS;
1638 /* Most clients set timeout to 0, allows server to use its default */
1639 ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
1641 /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
1642 ctx->ops = &smb30_operations;
1643 ctx->vals = &smbdefault_values;
1645 ctx->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
1647 /* default to no multichannel (single server connection) */
1648 ctx->multichannel = false;
1649 ctx->max_channels = 1;
1651 ctx->backupuid_specified = false; /* no backup intent for a user */
1652 ctx->backupgid_specified = false; /* no backup intent for a group */
1657 * short int override_uid = -1;
1658 * short int override_gid = -1;
1659 * char *nodename = strdup(utsname()->nodename);
1660 * struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
1663 fc->fs_private = ctx;
1664 fc->ops = &smb3_fs_context_ops;
1669 smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
1675 * Make sure this stays in sync with smb3_fs_context_dup()
1677 kfree(ctx->username);
1678 ctx->username = NULL;
1679 kfree_sensitive(ctx->password);
1680 ctx->password = NULL;
1681 kfree(ctx->server_hostname);
1682 ctx->server_hostname = NULL;
1687 kfree(ctx->domainname);
1688 ctx->domainname = NULL;
1689 kfree(ctx->nodename);
1690 ctx->nodename = NULL;
1691 kfree(ctx->iocharset);
1692 ctx->iocharset = NULL;
1693 kfree(ctx->prepath);
1694 ctx->prepath = NULL;
1695 kfree(ctx->leaf_fullpath);
1696 ctx->leaf_fullpath = NULL;
1700 smb3_cleanup_fs_context(struct smb3_fs_context *ctx)
1704 smb3_cleanup_fs_context_contents(ctx);
1708 void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
1710 struct smb3_fs_context *ctx = cifs_sb->ctx;
1713 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS;
1715 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_DFS;
1718 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
1720 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_PERM;
1723 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
1725 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SET_UID;
1727 if (ctx->setuidfromacl)
1728 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL;
1730 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UID_FROM_ACL;
1732 if (ctx->server_ino)
1733 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
1735 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
1738 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR;
1740 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SFM_CHR;
1743 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
1745 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SPECIAL_CHR;
1748 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
1750 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_XATTR;
1753 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
1755 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UNX_EMUL;
1758 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
1760 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_BRL;
1762 if (ctx->nohandlecache)
1763 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE;
1765 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_HANDLE_CACHE;
1767 if (ctx->nostrictsync)
1768 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
1770 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOSSYNC;
1773 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
1775 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOPOSIXBRL;
1777 if (ctx->rwpidforward)
1778 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
1780 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_RWPIDFORWARD;
1783 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MODE_FROM_SID;
1785 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MODE_FROM_SID;
1788 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
1790 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_ACL;
1792 if (ctx->backupuid_specified)
1793 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
1795 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPUID;
1797 if (ctx->backupgid_specified)
1798 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
1800 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPGID;
1802 if (ctx->override_uid)
1803 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
1805 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_UID;
1807 if (ctx->override_gid)
1808 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
1810 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_GID;
1813 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
1815 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DYNPERM;
1818 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
1820 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_FSCACHE;
1823 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
1824 CIFS_MOUNT_NO_PERM);
1826 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MULTIUSER;
1830 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
1832 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_STRICT_IO;
1835 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
1837 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DIRECT_IO;
1839 if (ctx->mfsymlinks)
1840 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
1842 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MF_SYMLINKS;
1843 if (ctx->mfsymlinks) {
1844 if (ctx->sfu_emul) {
1846 * Our SFU ("Services for Unix" emulation does not allow
1847 * creating symlinks but does allow reading existing SFU
1848 * symlinks (it does allow both creating and reading SFU
1849 * style mknod and FIFOs though). When "mfsymlinks" and
1850 * "sfu" are both enabled at the same time, it allows
1851 * reading both types of symlinks, but will only create
1852 * them with mfsymlinks format. This allows better
1853 * Apple compatibility (probably better for Samba too)
1854 * while still recognizing old Windows style symlinks.
1856 cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
1859 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SHUTDOWN;