PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/fs/cifs/fs_context.c

https://github.com/kvaneesh/linux
C | 1676 lines | 1611 code | 27 blank | 38 comment | 20 complexity | 43084d2a56a1879d53b3d10ecbb78775 MD5 | raw file
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2020, Microsoft Corporation.
  4. *
  5. * Author(s): Steve French <stfrench@microsoft.com>
  6. * David Howells <dhowells@redhat.com>
  7. */
  8. /*
  9. #include <linux/module.h>
  10. #include <linux/nsproxy.h>
  11. #include <linux/slab.h>
  12. #include <linux/magic.h>
  13. #include <linux/security.h>
  14. #include <net/net_namespace.h>
  15. #ifdef CONFIG_CIFS_DFS_UPCALL
  16. #include "dfs_cache.h"
  17. #endif
  18. */
  19. #include <linux/ctype.h>
  20. #include <linux/fs_context.h>
  21. #include <linux/fs_parser.h>
  22. #include <linux/fs.h>
  23. #include <linux/mount.h>
  24. #include <linux/parser.h>
  25. #include <linux/utsname.h>
  26. #include "cifsfs.h"
  27. #include "cifspdu.h"
  28. #include "cifsglob.h"
  29. #include "cifsproto.h"
  30. #include "cifs_unicode.h"
  31. #include "cifs_debug.h"
  32. #include "cifs_fs_sb.h"
  33. #include "ntlmssp.h"
  34. #include "nterr.h"
  35. #include "rfc1002pdu.h"
  36. #include "fs_context.h"
  37. static const match_table_t cifs_smb_version_tokens = {
  38. { Smb_1, SMB1_VERSION_STRING },
  39. { Smb_20, SMB20_VERSION_STRING},
  40. { Smb_21, SMB21_VERSION_STRING },
  41. { Smb_30, SMB30_VERSION_STRING },
  42. { Smb_302, SMB302_VERSION_STRING },
  43. { Smb_302, ALT_SMB302_VERSION_STRING },
  44. { Smb_311, SMB311_VERSION_STRING },
  45. { Smb_311, ALT_SMB311_VERSION_STRING },
  46. { Smb_3any, SMB3ANY_VERSION_STRING },
  47. { Smb_default, SMBDEFAULT_VERSION_STRING },
  48. { Smb_version_err, NULL }
  49. };
  50. static const match_table_t cifs_secflavor_tokens = {
  51. { Opt_sec_krb5, "krb5" },
  52. { Opt_sec_krb5i, "krb5i" },
  53. { Opt_sec_krb5p, "krb5p" },
  54. { Opt_sec_ntlmsspi, "ntlmsspi" },
  55. { Opt_sec_ntlmssp, "ntlmssp" },
  56. { Opt_sec_ntlmv2, "nontlm" },
  57. { Opt_sec_ntlmv2, "ntlmv2" },
  58. { Opt_sec_ntlmv2i, "ntlmv2i" },
  59. { Opt_sec_none, "none" },
  60. { Opt_sec_err, NULL }
  61. };
  62. const struct fs_parameter_spec smb3_fs_parameters[] = {
  63. /* Mount options that take no arguments */
  64. fsparam_flag_no("user_xattr", Opt_user_xattr),
  65. fsparam_flag_no("forceuid", Opt_forceuid),
  66. fsparam_flag_no("multichannel", Opt_multichannel),
  67. fsparam_flag_no("forcegid", Opt_forcegid),
  68. fsparam_flag("noblocksend", Opt_noblocksend),
  69. fsparam_flag("noautotune", Opt_noautotune),
  70. fsparam_flag("nolease", Opt_nolease),
  71. fsparam_flag_no("hard", Opt_hard),
  72. fsparam_flag_no("soft", Opt_soft),
  73. fsparam_flag_no("perm", Opt_perm),
  74. fsparam_flag("nodelete", Opt_nodelete),
  75. fsparam_flag_no("mapposix", Opt_mapposix),
  76. fsparam_flag("mapchars", Opt_mapchars),
  77. fsparam_flag("nomapchars", Opt_nomapchars),
  78. fsparam_flag_no("sfu", Opt_sfu),
  79. fsparam_flag("nodfs", Opt_nodfs),
  80. fsparam_flag_no("posixpaths", Opt_posixpaths),
  81. fsparam_flag_no("unix", Opt_unix),
  82. fsparam_flag_no("linux", Opt_unix),
  83. fsparam_flag_no("posix", Opt_unix),
  84. fsparam_flag("nocase", Opt_nocase),
  85. fsparam_flag("ignorecase", Opt_nocase),
  86. fsparam_flag_no("brl", Opt_brl),
  87. fsparam_flag_no("handlecache", Opt_handlecache),
  88. fsparam_flag("forcemandatorylock", Opt_forcemandatorylock),
  89. fsparam_flag("forcemand", Opt_forcemandatorylock),
  90. fsparam_flag("setuidfromacl", Opt_setuidfromacl),
  91. fsparam_flag("idsfromsid", Opt_setuidfromacl),
  92. fsparam_flag_no("setuids", Opt_setuids),
  93. fsparam_flag_no("dynperm", Opt_dynperm),
  94. fsparam_flag_no("intr", Opt_intr),
  95. fsparam_flag_no("strictsync", Opt_strictsync),
  96. fsparam_flag_no("serverino", Opt_serverino),
  97. fsparam_flag("rwpidforward", Opt_rwpidforward),
  98. fsparam_flag("cifsacl", Opt_cifsacl),
  99. fsparam_flag_no("acl", Opt_acl),
  100. fsparam_flag("locallease", Opt_locallease),
  101. fsparam_flag("sign", Opt_sign),
  102. fsparam_flag("ignore_signature", Opt_ignore_signature),
  103. fsparam_flag("signloosely", Opt_ignore_signature),
  104. fsparam_flag("seal", Opt_seal),
  105. fsparam_flag("noac", Opt_noac),
  106. fsparam_flag("fsc", Opt_fsc),
  107. fsparam_flag("mfsymlinks", Opt_mfsymlinks),
  108. fsparam_flag("multiuser", Opt_multiuser),
  109. fsparam_flag("sloppy", Opt_sloppy),
  110. fsparam_flag("nosharesock", Opt_nosharesock),
  111. fsparam_flag_no("persistenthandles", Opt_persistent),
  112. fsparam_flag_no("resilienthandles", Opt_resilient),
  113. fsparam_flag("domainauto", Opt_domainauto),
  114. fsparam_flag("rdma", Opt_rdma),
  115. fsparam_flag("modesid", Opt_modesid),
  116. fsparam_flag("modefromsid", Opt_modesid),
  117. fsparam_flag("rootfs", Opt_rootfs),
  118. fsparam_flag("compress", Opt_compress),
  119. fsparam_flag("witness", Opt_witness),
  120. /* Mount options which take numeric value */
  121. fsparam_u32("backupuid", Opt_backupuid),
  122. fsparam_u32("backupgid", Opt_backupgid),
  123. fsparam_u32("uid", Opt_uid),
  124. fsparam_u32("cruid", Opt_cruid),
  125. fsparam_u32("gid", Opt_gid),
  126. fsparam_u32("file_mode", Opt_file_mode),
  127. fsparam_u32("dirmode", Opt_dirmode),
  128. fsparam_u32("dir_mode", Opt_dirmode),
  129. fsparam_u32("port", Opt_port),
  130. fsparam_u32("min_enc_offload", Opt_min_enc_offload),
  131. fsparam_u32("esize", Opt_min_enc_offload),
  132. fsparam_u32("bsize", Opt_blocksize),
  133. fsparam_u32("rasize", Opt_rasize),
  134. fsparam_u32("rsize", Opt_rsize),
  135. fsparam_u32("wsize", Opt_wsize),
  136. fsparam_u32("actimeo", Opt_actimeo),
  137. fsparam_u32("acdirmax", Opt_acdirmax),
  138. fsparam_u32("acregmax", Opt_acregmax),
  139. fsparam_u32("echo_interval", Opt_echo_interval),
  140. fsparam_u32("max_credits", Opt_max_credits),
  141. fsparam_u32("handletimeout", Opt_handletimeout),
  142. fsparam_u32("snapshot", Opt_snapshot),
  143. fsparam_u32("max_channels", Opt_max_channels),
  144. /* Mount options which take string value */
  145. fsparam_string("source", Opt_source),
  146. fsparam_string("user", Opt_user),
  147. fsparam_string("username", Opt_user),
  148. fsparam_string("pass", Opt_pass),
  149. fsparam_string("password", Opt_pass),
  150. fsparam_string("ip", Opt_ip),
  151. fsparam_string("addr", Opt_ip),
  152. fsparam_string("domain", Opt_domain),
  153. fsparam_string("dom", Opt_domain),
  154. fsparam_string("srcaddr", Opt_srcaddr),
  155. fsparam_string("iocharset", Opt_iocharset),
  156. fsparam_string("netbiosname", Opt_netbiosname),
  157. fsparam_string("servern", Opt_servern),
  158. fsparam_string("ver", Opt_ver),
  159. fsparam_string("vers", Opt_vers),
  160. fsparam_string("sec", Opt_sec),
  161. fsparam_string("cache", Opt_cache),
  162. /* Arguments that should be ignored */
  163. fsparam_flag("guest", Opt_ignore),
  164. fsparam_flag("noatime", Opt_ignore),
  165. fsparam_flag("relatime", Opt_ignore),
  166. fsparam_flag("_netdev", Opt_ignore),
  167. fsparam_flag_no("suid", Opt_ignore),
  168. fsparam_flag_no("exec", Opt_ignore),
  169. fsparam_flag_no("dev", Opt_ignore),
  170. fsparam_flag_no("mand", Opt_ignore),
  171. fsparam_flag_no("auto", Opt_ignore),
  172. fsparam_string("cred", Opt_ignore),
  173. fsparam_string("credentials", Opt_ignore),
  174. /*
  175. * UNC and prefixpath is now extracted from Opt_source
  176. * in the new mount API so we can just ignore them going forward.
  177. */
  178. fsparam_string("unc", Opt_ignore),
  179. fsparam_string("prefixpath", Opt_ignore),
  180. {}
  181. };
  182. static int
  183. cifs_parse_security_flavors(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
  184. {
  185. substring_t args[MAX_OPT_ARGS];
  186. /*
  187. * With mount options, the last one should win. Reset any existing
  188. * settings back to default.
  189. */
  190. ctx->sectype = Unspecified;
  191. ctx->sign = false;
  192. switch (match_token(value, cifs_secflavor_tokens, args)) {
  193. case Opt_sec_krb5p:
  194. cifs_errorf(fc, "sec=krb5p is not supported!\n");
  195. return 1;
  196. case Opt_sec_krb5i:
  197. ctx->sign = true;
  198. fallthrough;
  199. case Opt_sec_krb5:
  200. ctx->sectype = Kerberos;
  201. break;
  202. case Opt_sec_ntlmsspi:
  203. ctx->sign = true;
  204. fallthrough;
  205. case Opt_sec_ntlmssp:
  206. ctx->sectype = RawNTLMSSP;
  207. break;
  208. case Opt_sec_ntlmv2i:
  209. ctx->sign = true;
  210. fallthrough;
  211. case Opt_sec_ntlmv2:
  212. ctx->sectype = NTLMv2;
  213. break;
  214. case Opt_sec_none:
  215. ctx->nullauth = 1;
  216. break;
  217. default:
  218. cifs_errorf(fc, "bad security option: %s\n", value);
  219. return 1;
  220. }
  221. return 0;
  222. }
  223. static const match_table_t cifs_cacheflavor_tokens = {
  224. { Opt_cache_loose, "loose" },
  225. { Opt_cache_strict, "strict" },
  226. { Opt_cache_none, "none" },
  227. { Opt_cache_ro, "ro" },
  228. { Opt_cache_rw, "singleclient" },
  229. { Opt_cache_err, NULL }
  230. };
  231. static int
  232. cifs_parse_cache_flavor(struct fs_context *fc, char *value, struct smb3_fs_context *ctx)
  233. {
  234. substring_t args[MAX_OPT_ARGS];
  235. switch (match_token(value, cifs_cacheflavor_tokens, args)) {
  236. case Opt_cache_loose:
  237. ctx->direct_io = false;
  238. ctx->strict_io = false;
  239. ctx->cache_ro = false;
  240. ctx->cache_rw = false;
  241. break;
  242. case Opt_cache_strict:
  243. ctx->direct_io = false;
  244. ctx->strict_io = true;
  245. ctx->cache_ro = false;
  246. ctx->cache_rw = false;
  247. break;
  248. case Opt_cache_none:
  249. ctx->direct_io = true;
  250. ctx->strict_io = false;
  251. ctx->cache_ro = false;
  252. ctx->cache_rw = false;
  253. break;
  254. case Opt_cache_ro:
  255. ctx->direct_io = false;
  256. ctx->strict_io = false;
  257. ctx->cache_ro = true;
  258. ctx->cache_rw = false;
  259. break;
  260. case Opt_cache_rw:
  261. ctx->direct_io = false;
  262. ctx->strict_io = false;
  263. ctx->cache_ro = false;
  264. ctx->cache_rw = true;
  265. break;
  266. default:
  267. cifs_errorf(fc, "bad cache= option: %s\n", value);
  268. return 1;
  269. }
  270. return 0;
  271. }
  272. #define DUP_CTX_STR(field) \
  273. do { \
  274. if (ctx->field) { \
  275. new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
  276. if (new_ctx->field == NULL) { \
  277. smb3_cleanup_fs_context_contents(new_ctx); \
  278. return -ENOMEM; \
  279. } \
  280. } \
  281. } while (0)
  282. int
  283. smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
  284. {
  285. memcpy(new_ctx, ctx, sizeof(*ctx));
  286. new_ctx->prepath = NULL;
  287. new_ctx->mount_options = NULL;
  288. new_ctx->nodename = NULL;
  289. new_ctx->username = NULL;
  290. new_ctx->password = NULL;
  291. new_ctx->domainname = NULL;
  292. new_ctx->UNC = NULL;
  293. new_ctx->source = NULL;
  294. new_ctx->iocharset = NULL;
  295. /*
  296. * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
  297. */
  298. DUP_CTX_STR(prepath);
  299. DUP_CTX_STR(mount_options);
  300. DUP_CTX_STR(username);
  301. DUP_CTX_STR(password);
  302. DUP_CTX_STR(UNC);
  303. DUP_CTX_STR(source);
  304. DUP_CTX_STR(domainname);
  305. DUP_CTX_STR(nodename);
  306. DUP_CTX_STR(iocharset);
  307. return 0;
  308. }
  309. static int
  310. cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_context *ctx, bool is_smb3)
  311. {
  312. substring_t args[MAX_OPT_ARGS];
  313. switch (match_token(value, cifs_smb_version_tokens, args)) {
  314. #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
  315. case Smb_1:
  316. if (disable_legacy_dialects) {
  317. cifs_errorf(fc, "mount with legacy dialect disabled\n");
  318. return 1;
  319. }
  320. if (is_smb3) {
  321. cifs_errorf(fc, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
  322. return 1;
  323. }
  324. cifs_errorf(fc, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
  325. ctx->ops = &smb1_operations;
  326. ctx->vals = &smb1_values;
  327. break;
  328. case Smb_20:
  329. if (disable_legacy_dialects) {
  330. cifs_errorf(fc, "mount with legacy dialect disabled\n");
  331. return 1;
  332. }
  333. if (is_smb3) {
  334. cifs_errorf(fc, "vers=2.0 not permitted when mounting with smb3\n");
  335. return 1;
  336. }
  337. ctx->ops = &smb20_operations;
  338. ctx->vals = &smb20_values;
  339. break;
  340. #else
  341. case Smb_1:
  342. cifs_errorf(fc, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
  343. return 1;
  344. case Smb_20:
  345. cifs_errorf(fc, "vers=2.0 mount not permitted when legacy dialects disabled\n");
  346. return 1;
  347. #endif /* CIFS_ALLOW_INSECURE_LEGACY */
  348. case Smb_21:
  349. ctx->ops = &smb21_operations;
  350. ctx->vals = &smb21_values;
  351. break;
  352. case Smb_30:
  353. ctx->ops = &smb30_operations;
  354. ctx->vals = &smb30_values;
  355. break;
  356. case Smb_302:
  357. ctx->ops = &smb30_operations; /* currently identical with 3.0 */
  358. ctx->vals = &smb302_values;
  359. break;
  360. case Smb_311:
  361. ctx->ops = &smb311_operations;
  362. ctx->vals = &smb311_values;
  363. break;
  364. case Smb_3any:
  365. ctx->ops = &smb30_operations; /* currently identical with 3.0 */
  366. ctx->vals = &smb3any_values;
  367. break;
  368. case Smb_default:
  369. ctx->ops = &smb30_operations;
  370. ctx->vals = &smbdefault_values;
  371. break;
  372. default:
  373. cifs_errorf(fc, "Unknown vers= option specified: %s\n", value);
  374. return 1;
  375. }
  376. return 0;
  377. }
  378. int smb3_parse_opt(const char *options, const char *key, char **val)
  379. {
  380. int rc = -ENOENT;
  381. char *opts, *orig, *p;
  382. orig = opts = kstrdup(options, GFP_KERNEL);
  383. if (!opts)
  384. return -ENOMEM;
  385. while ((p = strsep(&opts, ","))) {
  386. char *nval;
  387. if (!*p)
  388. continue;
  389. if (strncasecmp(p, key, strlen(key)))
  390. continue;
  391. nval = strchr(p, '=');
  392. if (nval) {
  393. if (nval == p)
  394. continue;
  395. *nval++ = 0;
  396. *val = kstrdup(nval, GFP_KERNEL);
  397. rc = !*val ? -ENOMEM : 0;
  398. goto out;
  399. }
  400. }
  401. out:
  402. kfree(orig);
  403. return rc;
  404. }
  405. /*
  406. * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
  407. * fields with the result. Returns 0 on success and an error otherwise
  408. * (e.g. ENOMEM or EINVAL)
  409. */
  410. int
  411. smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
  412. {
  413. char *pos;
  414. const char *delims = "/\\";
  415. size_t len;
  416. if (unlikely(!devname || !*devname)) {
  417. cifs_dbg(VFS, "Device name not specified\n");
  418. return -EINVAL;
  419. }
  420. /* make sure we have a valid UNC double delimiter prefix */
  421. len = strspn(devname, delims);
  422. if (len != 2)
  423. return -EINVAL;
  424. /* find delimiter between host and sharename */
  425. pos = strpbrk(devname + 2, delims);
  426. if (!pos)
  427. return -EINVAL;
  428. /* skip past delimiter */
  429. ++pos;
  430. /* now go until next delimiter or end of string */
  431. len = strcspn(pos, delims);
  432. /* move "pos" up to delimiter or NULL */
  433. pos += len;
  434. kfree(ctx->UNC);
  435. ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
  436. if (!ctx->UNC)
  437. return -ENOMEM;
  438. convert_delimiter(ctx->UNC, '\\');
  439. /* skip any delimiter */
  440. if (*pos == '/' || *pos == '\\')
  441. pos++;
  442. kfree(ctx->prepath);
  443. ctx->prepath = NULL;
  444. /* If pos is NULL then no prepath */
  445. if (!*pos)
  446. return 0;
  447. ctx->prepath = kstrdup(pos, GFP_KERNEL);
  448. if (!ctx->prepath)
  449. return -ENOMEM;
  450. return 0;
  451. }
  452. static void smb3_fs_context_free(struct fs_context *fc);
  453. static int smb3_fs_context_parse_param(struct fs_context *fc,
  454. struct fs_parameter *param);
  455. static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
  456. void *data);
  457. static int smb3_get_tree(struct fs_context *fc);
  458. static int smb3_reconfigure(struct fs_context *fc);
  459. static const struct fs_context_operations smb3_fs_context_ops = {
  460. .free = smb3_fs_context_free,
  461. .parse_param = smb3_fs_context_parse_param,
  462. .parse_monolithic = smb3_fs_context_parse_monolithic,
  463. .get_tree = smb3_get_tree,
  464. .reconfigure = smb3_reconfigure,
  465. };
  466. /*
  467. * Parse a monolithic block of data from sys_mount().
  468. * smb3_fs_context_parse_monolithic - Parse key[=val][,key[=val]]* mount data
  469. * @ctx: The superblock configuration to fill in.
  470. * @data: The data to parse
  471. *
  472. * Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
  473. * called from the ->monolithic_mount_data() fs_context operation.
  474. *
  475. * Returns 0 on success or the error returned by the ->parse_option() fs_context
  476. * operation on failure.
  477. */
  478. static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
  479. void *data)
  480. {
  481. struct smb3_fs_context *ctx = smb3_fc2context(fc);
  482. char *options = data, *key;
  483. int ret = 0;
  484. if (!options)
  485. return 0;
  486. ctx->mount_options = kstrdup(data, GFP_KERNEL);
  487. if (ctx->mount_options == NULL)
  488. return -ENOMEM;
  489. ret = security_sb_eat_lsm_opts(options, &fc->security);
  490. if (ret)
  491. return ret;
  492. /* BB Need to add support for sep= here TBD */
  493. while ((key = strsep(&options, ",")) != NULL) {
  494. size_t len;
  495. char *value;
  496. if (*key == 0)
  497. break;
  498. /* Check if following character is the deliminator If yes,
  499. * we have encountered a double deliminator reset the NULL
  500. * character to the deliminator
  501. */
  502. while (options && options[0] == ',') {
  503. len = strlen(key);
  504. strcpy(key + len, options);
  505. options = strchr(options, ',');
  506. if (options)
  507. *options++ = 0;
  508. }
  509. len = 0;
  510. value = strchr(key, '=');
  511. if (value) {
  512. if (value == key)
  513. continue;
  514. *value++ = 0;
  515. len = strlen(value);
  516. }
  517. ret = vfs_parse_fs_string(fc, key, value, len);
  518. if (ret < 0)
  519. break;
  520. }
  521. return ret;
  522. }
  523. /*
  524. * Validate the preparsed information in the config.
  525. */
  526. static int smb3_fs_context_validate(struct fs_context *fc)
  527. {
  528. struct smb3_fs_context *ctx = smb3_fc2context(fc);
  529. if (ctx->rdma && ctx->vals->protocol_id < SMB30_PROT_ID) {
  530. cifs_errorf(fc, "SMB Direct requires Version >=3.0\n");
  531. return -EOPNOTSUPP;
  532. }
  533. #ifndef CONFIG_KEYS
  534. /* Muliuser mounts require CONFIG_KEYS support */
  535. if (ctx->multiuser) {
  536. cifs_errorf(fc, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n");
  537. return -1;
  538. }
  539. #endif
  540. if (ctx->got_version == false)
  541. 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");
  542. if (!ctx->UNC) {
  543. cifs_errorf(fc, "CIFS mount error: No usable UNC path provided in device string!\n");
  544. return -1;
  545. }
  546. /* make sure UNC has a share name */
  547. if (strlen(ctx->UNC) < 3 || !strchr(ctx->UNC + 3, '\\')) {
  548. cifs_errorf(fc, "Malformed UNC. Unable to find share name.\n");
  549. return -ENOENT;
  550. }
  551. if (!ctx->got_ip) {
  552. int len;
  553. const char *slash;
  554. /* No ip= option specified? Try to get it from UNC */
  555. /* Use the address part of the UNC. */
  556. slash = strchr(&ctx->UNC[2], '\\');
  557. len = slash - &ctx->UNC[2];
  558. if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
  559. &ctx->UNC[2], len)) {
  560. pr_err("Unable to determine destination address\n");
  561. return -EHOSTUNREACH;
  562. }
  563. }
  564. /* set the port that we got earlier */
  565. cifs_set_port((struct sockaddr *)&ctx->dstaddr, ctx->port);
  566. if (ctx->override_uid && !ctx->uid_specified) {
  567. ctx->override_uid = 0;
  568. pr_notice("ignoring forceuid mount option specified with no uid= option\n");
  569. }
  570. if (ctx->override_gid && !ctx->gid_specified) {
  571. ctx->override_gid = 0;
  572. pr_notice("ignoring forcegid mount option specified with no gid= option\n");
  573. }
  574. return 0;
  575. }
  576. static int smb3_get_tree_common(struct fs_context *fc)
  577. {
  578. struct smb3_fs_context *ctx = smb3_fc2context(fc);
  579. struct dentry *root;
  580. int rc = 0;
  581. root = cifs_smb3_do_mount(fc->fs_type, 0, ctx);
  582. if (IS_ERR(root))
  583. return PTR_ERR(root);
  584. fc->root = root;
  585. return rc;
  586. }
  587. /*
  588. * Create an SMB3 superblock from the parameters passed.
  589. */
  590. static int smb3_get_tree(struct fs_context *fc)
  591. {
  592. int err = smb3_fs_context_validate(fc);
  593. if (err)
  594. return err;
  595. return smb3_get_tree_common(fc);
  596. }
  597. static void smb3_fs_context_free(struct fs_context *fc)
  598. {
  599. struct smb3_fs_context *ctx = smb3_fc2context(fc);
  600. smb3_cleanup_fs_context(ctx);
  601. }
  602. /*
  603. * Compare the old and new proposed context during reconfigure
  604. * and check if the changes are compatible.
  605. */
  606. static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
  607. struct smb3_fs_context *new_ctx,
  608. struct smb3_fs_context *old_ctx)
  609. {
  610. if (new_ctx->posix_paths != old_ctx->posix_paths) {
  611. cifs_errorf(fc, "can not change posixpaths during remount\n");
  612. return -EINVAL;
  613. }
  614. if (new_ctx->sectype != old_ctx->sectype) {
  615. cifs_errorf(fc, "can not change sec during remount\n");
  616. return -EINVAL;
  617. }
  618. if (new_ctx->multiuser != old_ctx->multiuser) {
  619. cifs_errorf(fc, "can not change multiuser during remount\n");
  620. return -EINVAL;
  621. }
  622. if (new_ctx->UNC &&
  623. (!old_ctx->UNC || strcmp(new_ctx->UNC, old_ctx->UNC))) {
  624. cifs_errorf(fc, "can not change UNC during remount\n");
  625. return -EINVAL;
  626. }
  627. if (new_ctx->username &&
  628. (!old_ctx->username || strcmp(new_ctx->username, old_ctx->username))) {
  629. cifs_errorf(fc, "can not change username during remount\n");
  630. return -EINVAL;
  631. }
  632. if (new_ctx->password &&
  633. (!old_ctx->password || strcmp(new_ctx->password, old_ctx->password))) {
  634. cifs_errorf(fc, "can not change password during remount\n");
  635. return -EINVAL;
  636. }
  637. if (new_ctx->domainname &&
  638. (!old_ctx->domainname || strcmp(new_ctx->domainname, old_ctx->domainname))) {
  639. cifs_errorf(fc, "can not change domainname during remount\n");
  640. return -EINVAL;
  641. }
  642. if (new_ctx->nodename &&
  643. (!old_ctx->nodename || strcmp(new_ctx->nodename, old_ctx->nodename))) {
  644. cifs_errorf(fc, "can not change nodename during remount\n");
  645. return -EINVAL;
  646. }
  647. if (new_ctx->iocharset &&
  648. (!old_ctx->iocharset || strcmp(new_ctx->iocharset, old_ctx->iocharset))) {
  649. cifs_errorf(fc, "can not change iocharset during remount\n");
  650. return -EINVAL;
  651. }
  652. return 0;
  653. }
  654. #define STEAL_STRING(cifs_sb, ctx, field) \
  655. do { \
  656. kfree(ctx->field); \
  657. ctx->field = cifs_sb->ctx->field; \
  658. cifs_sb->ctx->field = NULL; \
  659. } while (0)
  660. static int smb3_reconfigure(struct fs_context *fc)
  661. {
  662. struct smb3_fs_context *ctx = smb3_fc2context(fc);
  663. struct dentry *root = fc->root;
  664. struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
  665. int rc;
  666. rc = smb3_verify_reconfigure_ctx(fc, ctx, cifs_sb->ctx);
  667. if (rc)
  668. return rc;
  669. /*
  670. * We can not change UNC/username/password/domainname/nodename/iocharset
  671. * during reconnect so ignore what we have in the new context and
  672. * just use what we already have in cifs_sb->ctx.
  673. */
  674. STEAL_STRING(cifs_sb, ctx, UNC);
  675. STEAL_STRING(cifs_sb, ctx, source);
  676. STEAL_STRING(cifs_sb, ctx, username);
  677. STEAL_STRING(cifs_sb, ctx, password);
  678. STEAL_STRING(cifs_sb, ctx, domainname);
  679. STEAL_STRING(cifs_sb, ctx, nodename);
  680. STEAL_STRING(cifs_sb, ctx, iocharset);
  681. /* if rsize or wsize not passed in on remount, use previous values */
  682. if (ctx->rsize == 0)
  683. ctx->rsize = cifs_sb->ctx->rsize;
  684. if (ctx->wsize == 0)
  685. ctx->wsize = cifs_sb->ctx->wsize;
  686. smb3_cleanup_fs_context_contents(cifs_sb->ctx);
  687. rc = smb3_fs_context_dup(cifs_sb->ctx, ctx);
  688. smb3_update_mnt_flags(cifs_sb);
  689. #ifdef CONFIG_CIFS_DFS_UPCALL
  690. if (!rc)
  691. rc = dfs_cache_remount_fs(cifs_sb);
  692. #endif
  693. return rc;
  694. }
  695. static int smb3_fs_context_parse_param(struct fs_context *fc,
  696. struct fs_parameter *param)
  697. {
  698. struct fs_parse_result result;
  699. struct smb3_fs_context *ctx = smb3_fc2context(fc);
  700. int i, opt;
  701. bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
  702. bool skip_parsing = false;
  703. kuid_t uid;
  704. kgid_t gid;
  705. cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
  706. /*
  707. * fs_parse can not handle string options with an empty value so
  708. * we will need special handling of them.
  709. */
  710. if (param->type == fs_value_is_string && param->string[0] == 0) {
  711. if (!strcmp("pass", param->key) || !strcmp("password", param->key)) {
  712. skip_parsing = true;
  713. opt = Opt_pass;
  714. } else if (!strcmp("user", param->key) || !strcmp("username", param->key)) {
  715. skip_parsing = true;
  716. opt = Opt_user;
  717. }
  718. }
  719. if (!skip_parsing) {
  720. opt = fs_parse(fc, smb3_fs_parameters, param, &result);
  721. if (opt < 0)
  722. return ctx->sloppy ? 1 : opt;
  723. }
  724. switch (opt) {
  725. case Opt_compress:
  726. ctx->compression = UNKNOWN_TYPE;
  727. cifs_dbg(VFS,
  728. "SMB3 compression support is experimental\n");
  729. break;
  730. case Opt_nodfs:
  731. ctx->nodfs = 1;
  732. break;
  733. case Opt_hard:
  734. if (result.negated)
  735. ctx->retry = 0;
  736. else
  737. ctx->retry = 1;
  738. break;
  739. case Opt_soft:
  740. if (result.negated)
  741. ctx->retry = 1;
  742. else
  743. ctx->retry = 0;
  744. break;
  745. case Opt_mapposix:
  746. if (result.negated)
  747. ctx->remap = false;
  748. else {
  749. ctx->remap = true;
  750. ctx->sfu_remap = false; /* disable SFU mapping */
  751. }
  752. break;
  753. case Opt_user_xattr:
  754. if (result.negated)
  755. ctx->no_xattr = 1;
  756. else
  757. ctx->no_xattr = 0;
  758. break;
  759. case Opt_forceuid:
  760. if (result.negated)
  761. ctx->override_uid = 0;
  762. else
  763. ctx->override_uid = 1;
  764. break;
  765. case Opt_forcegid:
  766. if (result.negated)
  767. ctx->override_gid = 0;
  768. else
  769. ctx->override_gid = 1;
  770. break;
  771. case Opt_perm:
  772. if (result.negated)
  773. ctx->noperm = 1;
  774. else
  775. ctx->noperm = 0;
  776. break;
  777. case Opt_dynperm:
  778. if (result.negated)
  779. ctx->dynperm = 0;
  780. else
  781. ctx->dynperm = 1;
  782. break;
  783. case Opt_sfu:
  784. if (result.negated)
  785. ctx->sfu_emul = 0;
  786. else
  787. ctx->sfu_emul = 1;
  788. break;
  789. case Opt_noblocksend:
  790. ctx->noblocksnd = 1;
  791. break;
  792. case Opt_noautotune:
  793. ctx->noautotune = 1;
  794. break;
  795. case Opt_nolease:
  796. ctx->no_lease = 1;
  797. break;
  798. case Opt_nodelete:
  799. ctx->nodelete = 1;
  800. break;
  801. case Opt_multichannel:
  802. if (result.negated) {
  803. ctx->multichannel = false;
  804. ctx->max_channels = 1;
  805. } else {
  806. ctx->multichannel = true;
  807. /* if number of channels not specified, default to 2 */
  808. if (ctx->max_channels < 2)
  809. ctx->max_channels = 2;
  810. }
  811. break;
  812. case Opt_uid:
  813. uid = make_kuid(current_user_ns(), result.uint_32);
  814. if (!uid_valid(uid))
  815. goto cifs_parse_mount_err;
  816. ctx->linux_uid = uid;
  817. ctx->uid_specified = true;
  818. break;
  819. case Opt_cruid:
  820. uid = make_kuid(current_user_ns(), result.uint_32);
  821. if (!uid_valid(uid))
  822. goto cifs_parse_mount_err;
  823. ctx->cred_uid = uid;
  824. ctx->cruid_specified = true;
  825. break;
  826. case Opt_backupuid:
  827. uid = make_kuid(current_user_ns(), result.uint_32);
  828. if (!uid_valid(uid))
  829. goto cifs_parse_mount_err;
  830. ctx->backupuid = uid;
  831. ctx->backupuid_specified = true;
  832. break;
  833. case Opt_backupgid:
  834. gid = make_kgid(current_user_ns(), result.uint_32);
  835. if (!gid_valid(gid))
  836. goto cifs_parse_mount_err;
  837. ctx->backupgid = gid;
  838. ctx->backupgid_specified = true;
  839. break;
  840. case Opt_gid:
  841. gid = make_kgid(current_user_ns(), result.uint_32);
  842. if (!gid_valid(gid))
  843. goto cifs_parse_mount_err;
  844. ctx->linux_gid = gid;
  845. ctx->gid_specified = true;
  846. break;
  847. case Opt_port:
  848. ctx->port = result.uint_32;
  849. break;
  850. case Opt_file_mode:
  851. ctx->file_mode = result.uint_32;
  852. break;
  853. case Opt_dirmode:
  854. ctx->dir_mode = result.uint_32;
  855. break;
  856. case Opt_min_enc_offload:
  857. ctx->min_offload = result.uint_32;
  858. break;
  859. case Opt_blocksize:
  860. /*
  861. * inode blocksize realistically should never need to be
  862. * less than 16K or greater than 16M and default is 1MB.
  863. * Note that small inode block sizes (e.g. 64K) can lead
  864. * to very poor performance of common tools like cp and scp
  865. */
  866. if ((result.uint_32 < CIFS_MAX_MSGSIZE) ||
  867. (result.uint_32 > (4 * SMB3_DEFAULT_IOSIZE))) {
  868. cifs_errorf(fc, "%s: Invalid blocksize\n",
  869. __func__);
  870. goto cifs_parse_mount_err;
  871. }
  872. ctx->bsize = result.uint_32;
  873. ctx->got_bsize = true;
  874. break;
  875. case Opt_rasize:
  876. /*
  877. * readahead size realistically should never need to be
  878. * less than 1M (CIFS_DEFAULT_IOSIZE) or greater than 32M
  879. * (perhaps an exception should be considered in the
  880. * for the case of a large number of channels
  881. * when multichannel is negotiated) since that would lead
  882. * to plenty of parallel I/O in flight to the server.
  883. * Note that smaller read ahead sizes would
  884. * hurt performance of common tools like cp and scp
  885. * which often trigger sequential i/o with read ahead
  886. */
  887. if ((result.uint_32 > (8 * SMB3_DEFAULT_IOSIZE)) ||
  888. (result.uint_32 < CIFS_DEFAULT_IOSIZE)) {
  889. cifs_errorf(fc, "%s: Invalid rasize %d vs. %d\n",
  890. __func__, result.uint_32, SMB3_DEFAULT_IOSIZE);
  891. goto cifs_parse_mount_err;
  892. }
  893. ctx->rasize = result.uint_32;
  894. break;
  895. case Opt_rsize:
  896. ctx->rsize = result.uint_32;
  897. ctx->got_rsize = true;
  898. break;
  899. case Opt_wsize:
  900. ctx->wsize = result.uint_32;
  901. ctx->got_wsize = true;
  902. break;
  903. case Opt_acregmax:
  904. ctx->acregmax = HZ * result.uint_32;
  905. if (ctx->acregmax > CIFS_MAX_ACTIMEO) {
  906. cifs_errorf(fc, "acregmax too large\n");
  907. goto cifs_parse_mount_err;
  908. }
  909. break;
  910. case Opt_acdirmax:
  911. ctx->acdirmax = HZ * result.uint_32;
  912. if (ctx->acdirmax > CIFS_MAX_ACTIMEO) {
  913. cifs_errorf(fc, "acdirmax too large\n");
  914. goto cifs_parse_mount_err;
  915. }
  916. break;
  917. case Opt_actimeo:
  918. if (HZ * result.uint_32 > CIFS_MAX_ACTIMEO) {
  919. cifs_errorf(fc, "timeout too large\n");
  920. goto cifs_parse_mount_err;
  921. }
  922. if ((ctx->acdirmax != CIFS_DEF_ACTIMEO) ||
  923. (ctx->acregmax != CIFS_DEF_ACTIMEO)) {
  924. cifs_errorf(fc, "actimeo ignored since acregmax or acdirmax specified\n");
  925. break;
  926. }
  927. ctx->acdirmax = ctx->acregmax = HZ * result.uint_32;
  928. break;
  929. case Opt_echo_interval:
  930. ctx->echo_interval = result.uint_32;
  931. break;
  932. case Opt_snapshot:
  933. ctx->snapshot_time = result.uint_32;
  934. break;
  935. case Opt_max_credits:
  936. if (result.uint_32 < 20 || result.uint_32 > 60000) {
  937. cifs_errorf(fc, "%s: Invalid max_credits value\n",
  938. __func__);
  939. goto cifs_parse_mount_err;
  940. }
  941. ctx->max_credits = result.uint_32;
  942. break;
  943. case Opt_max_channels:
  944. if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
  945. cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
  946. __func__, CIFS_MAX_CHANNELS);
  947. goto cifs_parse_mount_err;
  948. }
  949. ctx->max_channels = result.uint_32;
  950. /* If more than one channel requested ... they want multichan */
  951. if (result.uint_32 > 1)
  952. ctx->multichannel = true;
  953. break;
  954. case Opt_handletimeout:
  955. ctx->handle_timeout = result.uint_32;
  956. if (ctx->handle_timeout > SMB3_MAX_HANDLE_TIMEOUT) {
  957. cifs_errorf(fc, "Invalid handle cache timeout, longer than 16 minutes\n");
  958. goto cifs_parse_mount_err;
  959. }
  960. break;
  961. case Opt_source:
  962. kfree(ctx->UNC);
  963. ctx->UNC = NULL;
  964. switch (smb3_parse_devname(param->string, ctx)) {
  965. case 0:
  966. break;
  967. case -ENOMEM:
  968. cifs_errorf(fc, "Unable to allocate memory for devname\n");
  969. goto cifs_parse_mount_err;
  970. case -EINVAL:
  971. cifs_errorf(fc, "Malformed UNC in devname\n");
  972. goto cifs_parse_mount_err;
  973. default:
  974. cifs_errorf(fc, "Unknown error parsing devname\n");
  975. goto cifs_parse_mount_err;
  976. }
  977. ctx->source = kstrdup(param->string, GFP_KERNEL);
  978. if (ctx->source == NULL) {
  979. cifs_errorf(fc, "OOM when copying UNC string\n");
  980. goto cifs_parse_mount_err;
  981. }
  982. fc->source = kstrdup(param->string, GFP_KERNEL);
  983. if (fc->source == NULL) {
  984. cifs_errorf(fc, "OOM when copying UNC string\n");
  985. goto cifs_parse_mount_err;
  986. }
  987. break;
  988. case Opt_user:
  989. kfree(ctx->username);
  990. ctx->username = NULL;
  991. if (strlen(param->string) == 0) {
  992. /* null user, ie. anonymous authentication */
  993. ctx->nullauth = 1;
  994. break;
  995. }
  996. if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
  997. CIFS_MAX_USERNAME_LEN) {
  998. pr_warn("username too long\n");
  999. goto cifs_parse_mount_err;
  1000. }
  1001. ctx->username = kstrdup(param->string, GFP_KERNEL);
  1002. if (ctx->username == NULL) {
  1003. cifs_errorf(fc, "OOM when copying username string\n");
  1004. goto cifs_parse_mount_err;
  1005. }
  1006. break;
  1007. case Opt_pass:
  1008. kfree(ctx->password);
  1009. ctx->password = NULL;
  1010. if (strlen(param->string) == 0)
  1011. break;
  1012. ctx->password = kstrdup(param->string, GFP_KERNEL);
  1013. if (ctx->password == NULL) {
  1014. cifs_errorf(fc, "OOM when copying password string\n");
  1015. goto cifs_parse_mount_err;
  1016. }
  1017. break;
  1018. case Opt_ip:
  1019. if (strlen(param->string) == 0) {
  1020. ctx->got_ip = false;
  1021. break;
  1022. }
  1023. if (!cifs_convert_address((struct sockaddr *)&ctx->dstaddr,
  1024. param->string,
  1025. strlen(param->string))) {
  1026. pr_err("bad ip= option (%s)\n", param->string);
  1027. goto cifs_parse_mount_err;
  1028. }
  1029. ctx->got_ip = true;
  1030. break;
  1031. case Opt_domain:
  1032. if (strnlen(param->string, CIFS_MAX_DOMAINNAME_LEN)
  1033. == CIFS_MAX_DOMAINNAME_LEN) {
  1034. pr_warn("domain name too long\n");
  1035. goto cifs_parse_mount_err;
  1036. }
  1037. kfree(ctx->domainname);
  1038. ctx->domainname = kstrdup(param->string, GFP_KERNEL);
  1039. if (ctx->domainname == NULL) {
  1040. cifs_errorf(fc, "OOM when copying domainname string\n");
  1041. goto cifs_parse_mount_err;
  1042. }
  1043. cifs_dbg(FYI, "Domain name set\n");
  1044. break;
  1045. case Opt_srcaddr:
  1046. if (!cifs_convert_address(
  1047. (struct sockaddr *)&ctx->srcaddr,
  1048. param->string, strlen(param->string))) {
  1049. pr_warn("Could not parse srcaddr: %s\n",
  1050. param->string);
  1051. goto cifs_parse_mount_err;
  1052. }
  1053. break;
  1054. case Opt_iocharset:
  1055. if (strnlen(param->string, 1024) >= 65) {
  1056. pr_warn("iocharset name too long\n");
  1057. goto cifs_parse_mount_err;
  1058. }
  1059. if (strncasecmp(param->string, "default", 7) != 0) {
  1060. kfree(ctx->iocharset);
  1061. ctx->iocharset = kstrdup(param->string, GFP_KERNEL);
  1062. if (ctx->iocharset == NULL) {
  1063. cifs_errorf(fc, "OOM when copying iocharset string\n");
  1064. goto cifs_parse_mount_err;
  1065. }
  1066. }
  1067. /* if iocharset not set then load_nls_default
  1068. * is used by caller
  1069. */
  1070. cifs_dbg(FYI, "iocharset set to %s\n", ctx->iocharset);
  1071. break;
  1072. case Opt_netbiosname:
  1073. memset(ctx->source_rfc1001_name, 0x20,
  1074. RFC1001_NAME_LEN);
  1075. /*
  1076. * FIXME: are there cases in which a comma can
  1077. * be valid in workstation netbios name (and
  1078. * need special handling)?
  1079. */
  1080. for (i = 0; i < RFC1001_NAME_LEN; i++) {
  1081. /* don't ucase netbiosname for user */
  1082. if (param->string[i] == 0)
  1083. break;
  1084. ctx->source_rfc1001_name[i] = param->string[i];
  1085. }
  1086. /* The string has 16th byte zero still from
  1087. * set at top of the function
  1088. */
  1089. if (i == RFC1001_NAME_LEN && param->string[i] != 0)
  1090. pr_warn("netbiosname longer than 15 truncated\n");
  1091. break;
  1092. case Opt_servern:
  1093. /* last byte, type, is 0x20 for servr type */
  1094. memset(ctx->target_rfc1001_name, 0x20,
  1095. RFC1001_NAME_LEN_WITH_NULL);
  1096. /*
  1097. * BB are there cases in which a comma can be valid in this
  1098. * workstation netbios name (and need special handling)?
  1099. */
  1100. /* user or mount helper must uppercase the netbios name */
  1101. for (i = 0; i < 15; i++) {
  1102. if (param->string[i] == 0)
  1103. break;
  1104. ctx->target_rfc1001_name[i] = param->string[i];
  1105. }
  1106. /* The string has 16th byte zero still from set at top of function */
  1107. if (i == RFC1001_NAME_LEN && param->string[i] != 0)
  1108. pr_warn("server netbiosname longer than 15 truncated\n");
  1109. break;
  1110. case Opt_ver:
  1111. /* version of mount userspace tools, not dialect */
  1112. /* If interface changes in mount.cifs bump to new ver */
  1113. if (strncasecmp(param->string, "1", 1) == 0) {
  1114. if (strlen(param->string) > 1) {
  1115. pr_warn("Bad mount helper ver=%s. Did you want SMB1 (CIFS) dialect and mean to type vers=1.0 instead?\n",
  1116. param->string);
  1117. goto cifs_parse_mount_err;
  1118. }
  1119. /* This is the default */
  1120. break;
  1121. }
  1122. /* For all other value, error */
  1123. pr_warn("Invalid mount helper version specified\n");
  1124. goto cifs_parse_mount_err;
  1125. case Opt_vers:
  1126. /* protocol version (dialect) */
  1127. if (cifs_parse_smb_version(fc, param->string, ctx, is_smb3) != 0)
  1128. goto cifs_parse_mount_err;
  1129. ctx->got_version = true;
  1130. break;
  1131. case Opt_sec:
  1132. if (cifs_parse_security_flavors(fc, param->string, ctx) != 0)
  1133. goto cifs_parse_mount_err;
  1134. break;
  1135. case Opt_cache:
  1136. if (cifs_parse_cache_flavor(fc, param->string, ctx) != 0)
  1137. goto cifs_parse_mount_err;
  1138. break;
  1139. case Opt_witness:
  1140. #ifndef CONFIG_CIFS_SWN_UPCALL
  1141. cifs_errorf(fc, "Witness support needs CONFIG_CIFS_SWN_UPCALL config option\n");
  1142. goto cifs_parse_mount_err;
  1143. #endif
  1144. ctx->witness = true;
  1145. pr_warn_once("Witness protocol support is experimental\n");
  1146. break;
  1147. case Opt_rootfs:
  1148. #ifndef CONFIG_CIFS_ROOT
  1149. cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
  1150. goto cifs_parse_mount_err;
  1151. #endif
  1152. ctx->rootfs = true;
  1153. break;
  1154. case Opt_posixpaths:
  1155. if (result.negated)
  1156. ctx->posix_paths = 0;
  1157. else
  1158. ctx->posix_paths = 1;
  1159. break;
  1160. case Opt_unix:
  1161. if (result.negated) {
  1162. if (ctx->linux_ext == 1)
  1163. pr_warn_once("conflicting posix mount options specified\n");
  1164. ctx->linux_ext = 0;
  1165. ctx->no_linux_ext = 1;
  1166. } else {
  1167. if (ctx->no_linux_ext == 1)
  1168. pr_warn_once("conflicting posix mount options specified\n");
  1169. ctx->linux_ext = 1;
  1170. ctx->no_linux_ext = 0;
  1171. }
  1172. break;
  1173. case Opt_nocase:
  1174. ctx->nocase = 1;
  1175. break;
  1176. case Opt_brl:
  1177. if (result.negated) {
  1178. /*
  1179. * turn off mandatory locking in mode
  1180. * if remote locking is turned off since the
  1181. * local vfs will do advisory
  1182. */
  1183. if (ctx->file_mode ==
  1184. (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
  1185. ctx->file_mode = S_IALLUGO;
  1186. ctx->nobrl = 1;
  1187. } else
  1188. ctx->nobrl = 0;
  1189. break;
  1190. case Opt_handlecache:
  1191. if (result.negated)
  1192. ctx->nohandlecache = 1;
  1193. else
  1194. ctx->nohandlecache = 0;
  1195. break;
  1196. case Opt_forcemandatorylock:
  1197. ctx->mand_lock = 1;
  1198. break;
  1199. case Opt_setuids:
  1200. ctx->setuids = result.negated;
  1201. break;
  1202. case Opt_intr:
  1203. ctx->intr = !result.negated;
  1204. break;
  1205. case Opt_setuidfromacl:
  1206. ctx->setuidfromacl = 1;
  1207. break;
  1208. case Opt_strictsync:
  1209. ctx->nostrictsync = result.negated;
  1210. break;
  1211. case Opt_serverino:
  1212. ctx->server_ino = !result.negated;
  1213. break;
  1214. case Opt_rwpidforward:
  1215. ctx->rwpidforward = 1;
  1216. break;
  1217. case Opt_modesid:
  1218. ctx->mode_ace = 1;
  1219. break;
  1220. case Opt_cifsacl:
  1221. ctx->cifs_acl = !result.negated;
  1222. break;
  1223. case Opt_acl:
  1224. ctx->no_psx_acl = result.negated;
  1225. break;
  1226. case Opt_locallease:
  1227. ctx->local_lease = 1;
  1228. break;
  1229. case Opt_sign:
  1230. ctx->sign = true;
  1231. break;
  1232. case Opt_ignore_signature:
  1233. ctx->sign = true;
  1234. ctx->ignore_signature = true;
  1235. break;
  1236. case Opt_seal:
  1237. /* we do not do the following in secFlags because seal
  1238. * is a per tree connection (mount) not a per socket
  1239. * or per-smb connection option in the protocol
  1240. * vol->secFlg |= CIFSSEC_MUST_SEAL;
  1241. */
  1242. ctx->seal = 1;
  1243. break;
  1244. case Opt_noac:
  1245. pr_warn("Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n");
  1246. break;
  1247. case Opt_fsc:
  1248. #ifndef CONFIG_CIFS_FSCACHE
  1249. cifs_errorf(fc, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n");
  1250. goto cifs_parse_mount_err;
  1251. #endif
  1252. ctx->fsc = true;
  1253. break;
  1254. case Opt_mfsymlinks:
  1255. ctx->mfsymlinks = true;
  1256. break;
  1257. case Opt_multiuser:
  1258. ctx->multiuser = true;
  1259. break;
  1260. case Opt_sloppy:
  1261. ctx->sloppy = true;
  1262. break;
  1263. case Opt_nosharesock:
  1264. ctx->nosharesock = true;
  1265. break;
  1266. case Opt_persistent:
  1267. if (result.negated) {
  1268. ctx->nopersistent = true;
  1269. if (ctx->persistent) {
  1270. cifs_errorf(fc, "persistenthandles mount options conflict\n");
  1271. goto cifs_parse_mount_err;
  1272. }
  1273. } else {
  1274. ctx->persistent = true;
  1275. if ((ctx->nopersistent) || (ctx->resilient)) {
  1276. cifs_errorf(fc, "persistenthandles mount options conflict\n");
  1277. goto cifs_parse_mount_err;
  1278. }
  1279. }
  1280. break;
  1281. case Opt_resilient:
  1282. if (result.negated) {
  1283. ctx->resilient = false; /* already the default */
  1284. } else {
  1285. ctx->resilient = true;
  1286. if (ctx->persistent) {
  1287. cifs_errorf(fc, "persistenthandles mount options conflict\n");
  1288. goto cifs_parse_mount_err;
  1289. }
  1290. }
  1291. break;
  1292. case Opt_domainauto:
  1293. ctx->domainauto = true;
  1294. break;
  1295. case Opt_rdma:
  1296. ctx->rdma = true;
  1297. break;
  1298. }
  1299. /* case Opt_ignore: - is ignored as expected ... */
  1300. return 0;
  1301. cifs_parse_mount_err:
  1302. return -EINVAL;
  1303. }
  1304. int smb3_init_fs_context(struct fs_context *fc)
  1305. {
  1306. struct smb3_fs_context *ctx;
  1307. char *nodename = utsname()->nodename;
  1308. int i;
  1309. ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
  1310. if (unlikely(!ctx))
  1311. return -ENOMEM;
  1312. /*
  1313. * does not have to be perfect mapping since field is
  1314. * informational, only used for servers that do not support
  1315. * port 445 and it can be overridden at mount time
  1316. */
  1317. memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
  1318. for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
  1319. ctx->source_rfc1001_name[i] = toupper(nodename[i]);
  1320. ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
  1321. /*
  1322. * null target name indicates to use *SMBSERVR default called name
  1323. * if we end up sending RFC1001 session initialize
  1324. */
  1325. ctx->target_rfc1001_name[0] = 0;
  1326. ctx->cred_uid = current_uid();
  1327. ctx->linux_uid = current_uid();
  1328. ctx->linux_gid = current_gid();
  1329. /* By default 4MB read ahead size, 1MB block size */
  1330. ctx->bsize = CIFS_DEFAULT_IOSIZE; /* can improve cp performance significantly */
  1331. ctx->rasize = 0; /* 0 = use default (ie negotiated rsize) for read ahead pages */
  1332. /*
  1333. * default to SFM style remapping of seven reserved characters
  1334. * unless user overrides it or we negotiate CIFS POSIX where
  1335. * it is unnecessary. Can not simultaneously use more than one mapping
  1336. * since then readdir could list files that open could not open
  1337. */
  1338. ctx->remap = true;
  1339. /* default to only allowing write access to owner of the mount */
  1340. ctx->dir_mode = ctx->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
  1341. /* ctx->retry default is 0 (i.e. "soft" limited retry not hard retry) */
  1342. /* default is always to request posix paths. */
  1343. ctx->posix_paths = 1;
  1344. /* default to using server inode numbers where available */
  1345. ctx->server_ino = 1;
  1346. /* default is to use strict cifs caching semantics */
  1347. ctx->strict_io = true;
  1348. ctx->acregmax = CIFS_DEF_ACTIMEO;
  1349. ctx->acdirmax = CIFS_DEF_ACTIMEO;
  1350. /* Most clients set timeout to 0, allows server to use its default */
  1351. ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */
  1352. /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
  1353. ctx->ops = &smb30_operations;
  1354. ctx->vals = &smbdefault_values;
  1355. ctx->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
  1356. /* default to no multichannel (single server connection) */
  1357. ctx->multichannel = false;
  1358. ctx->max_channels = 1;
  1359. ctx->backupuid_specified = false; /* no backup intent for a user */
  1360. ctx->backupgid_specified = false; /* no backup intent for a group */
  1361. /*
  1362. * short int override_uid = -1;
  1363. * short int override_gid = -1;
  1364. * char *nodename = strdup(utsname()->nodename);
  1365. * struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
  1366. */
  1367. fc->fs_private = ctx;
  1368. fc->ops = &smb3_fs_context_ops;
  1369. return 0;
  1370. }
  1371. void
  1372. smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
  1373. {
  1374. if (ctx == NULL)
  1375. return;
  1376. /*
  1377. * Make sure this stays in sync with smb3_fs_context_dup()
  1378. */
  1379. kfree(ctx->mount_options);
  1380. ctx->mount_options = NULL;
  1381. kfree(ctx->username);
  1382. ctx->username = NULL;
  1383. kfree_sensitive(ctx->password);
  1384. ctx->password = NULL;
  1385. kfree(ctx->UNC);
  1386. ctx->UNC = NULL;
  1387. kfree(ctx->source);
  1388. ctx->source = NULL;
  1389. kfree(ctx->domainname);
  1390. ctx->domainname = NULL;
  1391. kfree(ctx->nodename);
  1392. ctx->nodename = NULL;
  1393. kfree(ctx->iocharset);
  1394. ctx->iocharset = NULL;
  1395. kfree(ctx->prepath);
  1396. ctx->prepath = NULL;
  1397. }
  1398. void
  1399. smb3_cleanup_fs_context(struct smb3_fs_context *ctx)
  1400. {
  1401. if (!ctx)
  1402. return;
  1403. smb3_cleanup_fs_context_contents(ctx);
  1404. kfree(ctx);
  1405. }
  1406. void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb)
  1407. {
  1408. struct smb3_fs_context *ctx = cifs_sb->ctx;
  1409. if (ctx->nodfs)
  1410. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS;
  1411. else
  1412. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_DFS;
  1413. if (ctx->noperm)
  1414. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
  1415. else
  1416. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_PERM;
  1417. if (ctx->setuids)
  1418. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
  1419. else
  1420. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SET_UID;
  1421. if (ctx->setuidfromacl)
  1422. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL;
  1423. else
  1424. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UID_FROM_ACL;
  1425. if (ctx->server_ino)
  1426. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
  1427. else
  1428. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
  1429. if (ctx->remap)
  1430. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR;
  1431. else
  1432. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SFM_CHR;
  1433. if (ctx->sfu_remap)
  1434. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
  1435. else
  1436. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MAP_SPECIAL_CHR;
  1437. if (ctx->no_xattr)
  1438. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
  1439. else
  1440. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_XATTR;
  1441. if (ctx->sfu_emul)
  1442. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
  1443. else
  1444. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_UNX_EMUL;
  1445. if (ctx->nobrl)
  1446. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
  1447. else
  1448. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_BRL;
  1449. if (ctx->nohandlecache)
  1450. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE;
  1451. else
  1452. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NO_HANDLE_CACHE;
  1453. if (ctx->nostrictsync)
  1454. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
  1455. else
  1456. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOSSYNC;
  1457. if (ctx->mand_lock)
  1458. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
  1459. else
  1460. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_NOPOSIXBRL;
  1461. if (ctx->rwpidforward)
  1462. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
  1463. else
  1464. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_RWPIDFORWARD;
  1465. if (ctx->mode_ace)
  1466. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MODE_FROM_SID;
  1467. else
  1468. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MODE_FROM_SID;
  1469. if (ctx->cifs_acl)
  1470. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
  1471. else
  1472. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_ACL;
  1473. if (ctx->backupuid_specified)
  1474. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
  1475. else
  1476. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPUID;
  1477. if (ctx->backupgid_specified)
  1478. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
  1479. else
  1480. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_CIFS_BACKUPGID;
  1481. if (ctx->override_uid)
  1482. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
  1483. else
  1484. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_UID;
  1485. if (ctx->override_gid)
  1486. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
  1487. else
  1488. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_OVERR_GID;
  1489. if (ctx->dynperm)
  1490. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
  1491. else
  1492. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DYNPERM;
  1493. if (ctx->fsc)
  1494. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
  1495. else
  1496. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_FSCACHE;
  1497. if (ctx->multiuser)
  1498. cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
  1499. CIFS_MOUNT_NO_PERM);
  1500. else
  1501. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MULTIUSER;
  1502. if (ctx->strict_io)
  1503. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
  1504. else
  1505. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_STRICT_IO;
  1506. if (ctx->direct_io)
  1507. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
  1508. else
  1509. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_DIRECT_IO;
  1510. if (ctx->mfsymlinks)
  1511. cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS;
  1512. else
  1513. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_MF_SYMLINKS;
  1514. if (ctx->mfsymlinks) {
  1515. if (ctx->sfu_emul) {
  1516. /*
  1517. * Our SFU ("Services for Unix" emulation does not allow
  1518. * creating symlinks but does allow reading existing SFU
  1519. * symlinks (it does allow both creating and reading SFU
  1520. * style mknod and FIFOs though). When "mfsymlinks" and
  1521. * "sfu" are both enabled at the same time, it allows
  1522. * reading both types of symlinks, but will only create
  1523. * them with mfsymlinks format. This allows better
  1524. * Apple compatibility (probably better for Samba too)
  1525. * while still recognizing old Windows style symlinks.
  1526. */
  1527. cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n");
  1528. }
  1529. }
  1530. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SHUTDOWN;
  1531. return;
  1532. }