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 static const match_table_t cifs_upcall_target
= {
71 { Opt_upcall_target_mount
, "mount" },
72 { Opt_upcall_target_application
, "app" },
73 { Opt_upcall_target_err
, NULL
}
76 const struct fs_parameter_spec smb3_fs_parameters
[] = {
77 /* Mount options that take no arguments */
78 fsparam_flag_no("user_xattr", Opt_user_xattr
),
79 fsparam_flag_no("forceuid", Opt_forceuid
),
80 fsparam_flag_no("multichannel", Opt_multichannel
),
81 fsparam_flag_no("forcegid", Opt_forcegid
),
82 fsparam_flag("noblocksend", Opt_noblocksend
),
83 fsparam_flag("noautotune", Opt_noautotune
),
84 fsparam_flag("nolease", Opt_nolease
),
85 fsparam_flag_no("hard", Opt_hard
),
86 fsparam_flag_no("soft", Opt_soft
),
87 fsparam_flag_no("perm", Opt_perm
),
88 fsparam_flag("nodelete", Opt_nodelete
),
89 fsparam_flag_no("mapposix", Opt_mapposix
),
90 fsparam_flag("mapchars", Opt_mapchars
),
91 fsparam_flag("nomapchars", Opt_nomapchars
),
92 fsparam_flag_no("sfu", Opt_sfu
),
93 fsparam_flag("nodfs", Opt_nodfs
),
94 fsparam_flag_no("posixpaths", Opt_posixpaths
),
95 fsparam_flag_no("unix", Opt_unix
),
96 fsparam_flag_no("linux", Opt_unix
),
97 fsparam_flag_no("posix", Opt_unix
),
98 fsparam_flag("nocase", Opt_nocase
),
99 fsparam_flag("ignorecase", Opt_nocase
),
100 fsparam_flag_no("brl", Opt_brl
),
101 fsparam_flag_no("handlecache", Opt_handlecache
),
102 fsparam_flag("forcemandatorylock", Opt_forcemandatorylock
),
103 fsparam_flag("forcemand", Opt_forcemandatorylock
),
104 fsparam_flag("setuidfromacl", Opt_setuidfromacl
),
105 fsparam_flag("idsfromsid", Opt_setuidfromacl
),
106 fsparam_flag_no("setuids", Opt_setuids
),
107 fsparam_flag_no("dynperm", Opt_dynperm
),
108 fsparam_flag_no("intr", Opt_intr
),
109 fsparam_flag_no("strictsync", Opt_strictsync
),
110 fsparam_flag_no("serverino", Opt_serverino
),
111 fsparam_flag("rwpidforward", Opt_rwpidforward
),
112 fsparam_flag("cifsacl", Opt_cifsacl
),
113 fsparam_flag_no("acl", Opt_acl
),
114 fsparam_flag("locallease", Opt_locallease
),
115 fsparam_flag("sign", Opt_sign
),
116 fsparam_flag("ignore_signature", Opt_ignore_signature
),
117 fsparam_flag("signloosely", Opt_ignore_signature
),
118 fsparam_flag("seal", Opt_seal
),
119 fsparam_flag("noac", Opt_noac
),
120 fsparam_flag("fsc", Opt_fsc
),
121 fsparam_flag("mfsymlinks", Opt_mfsymlinks
),
122 fsparam_flag("multiuser", Opt_multiuser
),
123 fsparam_flag("sloppy", Opt_sloppy
),
124 fsparam_flag("nosharesock", Opt_nosharesock
),
125 fsparam_flag_no("persistenthandles", Opt_persistent
),
126 fsparam_flag_no("resilienthandles", Opt_resilient
),
127 fsparam_flag_no("tcpnodelay", Opt_tcp_nodelay
),
128 fsparam_flag("nosparse", Opt_nosparse
),
129 fsparam_flag("domainauto", Opt_domainauto
),
130 fsparam_flag("rdma", Opt_rdma
),
131 fsparam_flag("modesid", Opt_modesid
),
132 fsparam_flag("modefromsid", Opt_modesid
),
133 fsparam_flag("rootfs", Opt_rootfs
),
134 fsparam_flag("compress", Opt_compress
),
135 fsparam_flag("witness", Opt_witness
),
136 fsparam_flag_no("nativesocket", Opt_nativesocket
),
138 /* Mount options which take uid or gid */
139 fsparam_uid("backupuid", Opt_backupuid
),
140 fsparam_gid("backupgid", Opt_backupgid
),
141 fsparam_uid("uid", Opt_uid
),
142 fsparam_uid("cruid", Opt_cruid
),
143 fsparam_gid("gid", Opt_gid
),
145 /* Mount options which take numeric value */
146 fsparam_u32("file_mode", Opt_file_mode
),
147 fsparam_u32("dirmode", Opt_dirmode
),
148 fsparam_u32("dir_mode", Opt_dirmode
),
149 fsparam_u32("port", Opt_port
),
150 fsparam_u32("min_enc_offload", Opt_min_enc_offload
),
151 fsparam_u32("retrans", Opt_retrans
),
152 fsparam_u32("esize", Opt_min_enc_offload
),
153 fsparam_u32("bsize", Opt_blocksize
),
154 fsparam_u32("rasize", Opt_rasize
),
155 fsparam_u32("rsize", Opt_rsize
),
156 fsparam_u32("wsize", Opt_wsize
),
157 fsparam_u32("actimeo", Opt_actimeo
),
158 fsparam_u32("acdirmax", Opt_acdirmax
),
159 fsparam_u32("acregmax", Opt_acregmax
),
160 fsparam_u32("closetimeo", Opt_closetimeo
),
161 fsparam_u32("echo_interval", Opt_echo_interval
),
162 fsparam_u32("max_credits", Opt_max_credits
),
163 fsparam_u32("max_cached_dirs", Opt_max_cached_dirs
),
164 fsparam_u32("handletimeout", Opt_handletimeout
),
165 fsparam_u64("snapshot", Opt_snapshot
),
166 fsparam_u32("max_channels", Opt_max_channels
),
168 /* Mount options which take string value */
169 fsparam_string("source", Opt_source
),
170 fsparam_string("user", Opt_user
),
171 fsparam_string("username", Opt_user
),
172 fsparam_string("pass", Opt_pass
),
173 fsparam_string("password", Opt_pass
),
174 fsparam_string("password2", Opt_pass2
),
175 fsparam_string("ip", Opt_ip
),
176 fsparam_string("addr", Opt_ip
),
177 fsparam_string("domain", Opt_domain
),
178 fsparam_string("dom", Opt_domain
),
179 fsparam_string("srcaddr", Opt_srcaddr
),
180 fsparam_string("iocharset", Opt_iocharset
),
181 fsparam_string("netbiosname", Opt_netbiosname
),
182 fsparam_string("servern", Opt_servern
),
183 fsparam_string("ver", Opt_ver
),
184 fsparam_string("vers", Opt_vers
),
185 fsparam_string("sec", Opt_sec
),
186 fsparam_string("cache", Opt_cache
),
187 fsparam_string("reparse", Opt_reparse
),
188 fsparam_string("upcall_target", Opt_upcalltarget
),
189 fsparam_string("symlink", Opt_symlink
),
190 fsparam_string("symlinkroot", Opt_symlinkroot
),
192 /* Arguments that should be ignored */
193 fsparam_flag("guest", Opt_ignore
),
194 fsparam_flag("noatime", Opt_ignore
),
195 fsparam_flag("relatime", Opt_ignore
),
196 fsparam_flag("_netdev", Opt_ignore
),
197 fsparam_flag_no("suid", Opt_ignore
),
198 fsparam_flag_no("exec", Opt_ignore
),
199 fsparam_flag_no("dev", Opt_ignore
),
200 fsparam_flag_no("mand", Opt_ignore
),
201 fsparam_flag_no("auto", Opt_ignore
),
202 fsparam_string("cred", Opt_ignore
),
203 fsparam_string("credentials", Opt_ignore
),
205 * UNC and prefixpath is now extracted from Opt_source
206 * in the new mount API so we can just ignore them going forward.
208 fsparam_string("unc", Opt_ignore
),
209 fsparam_string("prefixpath", Opt_ignore
),
214 cifs_parse_security_flavors(struct fs_context
*fc
, char *value
, struct smb3_fs_context
*ctx
)
217 substring_t args
[MAX_OPT_ARGS
];
220 * With mount options, the last one should win. Reset any existing
221 * settings back to default.
223 ctx
->sectype
= Unspecified
;
226 switch (match_token(value
, cifs_secflavor_tokens
, args
)) {
228 cifs_errorf(fc
, "sec=krb5p is not supported. Use sec=krb5,seal instead\n");
234 ctx
->sectype
= Kerberos
;
236 case Opt_sec_ntlmsspi
:
239 case Opt_sec_ntlmssp
:
240 ctx
->sectype
= RawNTLMSSP
;
242 case Opt_sec_ntlmv2i
:
246 ctx
->sectype
= NTLMv2
;
250 kfree(ctx
->username
);
251 ctx
->username
= NULL
;
254 cifs_errorf(fc
, "bad security option: %s\n", value
);
262 cifs_parse_upcall_target(struct fs_context
*fc
, char *value
, struct smb3_fs_context
*ctx
)
264 substring_t args
[MAX_OPT_ARGS
];
266 ctx
->upcall_target
= UPTARGET_UNSPECIFIED
;
268 switch (match_token(value
, cifs_upcall_target
, args
)) {
269 case Opt_upcall_target_mount
:
270 ctx
->upcall_target
= UPTARGET_MOUNT
;
272 case Opt_upcall_target_application
:
273 ctx
->upcall_target
= UPTARGET_APP
;
277 cifs_errorf(fc
, "bad upcall target: %s\n", value
);
284 static const match_table_t cifs_cacheflavor_tokens
= {
285 { Opt_cache_loose
, "loose" },
286 { Opt_cache_strict
, "strict" },
287 { Opt_cache_none
, "none" },
288 { Opt_cache_ro
, "ro" },
289 { Opt_cache_rw
, "singleclient" },
290 { Opt_cache_err
, NULL
}
294 cifs_parse_cache_flavor(struct fs_context
*fc
, char *value
, struct smb3_fs_context
*ctx
)
296 substring_t args
[MAX_OPT_ARGS
];
298 switch (match_token(value
, cifs_cacheflavor_tokens
, args
)) {
299 case Opt_cache_loose
:
300 ctx
->direct_io
= false;
301 ctx
->strict_io
= false;
302 ctx
->cache_ro
= false;
303 ctx
->cache_rw
= false;
305 case Opt_cache_strict
:
306 ctx
->direct_io
= false;
307 ctx
->strict_io
= true;
308 ctx
->cache_ro
= false;
309 ctx
->cache_rw
= false;
312 ctx
->direct_io
= true;
313 ctx
->strict_io
= false;
314 ctx
->cache_ro
= false;
315 ctx
->cache_rw
= false;
318 ctx
->direct_io
= false;
319 ctx
->strict_io
= false;
320 ctx
->cache_ro
= true;
321 ctx
->cache_rw
= false;
324 ctx
->direct_io
= false;
325 ctx
->strict_io
= false;
326 ctx
->cache_ro
= false;
327 ctx
->cache_rw
= true;
330 cifs_errorf(fc
, "bad cache= option: %s\n", value
);
336 static const match_table_t reparse_flavor_tokens
= {
337 { Opt_reparse_default
, "default" },
338 { Opt_reparse_none
, "none" },
339 { Opt_reparse_nfs
, "nfs" },
340 { Opt_reparse_wsl
, "wsl" },
341 { Opt_reparse_err
, NULL
},
344 static int parse_reparse_flavor(struct fs_context
*fc
, char *value
,
345 struct smb3_fs_context
*ctx
)
347 substring_t args
[MAX_OPT_ARGS
];
349 switch (match_token(value
, reparse_flavor_tokens
, args
)) {
350 case Opt_reparse_default
:
351 ctx
->reparse_type
= CIFS_REPARSE_TYPE_DEFAULT
;
353 case Opt_reparse_none
:
354 ctx
->reparse_type
= CIFS_REPARSE_TYPE_NONE
;
356 case Opt_reparse_nfs
:
357 ctx
->reparse_type
= CIFS_REPARSE_TYPE_NFS
;
359 case Opt_reparse_wsl
:
360 ctx
->reparse_type
= CIFS_REPARSE_TYPE_WSL
;
363 cifs_errorf(fc
, "bad reparse= option: %s\n", value
);
369 static const match_table_t symlink_flavor_tokens
= {
370 { Opt_symlink_default
, "default" },
371 { Opt_symlink_none
, "none" },
372 { Opt_symlink_native
, "native" },
373 { Opt_symlink_unix
, "unix" },
374 { Opt_symlink_mfsymlinks
, "mfsymlinks" },
375 { Opt_symlink_sfu
, "sfu" },
376 { Opt_symlink_nfs
, "nfs" },
377 { Opt_symlink_wsl
, "wsl" },
378 { Opt_symlink_err
, NULL
},
381 static int parse_symlink_flavor(struct fs_context
*fc
, char *value
,
382 struct smb3_fs_context
*ctx
)
384 substring_t args
[MAX_OPT_ARGS
];
386 switch (match_token(value
, symlink_flavor_tokens
, args
)) {
387 case Opt_symlink_default
:
388 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_DEFAULT
;
390 case Opt_symlink_none
:
391 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_NONE
;
393 case Opt_symlink_native
:
394 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_NATIVE
;
396 case Opt_symlink_unix
:
397 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_UNIX
;
399 case Opt_symlink_mfsymlinks
:
400 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_MFSYMLINKS
;
402 case Opt_symlink_sfu
:
403 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_SFU
;
405 case Opt_symlink_nfs
:
406 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_NFS
;
408 case Opt_symlink_wsl
:
409 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_WSL
;
412 cifs_errorf(fc
, "bad symlink= option: %s\n", value
);
418 #define DUP_CTX_STR(field) \
421 new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
422 if (new_ctx->field == NULL) { \
423 smb3_cleanup_fs_context_contents(new_ctx); \
430 smb3_fs_context_dup(struct smb3_fs_context
*new_ctx
, struct smb3_fs_context
*ctx
)
432 memcpy(new_ctx
, ctx
, sizeof(*ctx
));
433 new_ctx
->prepath
= NULL
;
434 new_ctx
->nodename
= NULL
;
435 new_ctx
->username
= NULL
;
436 new_ctx
->password
= NULL
;
437 new_ctx
->password2
= NULL
;
438 new_ctx
->server_hostname
= NULL
;
439 new_ctx
->domainname
= NULL
;
441 new_ctx
->source
= NULL
;
442 new_ctx
->iocharset
= NULL
;
443 new_ctx
->leaf_fullpath
= NULL
;
444 new_ctx
->dns_dom
= NULL
;
445 new_ctx
->symlinkroot
= NULL
;
447 * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
449 DUP_CTX_STR(prepath
);
450 DUP_CTX_STR(username
);
451 DUP_CTX_STR(password
);
452 DUP_CTX_STR(password2
);
453 DUP_CTX_STR(server_hostname
);
456 DUP_CTX_STR(domainname
);
457 DUP_CTX_STR(nodename
);
458 DUP_CTX_STR(iocharset
);
459 DUP_CTX_STR(leaf_fullpath
);
460 DUP_CTX_STR(dns_dom
);
461 DUP_CTX_STR(symlinkroot
);
467 cifs_parse_smb_version(struct fs_context
*fc
, char *value
, struct smb3_fs_context
*ctx
, bool is_smb3
)
469 substring_t args
[MAX_OPT_ARGS
];
471 switch (match_token(value
, cifs_smb_version_tokens
, args
)) {
472 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
474 if (disable_legacy_dialects
) {
475 cifs_errorf(fc
, "mount with legacy dialect disabled\n");
479 cifs_errorf(fc
, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
482 cifs_errorf(fc
, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
483 ctx
->ops
= &smb1_operations
;
484 ctx
->vals
= &smb1_values
;
487 if (disable_legacy_dialects
) {
488 cifs_errorf(fc
, "mount with legacy dialect disabled\n");
492 cifs_errorf(fc
, "vers=2.0 not permitted when mounting with smb3\n");
495 ctx
->ops
= &smb20_operations
;
496 ctx
->vals
= &smb20_values
;
500 cifs_errorf(fc
, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
503 cifs_errorf(fc
, "vers=2.0 mount not permitted when legacy dialects disabled\n");
505 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
507 ctx
->ops
= &smb21_operations
;
508 ctx
->vals
= &smb21_values
;
511 ctx
->ops
= &smb30_operations
;
512 ctx
->vals
= &smb30_values
;
515 ctx
->ops
= &smb30_operations
; /* currently identical with 3.0 */
516 ctx
->vals
= &smb302_values
;
519 ctx
->ops
= &smb311_operations
;
520 ctx
->vals
= &smb311_values
;
523 ctx
->ops
= &smb30_operations
; /* currently identical with 3.0 */
524 ctx
->vals
= &smb3any_values
;
527 ctx
->ops
= &smb30_operations
;
528 ctx
->vals
= &smbdefault_values
;
531 cifs_errorf(fc
, "Unknown vers= option specified: %s\n", value
);
537 int smb3_parse_opt(const char *options
, const char *key
, char **val
)
540 char *opts
, *orig
, *p
;
542 orig
= opts
= kstrdup(options
, GFP_KERNEL
);
546 while ((p
= strsep(&opts
, ","))) {
551 if (strncasecmp(p
, key
, strlen(key
)))
553 nval
= strchr(p
, '=');
558 *val
= kstrdup(nval
, GFP_KERNEL
);
559 rc
= !*val
? -ENOMEM
: 0;
569 * Remove duplicate path delimiters. Windows is supposed to do that
570 * but there are some bugs that prevent rename from working if there are
571 * multiple delimiters.
573 * Return a sanitized duplicate of @path or NULL for empty prefix paths.
574 * Otherwise, return ERR_PTR.
576 * @gfp indicates the GFP_* flags for kstrdup.
577 * The caller is responsible for freeing the original.
579 #define IS_DELIM(c) ((c) == '/' || (c) == '\\')
580 char *cifs_sanitize_prepath(char *prepath
, gfp_t gfp
)
582 char *cursor1
= prepath
, *cursor2
= prepath
;
585 /* skip all prepended delimiters */
586 while (IS_DELIM(*cursor1
))
589 /* copy the first letter */
592 /* copy the remainder... */
593 while (*(cursor1
++)) {
594 /* ... skipping all duplicated delimiters */
595 if (IS_DELIM(*cursor1
) && IS_DELIM(*cursor2
))
597 *(++cursor2
) = *cursor1
;
600 /* if the last character is a delimiter, skip it */
601 if (IS_DELIM(*(cursor2
- 1)))
607 s
= kstrdup(prepath
, gfp
);
609 return ERR_PTR(-ENOMEM
);
614 * Return full path based on the values of @ctx->{UNC,prepath}.
616 * It is assumed that both values were already parsed by smb3_parse_devname().
618 char *smb3_fs_context_fullpath(const struct smb3_fs_context
*ctx
, char dirsep
)
623 ulen
= strlen(ctx
->UNC
);
624 plen
= ctx
->prepath
? strlen(ctx
->prepath
) + 1 : 0;
626 s
= kmalloc(ulen
+ plen
+ 1, GFP_KERNEL
);
628 return ERR_PTR(-ENOMEM
);
629 memcpy(s
, ctx
->UNC
, ulen
);
632 memcpy(s
+ ulen
+ 1, ctx
->prepath
, plen
);
634 s
[ulen
+ plen
] = '\0';
635 convert_delimiter(s
, dirsep
);
640 * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
641 * fields with the result. Returns 0 on success and an error otherwise
642 * (e.g. ENOMEM or EINVAL)
645 smb3_parse_devname(const char *devname
, struct smb3_fs_context
*ctx
)
648 const char *delims
= "/\\";
652 if (unlikely(!devname
|| !*devname
)) {
653 cifs_dbg(VFS
, "Device name not specified\n");
657 /* make sure we have a valid UNC double delimiter prefix */
658 len
= strspn(devname
, delims
);
662 /* find delimiter between host and sharename */
663 pos
= strpbrk(devname
+ 2, delims
);
667 /* record the server hostname */
668 kfree(ctx
->server_hostname
);
669 ctx
->server_hostname
= kstrndup(devname
+ 2, pos
- devname
- 2, GFP_KERNEL
);
670 if (!ctx
->server_hostname
)
673 /* skip past delimiter */
676 /* now go until next delimiter or end of string */
677 len
= strcspn(pos
, delims
);
681 /* move "pos" up to delimiter or NULL */
684 ctx
->UNC
= kstrndup(devname
, pos
- devname
, GFP_KERNEL
);
688 convert_delimiter(ctx
->UNC
, '\\');
690 /* skip any delimiter */
691 if (*pos
== '/' || *pos
== '\\')
697 /* If pos is NULL then no prepath */
701 ctx
->prepath
= cifs_sanitize_prepath(pos
, GFP_KERNEL
);
702 if (IS_ERR(ctx
->prepath
)) {
703 rc
= PTR_ERR(ctx
->prepath
);
711 static void smb3_fs_context_free(struct fs_context
*fc
);
712 static int smb3_fs_context_parse_param(struct fs_context
*fc
,
713 struct fs_parameter
*param
);
714 static int smb3_fs_context_parse_monolithic(struct fs_context
*fc
,
716 static int smb3_get_tree(struct fs_context
*fc
);
717 static int smb3_reconfigure(struct fs_context
*fc
);
719 static const struct fs_context_operations smb3_fs_context_ops
= {
720 .free
= smb3_fs_context_free
,
721 .parse_param
= smb3_fs_context_parse_param
,
722 .parse_monolithic
= smb3_fs_context_parse_monolithic
,
723 .get_tree
= smb3_get_tree
,
724 .reconfigure
= smb3_reconfigure
,
728 * Parse a monolithic block of data from sys_mount().
729 * smb3_fs_context_parse_monolithic - Parse key[=val][,key[=val]]* mount data
730 * @ctx: The superblock configuration to fill in.
731 * @data: The data to parse
733 * Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
734 * called from the ->monolithic_mount_data() fs_context operation.
736 * Returns 0 on success or the error returned by the ->parse_option() fs_context
737 * operation on failure.
739 static int smb3_fs_context_parse_monolithic(struct fs_context
*fc
,
742 char *options
= data
, *key
;
748 ret
= security_sb_eat_lsm_opts(options
, &fc
->security
);
752 /* BB Need to add support for sep= here TBD */
753 while ((key
= strsep(&options
, ",")) != NULL
) {
760 /* Check if following character is the deliminator If yes,
761 * we have encountered a double deliminator reset the NULL
762 * character to the deliminator
764 while (options
&& options
[0] == ',') {
766 strcpy(key
+ len
, options
);
767 options
= strchr(options
, ',');
774 value
= strchr(key
, '=');
782 ret
= vfs_parse_fs_string(fc
, key
, value
, len
);
791 * Validate the preparsed information in the config.
793 static int smb3_fs_context_validate(struct fs_context
*fc
)
795 struct smb3_fs_context
*ctx
= smb3_fc2context(fc
);
797 if (ctx
->rdma
&& ctx
->vals
->protocol_id
< SMB30_PROT_ID
) {
798 cifs_errorf(fc
, "SMB Direct requires Version >=3.0\n");
803 /* Muliuser mounts require CONFIG_KEYS support */
804 if (ctx
->multiuser
) {
805 cifs_errorf(fc
, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
810 if (ctx
->got_version
== false)
811 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");
815 cifs_errorf(fc
, "CIFS mount error: No usable UNC path provided in device string!\n");
819 /* make sure UNC has a share name */
820 if (strlen(ctx
->UNC
) < 3 || !strchr(ctx
->UNC
+ 3, '\\')) {
821 cifs_errorf(fc
, "Malformed UNC. Unable to find share name.\n");
829 /* No ip= option specified? Try to get it from UNC */
830 /* Use the address part of the UNC. */
831 slash
= strchr(&ctx
->UNC
[2], '\\');
832 len
= slash
- &ctx
->UNC
[2];
833 if (!cifs_convert_address((struct sockaddr
*)&ctx
->dstaddr
,
834 &ctx
->UNC
[2], len
)) {
835 pr_err("Unable to determine destination address\n");
836 return -EHOSTUNREACH
;
840 /* set the port that we got earlier */
841 cifs_set_port((struct sockaddr
*)&ctx
->dstaddr
, ctx
->port
);
843 if (ctx
->uid_specified
&& !ctx
->forceuid_specified
) {
844 ctx
->override_uid
= 1;
845 pr_notice("enabling forceuid mount option implicitly because uid= option is specified\n");
848 if (ctx
->gid_specified
&& !ctx
->forcegid_specified
) {
849 ctx
->override_gid
= 1;
850 pr_notice("enabling forcegid mount option implicitly because gid= option is specified\n");
853 if (ctx
->override_uid
&& !ctx
->uid_specified
) {
854 ctx
->override_uid
= 0;
855 pr_notice("ignoring forceuid mount option specified with no uid= option\n");
858 if (ctx
->override_gid
&& !ctx
->gid_specified
) {
859 ctx
->override_gid
= 0;
860 pr_notice("ignoring forcegid mount option specified with no gid= option\n");
866 static int smb3_get_tree_common(struct fs_context
*fc
)
868 struct smb3_fs_context
*ctx
= smb3_fc2context(fc
);
872 root
= cifs_smb3_do_mount(fc
->fs_type
, 0, ctx
);
874 return PTR_ERR(root
);
882 * Create an SMB3 superblock from the parameters passed.
884 static int smb3_get_tree(struct fs_context
*fc
)
886 int err
= smb3_fs_context_validate(fc
);
892 ret
= smb3_get_tree_common(fc
);
897 static void smb3_fs_context_free(struct fs_context
*fc
)
899 struct smb3_fs_context
*ctx
= smb3_fc2context(fc
);
901 smb3_cleanup_fs_context(ctx
);
905 * Compare the old and new proposed context during reconfigure
906 * and check if the changes are compatible.
908 static int smb3_verify_reconfigure_ctx(struct fs_context
*fc
,
909 struct smb3_fs_context
*new_ctx
,
910 struct smb3_fs_context
*old_ctx
, bool need_recon
)
912 if (new_ctx
->posix_paths
!= old_ctx
->posix_paths
) {
913 cifs_errorf(fc
, "can not change posixpaths during remount\n");
916 if (new_ctx
->sectype
!= old_ctx
->sectype
) {
917 cifs_errorf(fc
, "can not change sec during remount\n");
920 if (new_ctx
->multiuser
!= old_ctx
->multiuser
) {
921 cifs_errorf(fc
, "can not change multiuser during remount\n");
925 (!old_ctx
->UNC
|| strcmp(new_ctx
->UNC
, old_ctx
->UNC
))) {
926 cifs_errorf(fc
, "can not change UNC during remount\n");
929 if (new_ctx
->username
&&
930 (!old_ctx
->username
|| strcmp(new_ctx
->username
, old_ctx
->username
))) {
931 cifs_errorf(fc
, "can not change username during remount\n");
934 if (new_ctx
->password
&&
935 (!old_ctx
->password
|| strcmp(new_ctx
->password
, old_ctx
->password
))) {
936 if (need_recon
== false) {
938 "can not change password of active session during remount\n");
940 } else if (old_ctx
->sectype
== Kerberos
) {
942 "can not change password for Kerberos via remount\n");
946 if (new_ctx
->domainname
&&
947 (!old_ctx
->domainname
|| strcmp(new_ctx
->domainname
, old_ctx
->domainname
))) {
948 cifs_errorf(fc
, "can not change domainname during remount\n");
951 if (strcmp(new_ctx
->workstation_name
, old_ctx
->workstation_name
)) {
952 cifs_errorf(fc
, "can not change workstation_name during remount\n");
955 if (new_ctx
->nodename
&&
956 (!old_ctx
->nodename
|| strcmp(new_ctx
->nodename
, old_ctx
->nodename
))) {
957 cifs_errorf(fc
, "can not change nodename during remount\n");
960 if (new_ctx
->iocharset
&&
961 (!old_ctx
->iocharset
|| strcmp(new_ctx
->iocharset
, old_ctx
->iocharset
))) {
962 cifs_errorf(fc
, "can not change iocharset during remount\n");
969 #define STEAL_STRING(cifs_sb, ctx, field) \
972 ctx->field = cifs_sb->ctx->field; \
973 cifs_sb->ctx->field = NULL; \
976 #define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field) \
978 kfree_sensitive(ctx->field); \
979 ctx->field = cifs_sb->ctx->field; \
980 cifs_sb->ctx->field = NULL; \
983 int smb3_sync_session_ctx_passwords(struct cifs_sb_info
*cifs_sb
, struct cifs_ses
*ses
)
986 cifs_sb
->ctx
->password
&&
987 strcmp(ses
->password
, cifs_sb
->ctx
->password
)) {
988 kfree_sensitive(cifs_sb
->ctx
->password
);
989 cifs_sb
->ctx
->password
= kstrdup(ses
->password
, GFP_KERNEL
);
990 if (!cifs_sb
->ctx
->password
)
993 if (ses
->password2
&&
994 cifs_sb
->ctx
->password2
&&
995 strcmp(ses
->password2
, cifs_sb
->ctx
->password2
)) {
996 kfree_sensitive(cifs_sb
->ctx
->password2
);
997 cifs_sb
->ctx
->password2
= kstrdup(ses
->password2
, GFP_KERNEL
);
998 if (!cifs_sb
->ctx
->password2
) {
999 kfree_sensitive(cifs_sb
->ctx
->password
);
1000 cifs_sb
->ctx
->password
= NULL
;
1007 static int smb3_reconfigure(struct fs_context
*fc
)
1009 struct smb3_fs_context
*ctx
= smb3_fc2context(fc
);
1010 struct dentry
*root
= fc
->root
;
1011 struct cifs_sb_info
*cifs_sb
= CIFS_SB(root
->d_sb
);
1012 struct cifs_ses
*ses
= cifs_sb_master_tcon(cifs_sb
)->ses
;
1013 char *new_password
= NULL
, *new_password2
= NULL
;
1014 bool need_recon
= false;
1017 if (ses
->expired_pwd
)
1020 rc
= smb3_verify_reconfigure_ctx(fc
, ctx
, cifs_sb
->ctx
, need_recon
);
1025 * We can not change UNC/username/password/domainname/
1026 * workstation_name/nodename/iocharset
1027 * during reconnect so ignore what we have in the new context and
1028 * just use what we already have in cifs_sb->ctx.
1030 STEAL_STRING(cifs_sb
, ctx
, UNC
);
1031 STEAL_STRING(cifs_sb
, ctx
, source
);
1032 STEAL_STRING(cifs_sb
, ctx
, username
);
1034 if (need_recon
== false)
1035 STEAL_STRING_SENSITIVE(cifs_sb
, ctx
, password
);
1037 if (ctx
->password
) {
1038 new_password
= kstrdup(ctx
->password
, GFP_KERNEL
);
1042 STEAL_STRING_SENSITIVE(cifs_sb
, ctx
, password
);
1046 * if a new password2 has been specified, then reset it's value
1047 * inside the ses struct
1049 if (ctx
->password2
) {
1050 new_password2
= kstrdup(ctx
->password2
, GFP_KERNEL
);
1051 if (!new_password2
) {
1052 kfree_sensitive(new_password
);
1056 STEAL_STRING_SENSITIVE(cifs_sb
, ctx
, password2
);
1059 * we may update the passwords in the ses struct below. Make sure we do
1060 * not race with smb2_reconnect
1062 mutex_lock(&ses
->session_mutex
);
1065 * smb2_reconnect may swap password and password2 in case session setup
1066 * failed. First get ctx passwords in sync with ses passwords. It should
1067 * be okay to do this even if this function were to return an error at a
1070 rc
= smb3_sync_session_ctx_passwords(cifs_sb
, ses
);
1072 mutex_unlock(&ses
->session_mutex
);
1077 * now that allocations for passwords are done, commit them
1080 kfree_sensitive(ses
->password
);
1081 ses
->password
= new_password
;
1083 if (new_password2
) {
1084 kfree_sensitive(ses
->password2
);
1085 ses
->password2
= new_password2
;
1088 mutex_unlock(&ses
->session_mutex
);
1090 STEAL_STRING(cifs_sb
, ctx
, domainname
);
1091 STEAL_STRING(cifs_sb
, ctx
, nodename
);
1092 STEAL_STRING(cifs_sb
, ctx
, iocharset
);
1094 /* if rsize or wsize not passed in on remount, use previous values */
1095 if (ctx
->rsize
== 0)
1096 ctx
->rsize
= cifs_sb
->ctx
->rsize
;
1097 if (ctx
->wsize
== 0)
1098 ctx
->wsize
= cifs_sb
->ctx
->wsize
;
1101 smb3_cleanup_fs_context_contents(cifs_sb
->ctx
);
1102 rc
= smb3_fs_context_dup(cifs_sb
->ctx
, ctx
);
1103 smb3_update_mnt_flags(cifs_sb
);
1104 #ifdef CONFIG_CIFS_DFS_UPCALL
1106 rc
= dfs_cache_remount_fs(cifs_sb
);
1112 static int smb3_fs_context_parse_param(struct fs_context
*fc
,
1113 struct fs_parameter
*param
)
1115 struct fs_parse_result result
;
1116 struct smb3_fs_context
*ctx
= smb3_fc2context(fc
);
1118 bool is_smb3
= !strcmp(fc
->fs_type
->name
, "smb3");
1119 bool skip_parsing
= false;
1121 cifs_dbg(FYI
, "CIFS: parsing cifs mount option '%s'\n", param
->key
);
1124 * fs_parse can not handle string options with an empty value so
1125 * we will need special handling of them.
1127 if (param
->type
== fs_value_is_string
&& param
->string
[0] == 0) {
1128 if (!strcmp("pass", param
->key
) || !strcmp("password", param
->key
)) {
1129 skip_parsing
= true;
1131 } else if (!strcmp("user", param
->key
) || !strcmp("username", param
->key
)) {
1132 skip_parsing
= true;
1137 if (!skip_parsing
) {
1138 opt
= fs_parse(fc
, smb3_fs_parameters
, param
, &result
);
1140 return ctx
->sloppy
? 1 : opt
;
1145 if (!IS_ENABLED(CONFIG_CIFS_COMPRESSION
)) {
1146 cifs_errorf(fc
, "CONFIG_CIFS_COMPRESSION kernel config option is unset\n");
1147 goto cifs_parse_mount_err
;
1149 ctx
->compress
= true;
1150 cifs_dbg(VFS
, "SMB3 compression support is experimental\n");
1156 if (result
.negated
) {
1157 if (ctx
->retry
== 1)
1158 cifs_dbg(VFS
, "conflicting hard vs. soft mount options\n");
1167 if (ctx
->retry
== 1)
1168 cifs_dbg(VFS
, "conflicting hard vs soft mount options\n");
1177 ctx
->sfu_remap
= false; /* disable SFU mapping */
1182 ctx
->sfu_remap
= false;
1184 ctx
->sfu_remap
= true;
1185 ctx
->remap
= false; /* disable SFM (mapposix) mapping */
1188 case Opt_user_xattr
:
1196 ctx
->override_uid
= 0;
1198 ctx
->override_uid
= 1;
1199 ctx
->forceuid_specified
= true;
1203 ctx
->override_gid
= 0;
1205 ctx
->override_gid
= 1;
1206 ctx
->forcegid_specified
= true;
1226 case Opt_noblocksend
:
1227 ctx
->noblocksnd
= 1;
1229 case Opt_noautotune
:
1230 ctx
->noautotune
= 1;
1241 case Opt_multichannel
:
1242 if (result
.negated
) {
1243 ctx
->multichannel
= false;
1244 ctx
->max_channels
= 1;
1246 ctx
->multichannel
= true;
1247 /* if number of channels not specified, default to 2 */
1248 if (ctx
->max_channels
< 2)
1249 ctx
->max_channels
= 2;
1253 ctx
->linux_uid
= result
.uid
;
1254 ctx
->uid_specified
= true;
1257 ctx
->cred_uid
= result
.uid
;
1258 ctx
->cruid_specified
= true;
1261 ctx
->backupuid
= result
.uid
;
1262 ctx
->backupuid_specified
= true;
1265 ctx
->backupgid
= result
.gid
;
1266 ctx
->backupgid_specified
= true;
1269 ctx
->linux_gid
= result
.gid
;
1270 ctx
->gid_specified
= true;
1273 ctx
->port
= result
.uint_32
;
1276 ctx
->file_mode
= result
.uint_32
;
1279 ctx
->dir_mode
= result
.uint_32
;
1281 case Opt_min_enc_offload
:
1282 ctx
->min_offload
= result
.uint_32
;
1285 ctx
->retrans
= result
.uint_32
;
1289 * inode blocksize realistically should never need to be
1290 * less than 16K or greater than 16M and default is 1MB.
1291 * Note that small inode block sizes (e.g. 64K) can lead
1292 * to very poor performance of common tools like cp and scp
1294 if ((result
.uint_32
< CIFS_MAX_MSGSIZE
) ||
1295 (result
.uint_32
> (4 * SMB3_DEFAULT_IOSIZE
))) {
1296 cifs_errorf(fc
, "%s: Invalid blocksize\n",
1298 goto cifs_parse_mount_err
;
1300 ctx
->bsize
= result
.uint_32
;
1301 ctx
->got_bsize
= true;
1305 * readahead size realistically should never need to be
1306 * less than 1M (CIFS_DEFAULT_IOSIZE) or greater than 32M
1307 * (perhaps an exception should be considered in the
1308 * for the case of a large number of channels
1309 * when multichannel is negotiated) since that would lead
1310 * to plenty of parallel I/O in flight to the server.
1311 * Note that smaller read ahead sizes would
1312 * hurt performance of common tools like cp and scp
1313 * which often trigger sequential i/o with read ahead
1315 if ((result
.uint_32
> (8 * SMB3_DEFAULT_IOSIZE
)) ||
1316 (result
.uint_32
< CIFS_DEFAULT_IOSIZE
)) {
1317 cifs_errorf(fc
, "%s: Invalid rasize %d vs. %d\n",
1318 __func__
, result
.uint_32
, SMB3_DEFAULT_IOSIZE
);
1319 goto cifs_parse_mount_err
;
1321 ctx
->rasize
= result
.uint_32
;
1324 ctx
->rsize
= result
.uint_32
;
1325 ctx
->got_rsize
= true;
1328 ctx
->wsize
= result
.uint_32
;
1329 ctx
->got_wsize
= true;
1330 if (ctx
->wsize
% PAGE_SIZE
!= 0) {
1331 ctx
->wsize
= round_down(ctx
->wsize
, PAGE_SIZE
);
1332 if (ctx
->wsize
== 0) {
1333 ctx
->wsize
= PAGE_SIZE
;
1334 cifs_dbg(VFS
, "wsize too small, reset to minimum %ld\n", PAGE_SIZE
);
1337 "wsize rounded down to %d to multiple of PAGE_SIZE %ld\n",
1338 ctx
->wsize
, PAGE_SIZE
);
1343 ctx
->acregmax
= HZ
* result
.uint_32
;
1344 if (ctx
->acregmax
> CIFS_MAX_ACTIMEO
) {
1345 cifs_errorf(fc
, "acregmax too large\n");
1346 goto cifs_parse_mount_err
;
1350 ctx
->acdirmax
= HZ
* result
.uint_32
;
1351 if (ctx
->acdirmax
> CIFS_MAX_ACTIMEO
) {
1352 cifs_errorf(fc
, "acdirmax too large\n");
1353 goto cifs_parse_mount_err
;
1357 if (HZ
* result
.uint_32
> CIFS_MAX_ACTIMEO
) {
1358 cifs_errorf(fc
, "timeout too large\n");
1359 goto cifs_parse_mount_err
;
1361 if ((ctx
->acdirmax
!= CIFS_DEF_ACTIMEO
) ||
1362 (ctx
->acregmax
!= CIFS_DEF_ACTIMEO
)) {
1363 cifs_errorf(fc
, "actimeo ignored since acregmax or acdirmax specified\n");
1366 ctx
->acdirmax
= ctx
->acregmax
= HZ
* result
.uint_32
;
1368 case Opt_closetimeo
:
1369 ctx
->closetimeo
= HZ
* result
.uint_32
;
1370 if (ctx
->closetimeo
> SMB3_MAX_DCLOSETIMEO
) {
1371 cifs_errorf(fc
, "closetimeo too large\n");
1372 goto cifs_parse_mount_err
;
1375 case Opt_echo_interval
:
1376 ctx
->echo_interval
= result
.uint_32
;
1379 ctx
->snapshot_time
= result
.uint_64
;
1381 case Opt_max_credits
:
1382 if (result
.uint_32
< 20 || result
.uint_32
> 60000) {
1383 cifs_errorf(fc
, "%s: Invalid max_credits value\n",
1385 goto cifs_parse_mount_err
;
1387 ctx
->max_credits
= result
.uint_32
;
1389 case Opt_max_channels
:
1390 if (result
.uint_32
< 1 || result
.uint_32
> CIFS_MAX_CHANNELS
) {
1391 cifs_errorf(fc
, "%s: Invalid max_channels value, needs to be 1-%d\n",
1392 __func__
, CIFS_MAX_CHANNELS
);
1393 goto cifs_parse_mount_err
;
1395 ctx
->max_channels
= result
.uint_32
;
1396 /* If more than one channel requested ... they want multichan */
1397 if (result
.uint_32
> 1)
1398 ctx
->multichannel
= true;
1400 case Opt_max_cached_dirs
:
1401 if (result
.uint_32
< 1) {
1402 cifs_errorf(fc
, "%s: Invalid max_cached_dirs, needs to be 1 or more\n",
1404 goto cifs_parse_mount_err
;
1406 ctx
->max_cached_dirs
= result
.uint_32
;
1408 case Opt_handletimeout
:
1409 ctx
->handle_timeout
= result
.uint_32
;
1410 if (ctx
->handle_timeout
> SMB3_MAX_HANDLE_TIMEOUT
) {
1411 cifs_errorf(fc
, "Invalid handle cache timeout, longer than 16 minutes\n");
1412 goto cifs_parse_mount_err
;
1418 switch (smb3_parse_devname(param
->string
, ctx
)) {
1422 cifs_errorf(fc
, "Unable to allocate memory for devname\n");
1423 goto cifs_parse_mount_err
;
1425 cifs_errorf(fc
, "Malformed UNC in devname\n");
1426 goto cifs_parse_mount_err
;
1428 cifs_errorf(fc
, "Unknown error parsing devname\n");
1429 goto cifs_parse_mount_err
;
1431 ctx
->source
= smb3_fs_context_fullpath(ctx
, '/');
1432 if (IS_ERR(ctx
->source
)) {
1434 cifs_errorf(fc
, "OOM when copying UNC string\n");
1435 goto cifs_parse_mount_err
;
1437 fc
->source
= kstrdup(ctx
->source
, GFP_KERNEL
);
1438 if (fc
->source
== NULL
) {
1439 cifs_errorf(fc
, "OOM when copying UNC string\n");
1440 goto cifs_parse_mount_err
;
1444 kfree(ctx
->username
);
1445 ctx
->username
= NULL
;
1448 if (strlen(param
->string
) == 0) {
1449 /* null user, ie. anonymous authentication */
1454 if (strnlen(param
->string
, CIFS_MAX_USERNAME_LEN
) >
1455 CIFS_MAX_USERNAME_LEN
) {
1456 pr_warn("username too long\n");
1457 goto cifs_parse_mount_err
;
1459 ctx
->username
= kstrdup(param
->string
, GFP_KERNEL
);
1460 if (ctx
->username
== NULL
) {
1461 cifs_errorf(fc
, "OOM when copying username string\n");
1462 goto cifs_parse_mount_err
;
1466 kfree_sensitive(ctx
->password
);
1467 ctx
->password
= NULL
;
1468 if (strlen(param
->string
) == 0)
1471 ctx
->password
= kstrdup(param
->string
, GFP_KERNEL
);
1472 if (ctx
->password
== NULL
) {
1473 cifs_errorf(fc
, "OOM when copying password string\n");
1474 goto cifs_parse_mount_err
;
1478 kfree_sensitive(ctx
->password2
);
1479 ctx
->password2
= NULL
;
1480 if (strlen(param
->string
) == 0)
1483 ctx
->password2
= kstrdup(param
->string
, GFP_KERNEL
);
1484 if (ctx
->password2
== NULL
) {
1485 cifs_errorf(fc
, "OOM when copying password2 string\n");
1486 goto cifs_parse_mount_err
;
1490 if (strlen(param
->string
) == 0) {
1491 ctx
->got_ip
= false;
1494 if (!cifs_convert_address((struct sockaddr
*)&ctx
->dstaddr
,
1496 strlen(param
->string
))) {
1497 pr_err("bad ip= option (%s)\n", param
->string
);
1498 goto cifs_parse_mount_err
;
1503 if (strnlen(param
->string
, CIFS_MAX_DOMAINNAME_LEN
)
1504 == CIFS_MAX_DOMAINNAME_LEN
) {
1505 pr_warn("domain name too long\n");
1506 goto cifs_parse_mount_err
;
1509 kfree(ctx
->domainname
);
1510 ctx
->domainname
= kstrdup(param
->string
, GFP_KERNEL
);
1511 if (ctx
->domainname
== NULL
) {
1512 cifs_errorf(fc
, "OOM when copying domainname string\n");
1513 goto cifs_parse_mount_err
;
1515 cifs_dbg(FYI
, "Domain name set\n");
1518 if (!cifs_convert_address(
1519 (struct sockaddr
*)&ctx
->srcaddr
,
1520 param
->string
, strlen(param
->string
))) {
1521 pr_warn("Could not parse srcaddr: %s\n",
1523 goto cifs_parse_mount_err
;
1527 if (strnlen(param
->string
, 1024) >= 65) {
1528 pr_warn("iocharset name too long\n");
1529 goto cifs_parse_mount_err
;
1532 if (strncasecmp(param
->string
, "default", 7) != 0) {
1533 kfree(ctx
->iocharset
);
1534 ctx
->iocharset
= kstrdup(param
->string
, GFP_KERNEL
);
1535 if (ctx
->iocharset
== NULL
) {
1536 cifs_errorf(fc
, "OOM when copying iocharset string\n");
1537 goto cifs_parse_mount_err
;
1540 /* if iocharset not set then load_nls_default
1543 cifs_dbg(FYI
, "iocharset set to %s\n", ctx
->iocharset
);
1545 case Opt_netbiosname
:
1546 memset(ctx
->source_rfc1001_name
, 0x20,
1549 * FIXME: are there cases in which a comma can
1550 * be valid in workstation netbios name (and
1551 * need special handling)?
1553 for (i
= 0; i
< RFC1001_NAME_LEN
; i
++) {
1554 /* don't ucase netbiosname for user */
1555 if (param
->string
[i
] == 0)
1557 ctx
->source_rfc1001_name
[i
] = param
->string
[i
];
1559 /* The string has 16th byte zero still from
1560 * set at top of the function
1562 if (i
== RFC1001_NAME_LEN
&& param
->string
[i
] != 0)
1563 pr_warn("netbiosname longer than 15 truncated\n");
1566 /* last byte, type, is 0x20 for servr type */
1567 memset(ctx
->target_rfc1001_name
, 0x20,
1568 RFC1001_NAME_LEN_WITH_NULL
);
1570 * BB are there cases in which a comma can be valid in this
1571 * workstation netbios name (and need special handling)?
1574 /* user or mount helper must uppercase the netbios name */
1575 for (i
= 0; i
< 15; i
++) {
1576 if (param
->string
[i
] == 0)
1578 ctx
->target_rfc1001_name
[i
] = param
->string
[i
];
1581 /* The string has 16th byte zero still from set at top of function */
1582 if (i
== RFC1001_NAME_LEN
&& param
->string
[i
] != 0)
1583 pr_warn("server netbiosname longer than 15 truncated\n");
1586 /* version of mount userspace tools, not dialect */
1587 /* If interface changes in mount.cifs bump to new ver */
1588 if (strncasecmp(param
->string
, "1", 1) == 0) {
1589 if (strlen(param
->string
) > 1) {
1590 pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
1592 goto cifs_parse_mount_err
;
1594 /* This is the default */
1597 /* For all other value, error */
1598 pr_warn("Invalid mount helper version specified\n");
1599 goto cifs_parse_mount_err
;
1601 /* protocol version (dialect) */
1602 if (cifs_parse_smb_version(fc
, param
->string
, ctx
, is_smb3
) != 0)
1603 goto cifs_parse_mount_err
;
1604 ctx
->got_version
= true;
1607 if (cifs_parse_security_flavors(fc
, param
->string
, ctx
) != 0)
1608 goto cifs_parse_mount_err
;
1610 case Opt_upcalltarget
:
1611 if (cifs_parse_upcall_target(fc
, param
->string
, ctx
) != 0)
1612 goto cifs_parse_mount_err
;
1615 if (cifs_parse_cache_flavor(fc
, param
->string
, ctx
) != 0)
1616 goto cifs_parse_mount_err
;
1619 #ifndef CONFIG_CIFS_SWN_UPCALL
1620 cifs_errorf(fc
, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
1621 goto cifs_parse_mount_err
;
1623 ctx
->witness
= true;
1624 pr_warn_once("Witness protocol support is experimental\n");
1627 #ifndef CONFIG_CIFS_ROOT
1628 cifs_dbg(VFS
, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
1629 goto cifs_parse_mount_err
;
1633 case Opt_posixpaths
:
1635 ctx
->posix_paths
= 0;
1637 ctx
->posix_paths
= 1;
1640 if (result
.negated
) {
1641 if (ctx
->linux_ext
== 1)
1642 pr_warn_once("conflicting posix mount options specified\n");
1644 ctx
->no_linux_ext
= 1;
1646 if (ctx
->no_linux_ext
== 1)
1647 pr_warn_once("conflicting posix mount options specified\n");
1649 ctx
->no_linux_ext
= 0;
1656 if (result
.negated
) {
1658 * turn off mandatory locking in mode
1659 * if remote locking is turned off since the
1660 * local vfs will do advisory
1662 if (ctx
->file_mode
==
1663 (S_IALLUGO
& ~(S_ISUID
| S_IXGRP
)))
1664 ctx
->file_mode
= S_IALLUGO
;
1669 case Opt_handlecache
:
1671 ctx
->nohandlecache
= 1;
1673 ctx
->nohandlecache
= 0;
1675 case Opt_forcemandatorylock
:
1679 ctx
->setuids
= result
.negated
;
1682 ctx
->intr
= !result
.negated
;
1684 case Opt_setuidfromacl
:
1685 ctx
->setuidfromacl
= 1;
1687 case Opt_strictsync
:
1688 ctx
->nostrictsync
= result
.negated
;
1691 ctx
->server_ino
= !result
.negated
;
1693 case Opt_rwpidforward
:
1694 ctx
->rwpidforward
= 1;
1700 ctx
->cifs_acl
= !result
.negated
;
1703 ctx
->no_psx_acl
= result
.negated
;
1705 case Opt_locallease
:
1706 ctx
->local_lease
= 1;
1711 case Opt_ignore_signature
:
1713 ctx
->ignore_signature
= true;
1716 /* we do not do the following in secFlags because seal
1717 * is a per tree connection (mount) not a per socket
1718 * or per-smb connection option in the protocol
1719 * vol->secFlg |= CIFSSEC_MUST_SEAL;
1724 pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
1727 #ifndef CONFIG_CIFS_FSCACHE
1728 cifs_errorf(fc
, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
1729 goto cifs_parse_mount_err
;
1733 case Opt_mfsymlinks
:
1734 ctx
->mfsymlinks
= true;
1737 ctx
->multiuser
= true;
1742 case Opt_nosharesock
:
1743 ctx
->nosharesock
= true;
1745 case Opt_persistent
:
1746 if (result
.negated
) {
1747 ctx
->nopersistent
= true;
1748 if (ctx
->persistent
) {
1749 cifs_errorf(fc
, "persistenthandles mount options conflict\n");
1750 goto cifs_parse_mount_err
;
1753 ctx
->persistent
= true;
1754 if ((ctx
->nopersistent
) || (ctx
->resilient
)) {
1755 cifs_errorf(fc
, "persistenthandles mount options conflict\n");
1756 goto cifs_parse_mount_err
;
1761 if (result
.negated
) {
1762 ctx
->resilient
= false; /* already the default */
1764 ctx
->resilient
= true;
1765 if (ctx
->persistent
) {
1766 cifs_errorf(fc
, "persistenthandles mount options conflict\n");
1767 goto cifs_parse_mount_err
;
1771 case Opt_tcp_nodelay
:
1772 /* tcp nodelay should not usually be needed since we CORK/UNCORK the socket */
1774 ctx
->sockopt_tcp_nodelay
= false;
1776 ctx
->sockopt_tcp_nodelay
= true;
1778 case Opt_domainauto
:
1779 ctx
->domainauto
= true;
1785 if (parse_reparse_flavor(fc
, param
->string
, ctx
))
1786 goto cifs_parse_mount_err
;
1788 case Opt_nativesocket
:
1789 ctx
->nonativesocket
= result
.negated
;
1792 if (parse_symlink_flavor(fc
, param
->string
, ctx
))
1793 goto cifs_parse_mount_err
;
1795 case Opt_symlinkroot
:
1796 if (param
->string
[0] != '/') {
1797 cifs_errorf(fc
, "symlinkroot mount options must be absolute path\n");
1798 goto cifs_parse_mount_err
;
1800 kfree(ctx
->symlinkroot
);
1801 ctx
->symlinkroot
= kstrdup(param
->string
, GFP_KERNEL
);
1802 if (!ctx
->symlinkroot
)
1803 goto cifs_parse_mount_err
;
1806 /* case Opt_ignore: - is ignored as expected ... */
1808 if (ctx
->multiuser
&& ctx
->upcall_target
== UPTARGET_MOUNT
) {
1809 cifs_errorf(fc
, "multiuser mount option not supported with upcalltarget set as 'mount'\n");
1810 goto cifs_parse_mount_err
;
1814 * By default resolve all native absolute symlinks relative to "/mnt/".
1815 * Same default has drvfs driver running in WSL for resolving SMB shares.
1817 if (!ctx
->symlinkroot
)
1818 ctx
->symlinkroot
= kstrdup("/mnt/", GFP_KERNEL
);
1822 cifs_parse_mount_err
:
1823 kfree_sensitive(ctx
->password
);
1824 ctx
->password
= NULL
;
1825 kfree_sensitive(ctx
->password2
);
1826 ctx
->password2
= NULL
;
1830 enum cifs_symlink_type
get_cifs_symlink_type(struct cifs_sb_info
*cifs_sb
)
1832 if (cifs_sb
->ctx
->symlink_type
== CIFS_SYMLINK_TYPE_DEFAULT
) {
1833 if (cifs_sb
->ctx
->mfsymlinks
)
1834 return CIFS_SYMLINK_TYPE_MFSYMLINKS
;
1835 else if (cifs_sb
->ctx
->sfu_emul
)
1836 return CIFS_SYMLINK_TYPE_SFU
;
1837 else if (cifs_sb
->ctx
->linux_ext
&& !cifs_sb
->ctx
->no_linux_ext
)
1838 return CIFS_SYMLINK_TYPE_UNIX
;
1839 else if (cifs_sb
->ctx
->reparse_type
!= CIFS_REPARSE_TYPE_NONE
)
1840 return CIFS_SYMLINK_TYPE_NATIVE
;
1842 return CIFS_SYMLINK_TYPE_NONE
;
1844 return cifs_sb
->ctx
->symlink_type
;
1848 int smb3_init_fs_context(struct fs_context
*fc
)
1850 struct smb3_fs_context
*ctx
;
1851 char *nodename
= utsname()->nodename
;
1854 ctx
= kzalloc(sizeof(struct smb3_fs_context
), GFP_KERNEL
);
1858 strscpy(ctx
->workstation_name
, nodename
, sizeof(ctx
->workstation_name
));
1861 * does not have to be perfect mapping since field is
1862 * informational, only used for servers that do not support
1863 * port 445 and it can be overridden at mount time
1865 memset(ctx
->source_rfc1001_name
, 0x20, RFC1001_NAME_LEN
);
1866 for (i
= 0; i
< strnlen(nodename
, RFC1001_NAME_LEN
); i
++)
1867 ctx
->source_rfc1001_name
[i
] = toupper(nodename
[i
]);
1869 ctx
->source_rfc1001_name
[RFC1001_NAME_LEN
] = 0;
1871 * null target name indicates to use *SMBSERVR default called name
1872 * if we end up sending RFC1001 session initialize
1874 ctx
->target_rfc1001_name
[0] = 0;
1875 ctx
->cred_uid
= current_uid();
1876 ctx
->linux_uid
= current_uid();
1877 ctx
->linux_gid
= current_gid();
1878 /* By default 4MB read ahead size, 1MB block size */
1879 ctx
->bsize
= CIFS_DEFAULT_IOSIZE
; /* can improve cp performance significantly */
1880 ctx
->rasize
= 0; /* 0 = use default (ie negotiated rsize) for read ahead pages */
1883 * default to SFM style remapping of seven reserved characters
1884 * unless user overrides it or we negotiate CIFS POSIX where
1885 * it is unnecessary. Can not simultaneously use more than one mapping
1886 * since then readdir could list files that open could not open
1890 /* default to only allowing write access to owner of the mount */
1891 ctx
->dir_mode
= ctx
->file_mode
= S_IRUGO
| S_IXUGO
| S_IWUSR
;
1893 /* ctx->retry default is 0 (i.e. "soft" limited retry not hard retry) */
1894 /* default is always to request posix paths. */
1895 ctx
->posix_paths
= 1;
1896 /* default to using server inode numbers where available */
1897 ctx
->server_ino
= 1;
1899 /* default is to use strict cifs caching semantics */
1900 ctx
->strict_io
= true;
1902 ctx
->acregmax
= CIFS_DEF_ACTIMEO
;
1903 ctx
->acdirmax
= CIFS_DEF_ACTIMEO
;
1904 ctx
->closetimeo
= SMB3_DEF_DCLOSETIMEO
;
1905 ctx
->max_cached_dirs
= MAX_CACHED_FIDS
;
1906 /* Most clients set timeout to 0, allows server to use its default */
1907 ctx
->handle_timeout
= 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
1909 /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
1910 ctx
->ops
= &smb30_operations
;
1911 ctx
->vals
= &smbdefault_values
;
1913 ctx
->echo_interval
= SMB_ECHO_INTERVAL_DEFAULT
;
1915 /* default to no multichannel (single server connection) */
1916 ctx
->multichannel
= false;
1917 ctx
->max_channels
= 1;
1919 ctx
->backupuid_specified
= false; /* no backup intent for a user */
1920 ctx
->backupgid_specified
= false; /* no backup intent for a group */
1923 ctx
->reparse_type
= CIFS_REPARSE_TYPE_DEFAULT
;
1924 ctx
->symlink_type
= CIFS_SYMLINK_TYPE_DEFAULT
;
1925 ctx
->nonativesocket
= 0;
1928 * short int override_uid = -1;
1929 * short int override_gid = -1;
1930 * char *nodename = strdup(utsname()->nodename);
1931 * struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
1934 fc
->fs_private
= ctx
;
1935 fc
->ops
= &smb3_fs_context_ops
;
1940 smb3_cleanup_fs_context_contents(struct smb3_fs_context
*ctx
)
1946 * Make sure this stays in sync with smb3_fs_context_dup()
1948 kfree(ctx
->username
);
1949 ctx
->username
= NULL
;
1950 kfree_sensitive(ctx
->password
);
1951 ctx
->password
= NULL
;
1952 kfree_sensitive(ctx
->password2
);
1953 ctx
->password2
= NULL
;
1954 kfree(ctx
->server_hostname
);
1955 ctx
->server_hostname
= NULL
;
1960 kfree(ctx
->domainname
);
1961 ctx
->domainname
= NULL
;
1962 kfree(ctx
->nodename
);
1963 ctx
->nodename
= NULL
;
1964 kfree(ctx
->iocharset
);
1965 ctx
->iocharset
= NULL
;
1966 kfree(ctx
->prepath
);
1967 ctx
->prepath
= NULL
;
1968 kfree(ctx
->leaf_fullpath
);
1969 ctx
->leaf_fullpath
= NULL
;
1970 kfree(ctx
->dns_dom
);
1971 ctx
->dns_dom
= NULL
;
1972 kfree(ctx
->symlinkroot
);
1973 ctx
->symlinkroot
= NULL
;
1977 smb3_cleanup_fs_context(struct smb3_fs_context
*ctx
)
1981 smb3_cleanup_fs_context_contents(ctx
);
1985 void smb3_update_mnt_flags(struct cifs_sb_info
*cifs_sb
)
1987 struct smb3_fs_context
*ctx
= cifs_sb
->ctx
;
1990 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NO_DFS
;
1992 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NO_DFS
;
1995 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NO_PERM
;
1997 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NO_PERM
;
2000 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_SET_UID
;
2002 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_SET_UID
;
2004 if (ctx
->setuidfromacl
)
2005 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_UID_FROM_ACL
;
2007 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_UID_FROM_ACL
;
2009 if (ctx
->server_ino
)
2010 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_SERVER_INUM
;
2012 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_SERVER_INUM
;
2015 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_MAP_SFM_CHR
;
2017 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_MAP_SFM_CHR
;
2020 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_MAP_SPECIAL_CHR
;
2022 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_MAP_SPECIAL_CHR
;
2025 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NO_XATTR
;
2027 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NO_XATTR
;
2030 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_UNX_EMUL
;
2032 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_UNX_EMUL
;
2035 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NO_BRL
;
2037 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NO_BRL
;
2039 if (ctx
->nohandlecache
)
2040 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NO_HANDLE_CACHE
;
2042 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NO_HANDLE_CACHE
;
2044 if (ctx
->nostrictsync
)
2045 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NOSSYNC
;
2047 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NOSSYNC
;
2050 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_NOPOSIXBRL
;
2052 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_NOPOSIXBRL
;
2054 if (ctx
->rwpidforward
)
2055 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_RWPIDFORWARD
;
2057 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_RWPIDFORWARD
;
2060 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_MODE_FROM_SID
;
2062 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_MODE_FROM_SID
;
2065 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_CIFS_ACL
;
2067 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_CIFS_ACL
;
2069 if (ctx
->backupuid_specified
)
2070 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_CIFS_BACKUPUID
;
2072 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_CIFS_BACKUPUID
;
2074 if (ctx
->backupgid_specified
)
2075 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_CIFS_BACKUPGID
;
2077 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_CIFS_BACKUPGID
;
2079 if (ctx
->override_uid
)
2080 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_OVERR_UID
;
2082 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_OVERR_UID
;
2084 if (ctx
->override_gid
)
2085 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_OVERR_GID
;
2087 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_OVERR_GID
;
2090 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_DYNPERM
;
2092 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_DYNPERM
;
2095 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_FSCACHE
;
2097 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_FSCACHE
;
2100 cifs_sb
->mnt_cifs_flags
|= (CIFS_MOUNT_MULTIUSER
|
2101 CIFS_MOUNT_NO_PERM
);
2103 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_MULTIUSER
;
2107 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_STRICT_IO
;
2109 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_STRICT_IO
;
2112 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_DIRECT_IO
;
2114 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_DIRECT_IO
;
2116 if (ctx
->mfsymlinks
)
2117 cifs_sb
->mnt_cifs_flags
|= CIFS_MOUNT_MF_SYMLINKS
;
2119 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_MF_SYMLINKS
;
2120 if (ctx
->mfsymlinks
) {
2121 if (ctx
->sfu_emul
) {
2123 * Our SFU ("Services for Unix") emulation allows now
2124 * creating new and reading existing SFU symlinks.
2125 * Older Linux kernel versions were not able to neither
2126 * read existing nor create new SFU symlinks. But
2127 * creating and reading SFU style mknod and FIFOs was
2128 * supported for long time. When "mfsymlinks" and
2129 * "sfu" are both enabled at the same time, it allows
2130 * reading both types of symlinks, but will only create
2131 * them with mfsymlinks format. This allows better
2132 * Apple compatibility, compatibility with older Linux
2133 * kernel clients (probably better for Samba too)
2134 * while still recognizing old Windows style symlinks.
2136 cifs_dbg(VFS
, "mount options mfsymlinks and sfu both enabled\n");
2139 cifs_sb
->mnt_cifs_flags
&= ~CIFS_MOUNT_SHUTDOWN
;