0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <linux/ctype.h>
0022 #include <linux/fs_context.h>
0023 #include <linux/fs_parser.h>
0024 #include <linux/fs.h>
0025 #include <linux/mount.h>
0026 #include <linux/parser.h>
0027 #include <linux/utsname.h>
0028 #include "cifsfs.h"
0029 #include "cifspdu.h"
0030 #include "cifsglob.h"
0031 #include "cifsproto.h"
0032 #include "cifs_unicode.h"
0033 #include "cifs_debug.h"
0034 #include "cifs_fs_sb.h"
0035 #include "ntlmssp.h"
0036 #include "nterr.h"
0037 #include "rfc1002pdu.h"
0038 #include "fs_context.h"
0039
0040 static DEFINE_MUTEX(cifs_mount_mutex);
0041
0042 static const match_table_t cifs_smb_version_tokens = {
0043 { Smb_1, SMB1_VERSION_STRING },
0044 { Smb_20, SMB20_VERSION_STRING},
0045 { Smb_21, SMB21_VERSION_STRING },
0046 { Smb_30, SMB30_VERSION_STRING },
0047 { Smb_302, SMB302_VERSION_STRING },
0048 { Smb_302, ALT_SMB302_VERSION_STRING },
0049 { Smb_311, SMB311_VERSION_STRING },
0050 { Smb_311, ALT_SMB311_VERSION_STRING },
0051 { Smb_3any, SMB3ANY_VERSION_STRING },
0052 { Smb_default, SMBDEFAULT_VERSION_STRING },
0053 { Smb_version_err, NULL }
0054 };
0055
0056 static const match_table_t cifs_secflavor_tokens = {
0057 { Opt_sec_krb5, "krb5" },
0058 { Opt_sec_krb5i, "krb5i" },
0059 { Opt_sec_krb5p, "krb5p" },
0060 { Opt_sec_ntlmsspi, "ntlmsspi" },
0061 { Opt_sec_ntlmssp, "ntlmssp" },
0062 { Opt_sec_ntlmv2, "nontlm" },
0063 { Opt_sec_ntlmv2, "ntlmv2" },
0064 { Opt_sec_ntlmv2i, "ntlmv2i" },
0065 { Opt_sec_none, "none" },
0066
0067 { Opt_sec_err, NULL }
0068 };
0069
0070 const struct fs_parameter_spec smb3_fs_parameters[] = {
0071
0072 fsparam_flag_no("user_xattr", Opt_user_xattr),
0073 fsparam_flag_no("forceuid", Opt_forceuid),
0074 fsparam_flag_no("multichannel", Opt_multichannel),
0075 fsparam_flag_no("forcegid", Opt_forcegid),
0076 fsparam_flag("noblocksend", Opt_noblocksend),
0077 fsparam_flag("noautotune", Opt_noautotune),
0078 fsparam_flag("nolease", Opt_nolease),
0079 fsparam_flag_no("hard", Opt_hard),
0080 fsparam_flag_no("soft", Opt_soft),
0081 fsparam_flag_no("perm", Opt_perm),
0082 fsparam_flag("nodelete", Opt_nodelete),
0083 fsparam_flag_no("mapposix", Opt_mapposix),
0084 fsparam_flag("mapchars", Opt_mapchars),
0085 fsparam_flag("nomapchars", Opt_nomapchars),
0086 fsparam_flag_no("sfu", Opt_sfu),
0087 fsparam_flag("nodfs", Opt_nodfs),
0088 fsparam_flag_no("posixpaths", Opt_posixpaths),
0089 fsparam_flag_no("unix", Opt_unix),
0090 fsparam_flag_no("linux", Opt_unix),
0091 fsparam_flag_no("posix", Opt_unix),
0092 fsparam_flag("nocase", Opt_nocase),
0093 fsparam_flag("ignorecase", Opt_nocase),
0094 fsparam_flag_no("brl", Opt_brl),
0095 fsparam_flag_no("handlecache", Opt_handlecache),
0096 fsparam_flag("forcemandatorylock", Opt_forcemandatorylock),
0097 fsparam_flag("forcemand", Opt_forcemandatorylock),
0098 fsparam_flag("setuidfromacl", Opt_setuidfromacl),
0099 fsparam_flag("idsfromsid", Opt_setuidfromacl),
0100 fsparam_flag_no("setuids", Opt_setuids),
0101 fsparam_flag_no("dynperm", Opt_dynperm),
0102 fsparam_flag_no("intr", Opt_intr),
0103 fsparam_flag_no("strictsync", Opt_strictsync),
0104 fsparam_flag_no("serverino", Opt_serverino),
0105 fsparam_flag("rwpidforward", Opt_rwpidforward),
0106 fsparam_flag("cifsacl", Opt_cifsacl),
0107 fsparam_flag_no("acl", Opt_acl),
0108 fsparam_flag("locallease", Opt_locallease),
0109 fsparam_flag("sign", Opt_sign),
0110 fsparam_flag("ignore_signature", Opt_ignore_signature),
0111 fsparam_flag("signloosely", Opt_ignore_signature),
0112 fsparam_flag("seal", Opt_seal),
0113 fsparam_flag("noac", Opt_noac),
0114 fsparam_flag("fsc", Opt_fsc),
0115 fsparam_flag("mfsymlinks", Opt_mfsymlinks),
0116 fsparam_flag("multiuser", Opt_multiuser),
0117 fsparam_flag("sloppy", Opt_sloppy),
0118 fsparam_flag("nosharesock", Opt_nosharesock),
0119 fsparam_flag_no("persistenthandles", Opt_persistent),
0120 fsparam_flag_no("resilienthandles", Opt_resilient),
0121 fsparam_flag_no("tcpnodelay", Opt_tcp_nodelay),
0122 fsparam_flag("nosparse", Opt_nosparse),
0123 fsparam_flag("domainauto", Opt_domainauto),
0124 fsparam_flag("rdma", Opt_rdma),
0125 fsparam_flag("modesid", Opt_modesid),
0126 fsparam_flag("modefromsid", Opt_modesid),
0127 fsparam_flag("rootfs", Opt_rootfs),
0128 fsparam_flag("compress", Opt_compress),
0129 fsparam_flag("witness", Opt_witness),
0130
0131
0132 fsparam_u32("backupuid", Opt_backupuid),
0133 fsparam_u32("backupgid", Opt_backupgid),
0134 fsparam_u32("uid", Opt_uid),
0135 fsparam_u32("cruid", Opt_cruid),
0136 fsparam_u32("gid", Opt_gid),
0137 fsparam_u32("file_mode", Opt_file_mode),
0138 fsparam_u32("dirmode", Opt_dirmode),
0139 fsparam_u32("dir_mode", Opt_dirmode),
0140 fsparam_u32("port", Opt_port),
0141 fsparam_u32("min_enc_offload", Opt_min_enc_offload),
0142 fsparam_u32("esize", Opt_min_enc_offload),
0143 fsparam_u32("bsize", Opt_blocksize),
0144 fsparam_u32("rasize", Opt_rasize),
0145 fsparam_u32("rsize", Opt_rsize),
0146 fsparam_u32("wsize", Opt_wsize),
0147 fsparam_u32("actimeo", Opt_actimeo),
0148 fsparam_u32("acdirmax", Opt_acdirmax),
0149 fsparam_u32("acregmax", Opt_acregmax),
0150 fsparam_u32("closetimeo", Opt_closetimeo),
0151 fsparam_u32("echo_interval", Opt_echo_interval),
0152 fsparam_u32("max_credits", Opt_max_credits),
0153 fsparam_u32("handletimeout", Opt_handletimeout),
0154 fsparam_u64("snapshot", Opt_snapshot),
0155 fsparam_u32("max_channels", Opt_max_channels),
0156
0157
0158 fsparam_string("source", Opt_source),
0159 fsparam_string("user", Opt_user),
0160 fsparam_string("username", Opt_user),
0161 fsparam_string("pass", Opt_pass),
0162 fsparam_string("password", Opt_pass),
0163 fsparam_string("ip", Opt_ip),
0164 fsparam_string("addr", Opt_ip),
0165 fsparam_string("domain", Opt_domain),
0166 fsparam_string("dom", Opt_domain),
0167 fsparam_string("srcaddr", Opt_srcaddr),
0168 fsparam_string("iocharset", Opt_iocharset),
0169 fsparam_string("netbiosname", Opt_netbiosname),
0170 fsparam_string("servern", Opt_servern),
0171 fsparam_string("ver", Opt_ver),
0172 fsparam_string("vers", Opt_vers),
0173 fsparam_string("sec", Opt_sec),
0174 fsparam_string("cache", Opt_cache),
0175
0176
0177 fsparam_flag("guest", Opt_ignore),
0178 fsparam_flag("noatime", Opt_ignore),
0179 fsparam_flag("relatime", Opt_ignore),
0180 fsparam_flag("_netdev", Opt_ignore),
0181 fsparam_flag_no("suid", Opt_ignore),
0182 fsparam_flag_no("exec", Opt_ignore),
0183 fsparam_flag_no("dev", Opt_ignore),
0184 fsparam_flag_no("mand", Opt_ignore),
0185 fsparam_flag_no("auto", Opt_ignore),
0186 fsparam_string("cred", Opt_ignore),
0187 fsparam_string("credentials", Opt_ignore),
0188
0189
0190
0191
0192 fsparam_string("unc", Opt_ignore),
0193 fsparam_string("prefixpath", Opt_ignore),
0194 {}
0195 };
0196
0197 static int
0198 cifs_parse_security_flavors(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
0199 {
0200
0201 substring_t args[MAX_OPT_ARGS];
0202
0203
0204
0205
0206
0207 ctx->sectype = Unspecified;
0208 ctx->sign = false;
0209
0210 switch (match_token(value, cifs_secflavor_tokens, args)) {
0211 case Opt_sec_krb5p:
0212 cifs_errorf(fc, "sec=krb5p is not supported!\n");
0213 return 1;
0214 case Opt_sec_krb5i:
0215 ctx->sign = true;
0216 fallthrough;
0217 case Opt_sec_krb5:
0218 ctx->sectype = Kerberos;
0219 break;
0220 case Opt_sec_ntlmsspi:
0221 ctx->sign = true;
0222 fallthrough;
0223 case Opt_sec_ntlmssp:
0224 ctx->sectype = RawNTLMSSP;
0225 break;
0226 case Opt_sec_ntlmv2i:
0227 ctx->sign = true;
0228 fallthrough;
0229 case Opt_sec_ntlmv2:
0230 ctx->sectype = NTLMv2;
0231 break;
0232 case Opt_sec_none:
0233 ctx->nullauth = 1;
0234 break;
0235 default:
0236 cifs_errorf(fc, "bad security option: %s\n", value);
0237 return 1;
0238 }
0239
0240 return 0;
0241 }
0242
0243 static const match_table_t cifs_cacheflavor_tokens = {
0244 { Opt_cache_loose, "loose" },
0245 { Opt_cache_strict, "strict" },
0246 { Opt_cache_none, "none" },
0247 { Opt_cache_ro, "ro" },
0248 { Opt_cache_rw, "singleclient" },
0249 { Opt_cache_err, NULL }
0250 };
0251
0252 static int
0253 cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
0254 {
0255 substring_t args[MAX_OPT_ARGS];
0256
0257 switch (match_token(value, cifs_cacheflavor_tokens, args)) {
0258 case Opt_cache_loose:
0259 ctx->direct_io = false;
0260 ctx->strict_io = false;
0261 ctx->cache_ro = false;
0262 ctx->cache_rw = false;
0263 break;
0264 case Opt_cache_strict:
0265 ctx->direct_io = false;
0266 ctx->strict_io = true;
0267 ctx->cache_ro = false;
0268 ctx->cache_rw = false;
0269 break;
0270 case Opt_cache_none:
0271 ctx->direct_io = true;
0272 ctx->strict_io = false;
0273 ctx->cache_ro = false;
0274 ctx->cache_rw = false;
0275 break;
0276 case Opt_cache_ro:
0277 ctx->direct_io = false;
0278 ctx->strict_io = false;
0279 ctx->cache_ro = true;
0280 ctx->cache_rw = false;
0281 break;
0282 case Opt_cache_rw:
0283 ctx->direct_io = false;
0284 ctx->strict_io = false;
0285 ctx->cache_ro = false;
0286 ctx->cache_rw = true;
0287 break;
0288 default:
0289 cifs_errorf(fc, "bad cache= option: %s\n", value);
0290 return 1;
0291 }
0292 return 0;
0293 }
0294
0295 #define DUP_CTX_STR(field) \
0296 do { \
0297 if (ctx->field) { \
0298 new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
0299 if (new_ctx->field == NULL) { \
0300 smb3_cleanup_fs_context_contents(new_ctx); \
0301 return -ENOMEM; \
0302 } \
0303 } \
0304 } while (0)
0305
0306 int
0307 smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
0308 {
0309 memcpy(new_ctx, ctx, sizeof(*ctx));
0310 new_ctx->prepath = NULL;
0311 new_ctx->mount_options = NULL;
0312 new_ctx->nodename = NULL;
0313 new_ctx->username = NULL;
0314 new_ctx->password = NULL;
0315 new_ctx->server_hostname = NULL;
0316 new_ctx->domainname = NULL;
0317 new_ctx->UNC = NULL;
0318 new_ctx->source = NULL;
0319 new_ctx->iocharset = NULL;
0320
0321
0322
0323 DUP_CTX_STR(prepath);
0324 DUP_CTX_STR(mount_options);
0325 DUP_CTX_STR(username);
0326 DUP_CTX_STR(password);
0327 DUP_CTX_STR(server_hostname);
0328 DUP_CTX_STR(UNC);
0329 DUP_CTX_STR(source);
0330 DUP_CTX_STR(domainname);
0331 DUP_CTX_STR(nodename);
0332 DUP_CTX_STR(iocharset);
0333
0334 return 0;
0335 }
0336
0337 static int
0338 cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_context *ctx, bool is_smb3)
0339 {
0340 substring_t args[MAX_OPT_ARGS];
0341
0342 switch (match_token(value, cifs_smb_version_tokens, args)) {
0343 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
0344 case Smb_1:
0345 if (disable_legacy_dialects) {
0346 cifs_errorf(fc, "mount with legacy dialect disabled\n");
0347 return 1;
0348 }
0349 if (is_smb3) {
0350 cifs_errorf(fc, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
0351 return 1;
0352 }
0353 cifs_errorf(fc, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
0354 ctx->ops = &smb1_operations;
0355 ctx->vals = &smb1_values;
0356 break;
0357 case Smb_20:
0358 if (disable_legacy_dialects) {
0359 cifs_errorf(fc, "mount with legacy dialect disabled\n");
0360 return 1;
0361 }
0362 if (is_smb3) {
0363 cifs_errorf(fc, "vers=2.0 not permitted when mounting with smb3\n");
0364 return 1;
0365 }
0366 ctx->ops = &smb20_operations;
0367 ctx->vals = &smb20_values;
0368 break;
0369 #else
0370 case Smb_1:
0371 cifs_errorf(fc, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
0372 return 1;
0373 case Smb_20:
0374 cifs_errorf(fc, "vers=2.0 mount not permitted when legacy dialects disabled\n");
0375 return 1;
0376 #endif
0377 case Smb_21:
0378 ctx->ops = &smb21_operations;
0379 ctx->vals = &smb21_values;
0380 break;
0381 case Smb_30:
0382 ctx->ops = &smb30_operations;
0383 ctx->vals = &smb30_values;
0384 break;
0385 case Smb_302:
0386 ctx->ops = &smb30_operations;
0387 ctx->vals = &smb302_values;
0388 break;
0389 case Smb_311:
0390 ctx->ops = &smb311_operations;
0391 ctx->vals = &smb311_values;
0392 break;
0393 case Smb_3any:
0394 ctx->ops = &smb30_operations;
0395 ctx->vals = &smb3any_values;
0396 break;
0397 case Smb_default:
0398 ctx->ops = &smb30_operations;
0399 ctx->vals = &smbdefault_values;
0400 break;
0401 default:
0402 cifs_errorf(fc, "Unknown vers= option specified: %s\n", value);
0403 return 1;
0404 }
0405 return 0;
0406 }
0407
0408 int smb3_parse_opt(const char *options, const char *key, char **val)
0409 {
0410 int rc = -ENOENT;
0411 char *opts, *orig, *p;
0412
0413 orig = opts = kstrdup(options, GFP_KERNEL);
0414 if (!opts)
0415 return -ENOMEM;
0416
0417 while ((p = strsep(&opts, ","))) {
0418 char *nval;
0419
0420 if (!*p)
0421 continue;
0422 if (strncasecmp(p, key, strlen(key)))
0423 continue;
0424 nval = strchr(p, '=');
0425 if (nval) {
0426 if (nval == p)
0427 continue;
0428 *nval++ = 0;
0429 *val = kstrdup(nval, GFP_KERNEL);
0430 rc = !*val ? -ENOMEM : 0;
0431 goto out;
0432 }
0433 }
0434 out:
0435 kfree(orig);
0436 return rc;
0437 }
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447 #define IS_DELIM(c) ((c) == '/' || (c) == '\\')
0448 static char *sanitize_path(char *path)
0449 {
0450 char *cursor1 = path, *cursor2 = path;
0451
0452
0453 while (IS_DELIM(*cursor1))
0454 cursor1++;
0455
0456
0457 *cursor2 = *cursor1;
0458
0459
0460 while (*(cursor1++)) {
0461
0462 if (IS_DELIM(*cursor1) && IS_DELIM(*cursor2))
0463 continue;
0464 *(++cursor2) = *cursor1;
0465 }
0466
0467
0468 if (IS_DELIM(*(cursor2 - 1)))
0469 cursor2--;
0470
0471 *(cursor2) = '\0';
0472 return kstrdup(path, GFP_KERNEL);
0473 }
0474
0475
0476
0477
0478
0479
0480 int
0481 smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
0482 {
0483 char *pos;
0484 const char *delims = "/\\";
0485 size_t len;
0486
0487 if (unlikely(!devname || !*devname)) {
0488 cifs_dbg(VFS, "Device name not specified\n");
0489 return -EINVAL;
0490 }
0491
0492
0493 len = strspn(devname, delims);
0494 if (len != 2)
0495 return -EINVAL;
0496
0497
0498 pos = strpbrk(devname + 2, delims);
0499 if (!pos)
0500 return -EINVAL;
0501
0502
0503 kfree(ctx->server_hostname);
0504 ctx->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL);
0505 if (!ctx->server_hostname)
0506 return -ENOMEM;
0507
0508
0509 ++pos;
0510
0511
0512 len = strcspn(pos, delims);
0513
0514
0515 pos += len;
0516 kfree(ctx->UNC);
0517 ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
0518 if (!ctx->UNC)
0519 return -ENOMEM;
0520
0521 convert_delimiter(ctx->UNC, '\\');
0522
0523
0524 if (*pos == '/' || *pos == '\\')
0525 pos++;
0526
0527 kfree(ctx->prepath);
0528 ctx->prepath = NULL;
0529
0530
0531 if (!*pos)
0532 return 0;
0533
0534 ctx->prepath = sanitize_path(pos);
0535 if (!ctx->prepath)
0536 return -ENOMEM;
0537
0538 return 0;
0539 }
0540
0541 static void smb3_fs_context_free(struct fs_context *fc);
0542 static int smb3_fs_context_parse_param(struct fs_context *fc,
0543 struct fs_parameter *param);
0544 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
0545 void *data);
0546 static int smb3_get_tree(struct fs_context *fc);
0547 static int smb3_reconfigure(struct fs_context *fc);
0548
0549 static const struct fs_context_operations smb3_fs_context_ops = {
0550 .free = smb3_fs_context_free,
0551 .parse_param = smb3_fs_context_parse_param,
0552 .parse_monolithic = smb3_fs_context_parse_monolithic,
0553 .get_tree = smb3_get_tree,
0554 .reconfigure = smb3_reconfigure,
0555 };
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569 static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
0570 void *data)
0571 {
0572 struct smb3_fs_context *ctx = smb3_fc2context(fc);
0573 char *options = data, *key;
0574 int ret = 0;
0575
0576 if (!options)
0577 return 0;
0578
0579 ctx->mount_options = kstrdup(data, GFP_KERNEL);
0580 if (ctx->mount_options == NULL)
0581 return -ENOMEM;
0582
0583 ret = security_sb_eat_lsm_opts(options, &fc->security);
0584 if (ret)
0585 return ret;
0586
0587
0588 while ((key = strsep(&options, ",")) != NULL) {
0589 size_t len;
0590 char *value;
0591
0592 if (*key == 0)
0593 break;
0594
0595
0596
0597
0598
0599 while (options && options[0] == ',') {
0600 len = strlen(key);
0601 strcpy(key + len, options);
0602 options = strchr(options, ',');
0603 if (options)
0604 *options++ = 0;
0605 }
0606
0607
0608 len = 0;
0609 value = strchr(key, '=');
0610 if (value) {
0611 if (value == key)
0612 continue;
0613 *value++ = 0;
0614 len = strlen(value);
0615 }
0616
0617 ret = vfs_parse_fs_string(fc, key, value, len);
0618 if (ret < 0)
0619 break;
0620 }
0621
0622 return ret;
0623 }
0624
0625
0626
0627
0628 static int smb3_fs_context_validate(struct fs_context *fc)
0629 {
0630 struct smb3_fs_context *ctx = smb3_fc2context(fc);
0631
0632 if (ctx->rdma && ctx->vals->protocol_id < SMB30_PROT_ID) {
0633 cifs_errorf(fc, "SMB Direct requires Version >=3.0\n");
0634 return -EOPNOTSUPP;
0635 }
0636
0637 #ifndef CONFIG_KEYS
0638
0639 if (ctx->multiuser) {
0640 cifs_errorf(fc, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
0641 return -1;
0642 }
0643 #endif
0644
0645 if (ctx->got_version == false)
0646 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");
0647
0648
0649 if (!ctx->UNC) {
0650 cifs_errorf(fc, "CIFS mount error: No usable UNC path provided in device string!\n");
0651 return -1;
0652 }
0653
0654
0655 if (strlen(ctx->UNC) < 3 || !strchr(ctx->UNC + 3, '\\')) {
0656 cifs_errorf(fc, "Malformed UNC. Unable to find share name.\n");
0657 return -ENOENT;
0658 }
0659
0660 if (!ctx->got_ip) {
0661 int len;
0662 const char *slash;
0663
0664
0665
0666 slash = strchr(&ctx->UNC[2], '\\');
0667 len = slash - &ctx->UNC[2];
0668 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
0669 &ctx->UNC[2], len)) {
0670 pr_err("Unable to determine destination address\n");
0671 return -EHOSTUNREACH;
0672 }
0673 }
0674
0675
0676 cifs_set_port((struct sockaddr *)&ctx->dstaddr, ctx->port);
0677
0678 if (ctx->override_uid && !ctx->uid_specified) {
0679 ctx->override_uid = 0;
0680 pr_notice("ignoring forceuid mount option specified with no uid= option\n");
0681 }
0682
0683 if (ctx->override_gid && !ctx->gid_specified) {
0684 ctx->override_gid = 0;
0685 pr_notice("ignoring forcegid mount option specified with no gid= option\n");
0686 }
0687
0688 return 0;
0689 }
0690
0691 static int smb3_get_tree_common(struct fs_context *fc)
0692 {
0693 struct smb3_fs_context *ctx = smb3_fc2context(fc);
0694 struct dentry *root;
0695 int rc = 0;
0696
0697 root = cifs_smb3_do_mount(fc->fs_type, 0, ctx);
0698 if (IS_ERR(root))
0699 return PTR_ERR(root);
0700
0701 fc->root = root;
0702
0703 return rc;
0704 }
0705
0706
0707
0708
0709 static int smb3_get_tree(struct fs_context *fc)
0710 {
0711 int err = smb3_fs_context_validate(fc);
0712 int ret;
0713
0714 if (err)
0715 return err;
0716 mutex_lock(&cifs_mount_mutex);
0717 ret = smb3_get_tree_common(fc);
0718 mutex_unlock(&cifs_mount_mutex);
0719 return ret;
0720 }
0721
0722 static void smb3_fs_context_free(struct fs_context *fc)
0723 {
0724 struct smb3_fs_context *ctx = smb3_fc2context(fc);
0725
0726 smb3_cleanup_fs_context(ctx);
0727 }
0728
0729
0730
0731
0732
0733 static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
0734 struct smb3_fs_context *new_ctx,
0735 struct smb3_fs_context *old_ctx)
0736 {
0737 if (new_ctx->posix_paths != old_ctx->posix_paths) {
0738 cifs_errorf(fc, "can not change posixpaths during remount\n");
0739 return -EINVAL;
0740 }
0741 if (new_ctx->sectype != old_ctx->sectype) {
0742 cifs_errorf(fc, "can not change sec during remount\n");
0743 return -EINVAL;
0744 }
0745 if (new_ctx->multiuser != old_ctx->multiuser) {
0746 cifs_errorf(fc, "can not change multiuser during remount\n");
0747 return -EINVAL;
0748 }
0749 if (new_ctx->UNC &&
0750 (!old_ctx->UNC || strcmp(new_ctx->UNC, old_ctx->UNC))) {
0751 cifs_errorf(fc, "can not change UNC during remount\n");
0752 return -EINVAL;
0753 }
0754 if (new_ctx->username &&
0755 (!old_ctx->username || strcmp(new_ctx->username, old_ctx->username))) {
0756 cifs_errorf(fc, "can not change username during remount\n");
0757 return -EINVAL;
0758 }
0759 if (new_ctx->password &&
0760 (!old_ctx->password || strcmp(new_ctx->password, old_ctx->password))) {
0761 cifs_errorf(fc, "can not change password during remount\n");
0762 return -EINVAL;
0763 }
0764 if (new_ctx->domainname &&
0765 (!old_ctx->domainname || strcmp(new_ctx->domainname, old_ctx->domainname))) {
0766 cifs_errorf(fc, "can not change domainname during remount\n");
0767 return -EINVAL;
0768 }
0769 if (strcmp(new_ctx->workstation_name, old_ctx->workstation_name)) {
0770 cifs_errorf(fc, "can not change workstation_name during remount\n");
0771 return -EINVAL;
0772 }
0773 if (new_ctx->nodename &&
0774 (!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
0775 cifs_errorf(fc, "can not change nodename during remount\n");
0776 return -EINVAL;
0777 }
0778 if (new_ctx->iocharset &&
0779 (!old_ctx->iocharset || strcmp(new_ctx->iocharset, old_ctx->iocharset))) {
0780 cifs_errorf(fc, "can not change iocharset during remount\n");
0781 return -EINVAL;
0782 }
0783
0784 return 0;
0785 }
0786
0787 #define STEAL_STRING(cifs_sb, ctx, field) \
0788 do { \
0789 kfree(ctx->field); \
0790 ctx->field = cifs_sb->ctx->field; \
0791 cifs_sb->ctx->field = NULL; \
0792 } while (0)
0793
0794 static int smb3_reconfigure(struct fs_context *fc)
0795 {
0796 struct smb3_fs_context *ctx = smb3_fc2context(fc);
0797 struct dentry *root = fc->root;
0798 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
0799 int rc;
0800
0801 rc = smb3_verify_reconfigure_ctx(fc, ctx, cifs_sb->ctx);
0802 if (rc)
0803 return rc;
0804
0805
0806
0807
0808
0809
0810
0811 STEAL_STRING(cifs_sb, ctx, UNC);
0812 STEAL_STRING(cifs_sb, ctx, source);
0813 STEAL_STRING(cifs_sb, ctx, username);
0814 STEAL_STRING(cifs_sb, ctx, password);
0815 STEAL_STRING(cifs_sb, ctx, domainname);
0816 STEAL_STRING(cifs_sb, ctx, nodename);
0817 STEAL_STRING(cifs_sb, ctx, iocharset);
0818
0819
0820 if (ctx->rsize == 0)
0821 ctx->rsize = cifs_sb->ctx->rsize;
0822 if (ctx->wsize == 0)
0823 ctx->wsize = cifs_sb->ctx->wsize;
0824
0825
0826 smb3_cleanup_fs_context_contents(cifs_sb->ctx);
0827 rc = smb3_fs_context_dup(cifs_sb->ctx, ctx);
0828 smb3_update_mnt_flags(cifs_sb);
0829 #ifdef CONFIG_CIFS_DFS_UPCALL
0830 if (!rc)
0831 rc = dfs_cache_remount_fs(cifs_sb);
0832 #endif
0833
0834 return rc;
0835 }
0836
0837 static int smb3_fs_context_parse_param(struct fs_context *fc,
0838 struct fs_parameter *param)
0839 {
0840 struct fs_parse_result result;
0841 struct smb3_fs_context *ctx = smb3_fc2context(fc);
0842 int i, opt;
0843 bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
0844 bool skip_parsing = false;
0845 kuid_t uid;
0846 kgid_t gid;
0847
0848 cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
0849
0850
0851
0852
0853
0854 if (param->type == fs_value_is_string && param->string[0] == 0) {
0855 if (!strcmp("pass", param->key) || !strcmp("password", param->key)) {
0856 skip_parsing = true;
0857 opt = Opt_pass;
0858 } else if (!strcmp("user", param->key) || !strcmp("username", param->key)) {
0859 skip_parsing = true;
0860 opt = Opt_user;
0861 }
0862 }
0863
0864 if (!skip_parsing) {
0865 opt = fs_parse(fc, smb3_fs_parameters, param, &result);
0866 if (opt < 0)
0867 return ctx->sloppy ? 1 : opt;
0868 }
0869
0870 switch (opt) {
0871 case Opt_compress:
0872 ctx->compression = UNKNOWN_TYPE;
0873 cifs_dbg(VFS,
0874 "SMB3 compression support is experimental\n");
0875 break;
0876 case Opt_nodfs:
0877 ctx->nodfs = 1;
0878 break;
0879 case Opt_hard:
0880 if (result.negated)
0881 ctx->retry = 0;
0882 else
0883 ctx->retry = 1;
0884 break;
0885 case Opt_soft:
0886 if (result.negated)
0887 ctx->retry = 1;
0888 else
0889 ctx->retry = 0;
0890 break;
0891 case Opt_mapposix:
0892 if (result.negated)
0893 ctx->remap = false;
0894 else {
0895 ctx->remap = true;
0896 ctx->sfu_remap = false;
0897 }
0898 break;
0899 case Opt_user_xattr:
0900 if (result.negated)
0901 ctx->no_xattr = 1;
0902 else
0903 ctx->no_xattr = 0;
0904 break;
0905 case Opt_forceuid:
0906 if (result.negated)
0907 ctx->override_uid = 0;
0908 else
0909 ctx->override_uid = 1;
0910 break;
0911 case Opt_forcegid:
0912 if (result.negated)
0913 ctx->override_gid = 0;
0914 else
0915 ctx->override_gid = 1;
0916 break;
0917 case Opt_perm:
0918 if (result.negated)
0919 ctx->noperm = 1;
0920 else
0921 ctx->noperm = 0;
0922 break;
0923 case Opt_dynperm:
0924 if (result.negated)
0925 ctx->dynperm = 0;
0926 else
0927 ctx->dynperm = 1;
0928 break;
0929 case Opt_sfu:
0930 if (result.negated)
0931 ctx->sfu_emul = 0;
0932 else
0933 ctx->sfu_emul = 1;
0934 break;
0935 case Opt_noblocksend:
0936 ctx->noblocksnd = 1;
0937 break;
0938 case Opt_noautotune:
0939 ctx->noautotune = 1;
0940 break;
0941 case Opt_nolease:
0942 ctx->no_lease = 1;
0943 break;
0944 case Opt_nosparse:
0945 ctx->no_sparse = 1;
0946 break;
0947 case Opt_nodelete:
0948 ctx->nodelete = 1;
0949 break;
0950 case Opt_multichannel:
0951 if (result.negated) {
0952 ctx->multichannel = false;
0953 ctx->max_channels = 1;
0954 } else {
0955 ctx->multichannel = true;
0956
0957 if (ctx->max_channels < 2)
0958 ctx->max_channels = 2;
0959 }
0960 break;
0961 case Opt_uid:
0962 uid = make_kuid(current_user_ns(), result.uint_32);
0963 if (!uid_valid(uid))
0964 goto cifs_parse_mount_err;
0965 ctx->linux_uid = uid;
0966 ctx->uid_specified = true;
0967 break;
0968 case Opt_cruid:
0969 uid = make_kuid(current_user_ns(), result.uint_32);
0970 if (!uid_valid(uid))
0971 goto cifs_parse_mount_err;
0972 ctx->cred_uid = uid;
0973 ctx->cruid_specified = true;
0974 break;
0975 case Opt_backupuid:
0976 uid = make_kuid(current_user_ns(), result.uint_32);
0977 if (!uid_valid(uid))
0978 goto cifs_parse_mount_err;
0979 ctx->backupuid = uid;
0980 ctx->backupuid_specified = true;
0981 break;
0982 case Opt_backupgid:
0983 gid = make_kgid(current_user_ns(), result.uint_32);
0984 if (!gid_valid(gid))
0985 goto cifs_parse_mount_err;
0986 ctx->backupgid = gid;
0987 ctx->backupgid_specified = true;
0988 break;
0989 case Opt_gid:
0990 gid = make_kgid(current_user_ns(), result.uint_32);
0991 if (!gid_valid(gid))
0992 goto cifs_parse_mount_err;
0993 ctx->linux_gid = gid;
0994 ctx->gid_specified = true;
0995 break;
0996 case Opt_port:
0997 ctx->port = result.uint_32;
0998 break;
0999 case Opt_file_mode:
1000 ctx->file_mode = result.uint_32;
1001 break;
1002 case Opt_dirmode:
1003 ctx->dir_mode = result.uint_32;
1004 break;
1005 case Opt_min_enc_offload:
1006 ctx->min_offload = result.uint_32;
1007 break;
1008 case Opt_blocksize:
1009
1010
1011
1012
1013
1014
1015 if ((result.uint_32 < CIFS_MAX_MSGSIZE) ||
1016 (result.uint_32 > (4 * SMB3_DEFAULT_IOSIZE))) {
1017 cifs_errorf(fc, "%s: Invalid blocksize\n",
1018 __func__);
1019 goto cifs_parse_mount_err;
1020 }
1021 ctx->bsize = result.uint_32;
1022 ctx->got_bsize = true;
1023 break;
1024 case Opt_rasize:
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036 if ((result.uint_32 > (8 * SMB3_DEFAULT_IOSIZE)) ||
1037 (result.uint_32 < CIFS_DEFAULT_IOSIZE)) {
1038 cifs_errorf(fc, "%s: Invalid rasize %d vs. %d\n",
1039 __func__, result.uint_32, SMB3_DEFAULT_IOSIZE);
1040 goto cifs_parse_mount_err;
1041 }
1042 ctx->rasize = result.uint_32;
1043 break;
1044 case Opt_rsize:
1045 ctx->rsize = result.uint_32;
1046 ctx->got_rsize = true;
1047 break;
1048 case Opt_wsize:
1049 ctx->wsize = result.uint_32;
1050 ctx->got_wsize = true;
1051 break;
1052 case Opt_acregmax:
1053 ctx->acregmax = HZ * result.uint_32;
1054 if (ctx->acregmax > CIFS_MAX_ACTIMEO) {
1055 cifs_errorf(fc, "acregmax too large\n");
1056 goto cifs_parse_mount_err;
1057 }
1058 break;
1059 case Opt_acdirmax:
1060 ctx->acdirmax = HZ * result.uint_32;
1061 if (ctx->acdirmax > CIFS_MAX_ACTIMEO) {
1062 cifs_errorf(fc, "acdirmax too large\n");
1063 goto cifs_parse_mount_err;
1064 }
1065 break;
1066 case Opt_actimeo:
1067 if (HZ * result.uint_32 > CIFS_MAX_ACTIMEO) {
1068 cifs_errorf(fc, "timeout too large\n");
1069 goto cifs_parse_mount_err;
1070 }
1071 if ((ctx->acdirmax != CIFS_DEF_ACTIMEO) ||
1072 (ctx->acregmax != CIFS_DEF_ACTIMEO)) {
1073 cifs_errorf(fc, "actimeo ignored since acregmax or acdirmax specified\n");
1074 break;
1075 }
1076 ctx->acdirmax = ctx->acregmax = HZ * result.uint_32;
1077 break;
1078 case Opt_closetimeo:
1079 ctx->closetimeo = HZ * result.uint_32;
1080 if (ctx->closetimeo > SMB3_MAX_DCLOSETIMEO) {
1081 cifs_errorf(fc, "closetimeo too large\n");
1082 goto cifs_parse_mount_err;
1083 }
1084 break;
1085 case Opt_echo_interval:
1086 ctx->echo_interval = result.uint_32;
1087 break;
1088 case Opt_snapshot:
1089 ctx->snapshot_time = result.uint_64;
1090 break;
1091 case Opt_max_credits:
1092 if (result.uint_32 < 20 || result.uint_32 > 60000) {
1093 cifs_errorf(fc, "%s: Invalid max_credits value\n",
1094 __func__);
1095 goto cifs_parse_mount_err;
1096 }
1097 ctx->max_credits = result.uint_32;
1098 break;
1099 case Opt_max_channels:
1100 if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
1101 cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
1102 __func__, CIFS_MAX_CHANNELS);
1103 goto cifs_parse_mount_err;
1104 }
1105 ctx->max_channels = result.uint_32;
1106
1107 if (result.uint_32 > 1)
1108 ctx->multichannel = true;
1109 break;
1110 case Opt_handletimeout:
1111 ctx->handle_timeout = result.uint_32;
1112 if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
1113 cifs_errorf(fc, "Invalid handle cache timeout, longer than 16 minutes\n");
1114 goto cifs_parse_mount_err;
1115 }
1116 break;
1117 case Opt_source:
1118 kfree(ctx->UNC);
1119 ctx->UNC = NULL;
1120 switch (smb3_parse_devname(param->string, ctx)) {
1121 case 0:
1122 break;
1123 case -ENOMEM:
1124 cifs_errorf(fc, "Unable to allocate memory for devname\n");
1125 goto cifs_parse_mount_err;
1126 case -EINVAL:
1127 cifs_errorf(fc, "Malformed UNC in devname\n");
1128 goto cifs_parse_mount_err;
1129 default:
1130 cifs_errorf(fc, "Unknown error parsing devname\n");
1131 goto cifs_parse_mount_err;
1132 }
1133 ctx->source = kstrdup(param->string, GFP_KERNEL);
1134 if (ctx->source == NULL) {
1135 cifs_errorf(fc, "OOM when copying UNC string\n");
1136 goto cifs_parse_mount_err;
1137 }
1138 fc->source = kstrdup(param->string, GFP_KERNEL);
1139 if (fc->source == NULL) {
1140 cifs_errorf(fc, "OOM when copying UNC string\n");
1141 goto cifs_parse_mount_err;
1142 }
1143 break;
1144 case Opt_user:
1145 kfree(ctx->username);
1146 ctx->username = NULL;
1147 if (strlen(param->string) == 0) {
1148
1149 ctx->nullauth = 1;
1150 break;
1151 }
1152
1153 if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
1154 CIFS_MAX_USERNAME_LEN) {
1155 pr_warn("username too long\n");
1156 goto cifs_parse_mount_err;
1157 }
1158 ctx->username = kstrdup(param->string, GFP_KERNEL);
1159 if (ctx->username == NULL) {
1160 cifs_errorf(fc, "OOM when copying username string\n");
1161 goto cifs_parse_mount_err;
1162 }
1163 break;
1164 case Opt_pass:
1165 kfree(ctx->password);
1166 ctx->password = NULL;
1167 if (strlen(param->string) == 0)
1168 break;
1169
1170 ctx->password = kstrdup(param->string, GFP_KERNEL);
1171 if (ctx->password == NULL) {
1172 cifs_errorf(fc, "OOM when copying password string\n");
1173 goto cifs_parse_mount_err;
1174 }
1175 break;
1176 case Opt_ip:
1177 if (strlen(param->string) == 0) {
1178 ctx->got_ip = false;
1179 break;
1180 }
1181 if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
1182 param->string,
1183 strlen(param->string))) {
1184 pr_err("bad ip= option (%s)\n", param->string);
1185 goto cifs_parse_mount_err;
1186 }
1187 ctx->got_ip = true;
1188 break;
1189 case Opt_domain:
1190 if (strnlen(param->string, CIFS_MAX_DOMAINNAME_LEN)
1191 == CIFS_MAX_DOMAINNAME_LEN) {
1192 pr_warn("domain name too long\n");
1193 goto cifs_parse_mount_err;
1194 }
1195
1196 kfree(ctx->domainname);
1197 ctx->domainname = kstrdup(param->string, GFP_KERNEL);
1198 if (ctx->domainname == NULL) {
1199 cifs_errorf(fc, "OOM when copying domainname string\n");
1200 goto cifs_parse_mount_err;
1201 }
1202 cifs_dbg(FYI, "Domain name set\n");
1203 break;
1204 case Opt_srcaddr:
1205 if (!cifs_convert_address(
1206 (struct sockaddr *)&ctx->srcaddr,
1207 param->string, strlen(param->string))) {
1208 pr_warn("Could not parse srcaddr: %s\n",
1209 param->string);
1210 goto cifs_parse_mount_err;
1211 }
1212 break;
1213 case Opt_iocharset:
1214 if (strnlen(param->string, 1024) >= 65) {
1215 pr_warn("iocharset name too long\n");
1216 goto cifs_parse_mount_err;
1217 }
1218
1219 if (strncasecmp(param->string, "default", 7) != 0) {
1220 kfree(ctx->iocharset);
1221 ctx->iocharset = kstrdup(param->string, GFP_KERNEL);
1222 if (ctx->iocharset == NULL) {
1223 cifs_errorf(fc, "OOM when copying iocharset string\n");
1224 goto cifs_parse_mount_err;
1225 }
1226 }
1227
1228
1229
1230 cifs_dbg(FYI, "iocharset set to %s\n", ctx->iocharset);
1231 break;
1232 case Opt_netbiosname:
1233 memset(ctx->source_rfc1001_name, 0x20,
1234 RFC1001_NAME_LEN);
1235
1236
1237
1238
1239
1240 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1241
1242 if (param->string[i] == 0)
1243 break;
1244 ctx->source_rfc1001_name[i] = param->string[i];
1245 }
1246
1247
1248
1249 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1250 pr_warn("netbiosname longer than 15 truncated\n");
1251 break;
1252 case Opt_servern:
1253
1254 memset(ctx->target_rfc1001_name, 0x20,
1255 RFC1001_NAME_LEN_WITH_NULL);
1256
1257
1258
1259
1260
1261
1262 for (i = 0; i < 15; i++) {
1263 if (param->string[i] == 0)
1264 break;
1265 ctx->target_rfc1001_name[i] = param->string[i];
1266 }
1267
1268
1269 if (i == RFC1001_NAME_LEN && param->string[i] != 0)
1270 pr_warn("server netbiosname longer than 15 truncated\n");
1271 break;
1272 case Opt_ver:
1273
1274
1275 if (strncasecmp(param->string, "1", 1) == 0) {
1276 if (strlen(param->string) > 1) {
1277 pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
1278 param->string);
1279 goto cifs_parse_mount_err;
1280 }
1281
1282 break;
1283 }
1284
1285 pr_warn("Invalid mount helper version specified\n");
1286 goto cifs_parse_mount_err;
1287 case Opt_vers:
1288
1289 if (cifs_parse_smb_version(fc, param->string, ctx, is_smb3) != 0)
1290 goto cifs_parse_mount_err;
1291 ctx->got_version = true;
1292 break;
1293 case Opt_sec:
1294 if (cifs_parse_security_flavors(fc, param->string, ctx) != 0)
1295 goto cifs_parse_mount_err;
1296 break;
1297 case Opt_cache:
1298 if (cifs_parse_cache_flavor(fc, param->string, ctx) != 0)
1299 goto cifs_parse_mount_err;
1300 break;
1301 case Opt_witness:
1302 #ifndef CONFIG_CIFS_SWN_UPCALL
1303 cifs_errorf(fc, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
1304 goto cifs_parse_mount_err;
1305 #endif
1306 ctx->witness = true;
1307 pr_warn_once("Witness protocol support is experimental\n");
1308 break;
1309 case Opt_rootfs:
1310 #ifndef CONFIG_CIFS_ROOT
1311 cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
1312 goto cifs_parse_mount_err;
1313 #endif
1314 ctx->rootfs = true;
1315 break;
1316 case Opt_posixpaths:
1317 if (result.negated)
1318 ctx->posix_paths = 0;
1319 else
1320 ctx->posix_paths = 1;
1321 break;
1322 case Opt_unix:
1323 if (result.negated) {
1324 if (ctx->linux_ext == 1)
1325 pr_warn_once("conflicting posix mount options specified\n");
1326 ctx->linux_ext = 0;
1327 ctx->no_linux_ext = 1;
1328 } else {
1329 if (ctx->no_linux_ext == 1)
1330 pr_warn_once("conflicting posix mount options specified\n");
1331 ctx->linux_ext = 1;
1332 ctx->no_linux_ext = 0;
1333 }
1334 break;
1335 case Opt_nocase:
1336 ctx->nocase = 1;
1337 break;
1338 case Opt_brl:
1339 if (result.negated) {
1340
1341
1342
1343
1344
1345 if (ctx->file_mode ==
1346 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1347 ctx->file_mode = S_IALLUGO;
1348 ctx->nobrl = 1;
1349 } else
1350 ctx->nobrl = 0;
1351 break;
1352 case Opt_handlecache:
1353 if (result.negated)
1354 ctx->nohandlecache = 1;
1355 else
1356 ctx->nohandlecache = 0;
1357 break;
1358 case Opt_forcemandatorylock:
1359 ctx->mand_lock = 1;
1360 break;
1361 case Opt_setuids:
1362 ctx->setuids = result.negated;
1363 break;
1364 case Opt_intr:
1365 ctx->intr = !result.negated;
1366 break;
1367 case Opt_setuidfromacl:
1368 ctx->setuidfromacl = 1;
1369 break;
1370 case Opt_strictsync:
1371 ctx->nostrictsync = result.negated;
1372 break;
1373 case Opt_serverino:
1374 ctx->server_ino = !result.negated;
1375 break;
1376 case Opt_rwpidforward:
1377 ctx->rwpidforward = 1;
1378 break;
1379 case Opt_modesid:
1380 ctx->mode_ace = 1;
1381 break;
1382 case Opt_cifsacl:
1383 ctx->cifs_acl = !result.negated;
1384 break;
1385 case Opt_acl:
1386 ctx->no_psx_acl = result.negated;
1387 break;
1388 case Opt_locallease:
1389 ctx->local_lease = 1;
1390 break;
1391 case Opt_sign:
1392 ctx->sign = true;
1393 break;
1394 case Opt_ignore_signature:
1395 ctx->sign = true;
1396 ctx->ignore_signature = true;
1397 break;
1398 case Opt_seal:
1399
1400
1401
1402
1403
1404 ctx->seal = 1;
1405 break;
1406 case Opt_noac:
1407 pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
1408 break;
1409 case Opt_fsc:
1410 #ifndef CONFIG_CIFS_FSCACHE
1411 cifs_errorf(fc, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
1412 goto cifs_parse_mount_err;
1413 #endif
1414 ctx->fsc = true;
1415 break;
1416 case Opt_mfsymlinks:
1417 ctx->mfsymlinks = true;
1418 break;
1419 case Opt_multiuser:
1420 ctx->multiuser = true;
1421 break;
1422 case Opt_sloppy:
1423 ctx->sloppy = true;
1424 break;
1425 case Opt_nosharesock:
1426 ctx->nosharesock = true;
1427 break;
1428 case Opt_persistent:
1429 if (result.negated) {
1430 ctx->nopersistent = true;
1431 if (ctx->persistent) {
1432 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1433 goto cifs_parse_mount_err;
1434 }
1435 } else {
1436 ctx->persistent = true;
1437 if ((ctx->nopersistent) || (ctx->resilient)) {
1438 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1439 goto cifs_parse_mount_err;
1440 }
1441 }
1442 break;
1443 case Opt_resilient:
1444 if (result.negated) {
1445 ctx->resilient = false;
1446 } else {
1447 ctx->resilient = true;
1448 if (ctx->persistent) {
1449 cifs_errorf(fc, "persistenthandles mount options conflict\n");
1450 goto cifs_parse_mount_err;
1451 }
1452 }
1453 break;
1454 case Opt_tcp_nodelay:
1455
1456 if (result.negated)
1457 ctx->sockopt_tcp_nodelay = false;
1458 else
1459 ctx->sockopt_tcp_nodelay = true;
1460 break;
1461 case Opt_domainauto:
1462 ctx->domainauto = true;
1463 break;
1464 case Opt_rdma:
1465 ctx->rdma = true;
1466 break;
1467 }
1468
1469
1470 return 0;
1471
1472 cifs_parse_mount_err:
1473 return -EINVAL;
1474 }
1475
1476 int smb3_init_fs_context(struct fs_context *fc)
1477 {
1478 struct smb3_fs_context *ctx;
1479 char *nodename = utsname()->nodename;
1480 int i;
1481
1482 ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
1483 if (unlikely(!ctx))
1484 return -ENOMEM;
1485
1486 strscpy(ctx->workstation_name, nodename, sizeof(ctx->workstation_name));
1487
1488
1489
1490
1491
1492
1493 memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
1494 for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
1495 ctx->source_rfc1001_name[i] = toupper(nodename[i]);
1496
1497 ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
1498
1499
1500
1501
1502 ctx->target_rfc1001_name[0] = 0;
1503 ctx->cred_uid = current_uid();
1504 ctx->linux_uid = current_uid();
1505 ctx->linux_gid = current_gid();
1506
1507 ctx->bsize = CIFS_DEFAULT_IOSIZE;
1508 ctx->rasize = 0;
1509
1510
1511
1512
1513
1514
1515
1516 ctx->remap = true;
1517
1518
1519 ctx->dir_mode = ctx->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
1520
1521
1522
1523 ctx->posix_paths = 1;
1524
1525 ctx->server_ino = 1;
1526
1527
1528 ctx->strict_io = true;
1529
1530 ctx->acregmax = CIFS_DEF_ACTIMEO;
1531 ctx->acdirmax = CIFS_DEF_ACTIMEO;
1532 ctx->closetimeo = SMB3_DEF_DCLOSETIMEO;
1533
1534
1535 ctx->handle_timeout = 0;
1536
1537
1538 ctx->ops = &smb30_operations;
1539 ctx->vals = &smbdefault_values;
1540
1541 ctx->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
1542
1543
1544 ctx->multichannel = false;
1545 ctx->max_channels = 1;
1546
1547 ctx->backupuid_specified = false;
1548 ctx->backupgid_specified = false;
1549
1550
1551
1552
1553
1554
1555
1556
1557 fc->fs_private = ctx;
1558 fc->ops = &smb3_fs_context_ops;
1559 return 0;
1560 }
1561
1562 void
1563 smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
1564 {
1565 if (ctx == NULL)
1566 return;
1567
1568
1569
1570
1571 kfree(ctx->mount_options);
1572 ctx->mount_options = NULL;
1573 kfree(ctx->username);
1574 ctx->username = NULL;
1575 kfree_sensitive(ctx->password);
1576 ctx->password = NULL;
1577 kfree(ctx->server_hostname);
1578 ctx->server_hostname = NULL;
1579 kfree(ctx->UNC);
1580 ctx->UNC = NULL;
1581 kfree(ctx->source);
1582 ctx->source = NULL;
1583 kfree(ctx->domainname);
1584 ctx->domainname = NULL;
1585 kfree(ctx->nodename);
1586 ctx->nodename = NULL;
1587 kfree(ctx->iocharset);
1588 ctx->iocharset = NULL;
1589 kfree(ctx->prepath);
1590 ctx->prepath = NULL;
1591 }
1592
1593 void
1594 smb3_cleanup_fs_context(struct smb3_fs_context *ctx)
1595 {
1596 if (!ctx)
1597 return;
1598 smb3_cleanup_fs_context_contents(ctx);
1599 kfree(ctx);
1600 }
1601
1602 void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
1603 {
1604 struct smb3_fs_context *ctx = cifs_sb->ctx;
1605
1606 if (ctx->nodfs)
1607 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS;
1608 else
1609 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_DFS;
1610
1611 if (ctx->noperm)
1612 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
1613 else
1614 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_PERM;
1615
1616 if (ctx->setuids)
1617 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
1618 else
1619 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SET_UID;
1620
1621 if (ctx->setuidfromacl)
1622 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL;
1623 else
1624 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UID_FROM_ACL;
1625
1626 if (ctx->server_ino)
1627 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
1628 else
1629 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
1630
1631 if (ctx->remap)
1632 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR;
1633 else
1634 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SFM_CHR;
1635
1636 if (ctx->sfu_remap)
1637 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
1638 else
1639 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SPECIAL_CHR;
1640
1641 if (ctx->no_xattr)
1642 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
1643 else
1644 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_XATTR;
1645
1646 if (ctx->sfu_emul)
1647 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
1648 else
1649 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UNX_EMUL;
1650
1651 if (ctx->nobrl)
1652 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
1653 else
1654 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_BRL;
1655
1656 if (ctx->nohandlecache)
1657 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE;
1658 else
1659 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_HANDLE_CACHE;
1660
1661 if (ctx->nostrictsync)
1662 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
1663 else
1664 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOSSYNC;
1665
1666 if (ctx->mand_lock)
1667 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
1668 else
1669 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOPOSIXBRL;
1670
1671 if (ctx->rwpidforward)
1672 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
1673 else
1674 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_RWPIDFORWARD;
1675
1676 if (ctx->mode_ace)
1677 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MODE_FROM_SID;
1678 else
1679 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MODE_FROM_SID;
1680
1681 if (ctx->cifs_acl)
1682 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
1683 else
1684 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_ACL;
1685
1686 if (ctx->backupuid_specified)
1687 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
1688 else
1689 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPUID;
1690
1691 if (ctx->backupgid_specified)
1692 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
1693 else
1694 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPGID;
1695
1696 if (ctx->override_uid)
1697 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
1698 else
1699 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_UID;
1700
1701 if (ctx->override_gid)
1702 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
1703 else
1704 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_GID;
1705
1706 if (ctx->dynperm)
1707 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
1708 else
1709 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DYNPERM;
1710
1711 if (ctx->fsc)
1712 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
1713 else
1714 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_FSCACHE;
1715
1716 if (ctx->multiuser)
1717 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
1718 CIFS_MOUNT_NO_PERM);
1719 else
1720 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MULTIUSER;
1721
1722
1723 if (ctx->strict_io)
1724 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
1725 else
1726 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_STRICT_IO;
1727
1728 if (ctx->direct_io)
1729 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
1730 else
1731 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DIRECT_IO;
1732
1733 if (ctx->mfsymlinks)
1734 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
1735 else
1736 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MF_SYMLINKS;
1737 if (ctx->mfsymlinks) {
1738 if (ctx->sfu_emul) {
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750 cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
1751 }
1752 }
1753 cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SHUTDOWN;
1754
1755 return;
1756 }