PageRenderTime 196ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/fs/cifs/fs_context.c

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