cifs_debug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * fs/cifs_debug.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2000,2005
  5. *
  6. * Modified by Steve French (sfrench@us.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  16. * the GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/fs.h>
  23. #include <linux/string.h>
  24. #include <linux/ctype.h>
  25. #include <linux/module.h>
  26. #include <linux/proc_fs.h>
  27. #include <asm/uaccess.h>
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifsfs.h"
  33. void
  34. cifs_dump_mem(char *label, void *data, int length)
  35. {
  36. pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
  37. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
  38. data, length, true);
  39. }
  40. #ifdef CONFIG_CIFS_DEBUG
  41. void cifs_vfs_err(const char *fmt, ...)
  42. {
  43. struct va_format vaf;
  44. va_list args;
  45. va_start(args, fmt);
  46. vaf.fmt = fmt;
  47. vaf.va = &args;
  48. pr_err("CIFS VFS: %pV", &vaf);
  49. va_end(args);
  50. }
  51. #endif
  52. void cifs_dump_detail(void *buf)
  53. {
  54. #ifdef CONFIG_CIFS_DEBUG2
  55. struct smb_hdr *smb = (struct smb_hdr *)buf;
  56. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
  57. smb->Command, smb->Status.CifsError,
  58. smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  59. cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
  60. #endif /* CONFIG_CIFS_DEBUG2 */
  61. }
  62. void cifs_dump_mids(struct TCP_Server_Info *server)
  63. {
  64. #ifdef CONFIG_CIFS_DEBUG2
  65. struct list_head *tmp;
  66. struct mid_q_entry *mid_entry;
  67. if (server == NULL)
  68. return;
  69. cifs_dbg(VFS, "Dump pending requests:\n");
  70. spin_lock(&GlobalMid_Lock);
  71. list_for_each(tmp, &server->pending_mid_q) {
  72. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  73. cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
  74. mid_entry->mid_state,
  75. le16_to_cpu(mid_entry->command),
  76. mid_entry->pid,
  77. mid_entry->callback_data,
  78. mid_entry->mid);
  79. #ifdef CONFIG_CIFS_STATS2
  80. cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
  81. mid_entry->large_buf,
  82. mid_entry->resp_buf,
  83. mid_entry->when_received,
  84. jiffies);
  85. #endif /* STATS2 */
  86. cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
  87. mid_entry->multiRsp, mid_entry->multiEnd);
  88. if (mid_entry->resp_buf) {
  89. cifs_dump_detail(mid_entry->resp_buf);
  90. cifs_dump_mem("existing buf: ",
  91. mid_entry->resp_buf, 62);
  92. }
  93. }
  94. spin_unlock(&GlobalMid_Lock);
  95. #endif /* CONFIG_CIFS_DEBUG2 */
  96. }
  97. #ifdef CONFIG_PROC_FS
  98. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  99. {
  100. struct list_head *tmp1, *tmp2, *tmp3;
  101. struct mid_q_entry *mid_entry;
  102. struct TCP_Server_Info *server;
  103. struct cifs_ses *ses;
  104. struct cifs_tcon *tcon;
  105. int i, j;
  106. __u32 dev_type;
  107. seq_puts(m,
  108. "Display Internal CIFS Data Structures for Debugging\n"
  109. "---------------------------------------------------\n");
  110. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  111. seq_printf(m, "Features:");
  112. #ifdef CONFIG_CIFS_DFS_UPCALL
  113. seq_printf(m, " dfs");
  114. #endif
  115. #ifdef CONFIG_CIFS_FSCACHE
  116. seq_printf(m, " fscache");
  117. #endif
  118. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  119. seq_printf(m, " lanman");
  120. #endif
  121. #ifdef CONFIG_CIFS_POSIX
  122. seq_printf(m, " posix");
  123. #endif
  124. #ifdef CONFIG_CIFS_UPCALL
  125. seq_printf(m, " spnego");
  126. #endif
  127. #ifdef CONFIG_CIFS_XATTR
  128. seq_printf(m, " xattr");
  129. #endif
  130. #ifdef CONFIG_CIFS_ACL
  131. seq_printf(m, " acl");
  132. #endif
  133. seq_putc(m, '\n');
  134. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  135. seq_printf(m, "Servers:");
  136. i = 0;
  137. spin_lock(&cifs_tcp_ses_lock);
  138. list_for_each(tmp1, &cifs_tcp_ses_list) {
  139. server = list_entry(tmp1, struct TCP_Server_Info,
  140. tcp_ses_list);
  141. i++;
  142. list_for_each(tmp2, &server->smb_ses_list) {
  143. ses = list_entry(tmp2, struct cifs_ses,
  144. smb_ses_list);
  145. if ((ses->serverDomain == NULL) ||
  146. (ses->serverOS == NULL) ||
  147. (ses->serverNOS == NULL)) {
  148. seq_printf(m, "\n%d) entry for %s not fully "
  149. "displayed\n\t", i, ses->serverName);
  150. } else {
  151. seq_printf(m,
  152. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  153. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  154. " session status: %d\t",
  155. i, ses->serverName, ses->serverDomain,
  156. ses->ses_count, ses->serverOS, ses->serverNOS,
  157. ses->capabilities, ses->status);
  158. }
  159. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  160. "Server: %d SecMode: 0x%x Req On Wire: %d",
  161. server->tcpStatus, server->srv_count,
  162. server->sec_mode, in_flight(server));
  163. #ifdef CONFIG_CIFS_STATS2
  164. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  165. atomic_read(&server->in_send),
  166. atomic_read(&server->num_waiters));
  167. #endif
  168. seq_puts(m, "\n\tShares:");
  169. j = 0;
  170. list_for_each(tmp3, &ses->tcon_list) {
  171. tcon = list_entry(tmp3, struct cifs_tcon,
  172. tcon_list);
  173. ++j;
  174. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  175. seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
  176. tcon->treeName, tcon->tc_count);
  177. if (tcon->nativeFileSystem) {
  178. seq_printf(m, "Type: %s ",
  179. tcon->nativeFileSystem);
  180. }
  181. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  182. "\n\tPathComponentMax: %d Status: %d",
  183. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  184. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  185. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  186. tcon->tidStatus);
  187. if (dev_type == FILE_DEVICE_DISK)
  188. seq_puts(m, " type: DISK ");
  189. else if (dev_type == FILE_DEVICE_CD_ROM)
  190. seq_puts(m, " type: CDROM ");
  191. else
  192. seq_printf(m, " type: %d ", dev_type);
  193. if (server->ops->dump_share_caps)
  194. server->ops->dump_share_caps(m, tcon);
  195. if (tcon->need_reconnect)
  196. seq_puts(m, "\tDISCONNECTED ");
  197. seq_putc(m, '\n');
  198. }
  199. seq_puts(m, "\n\tMIDs:\n");
  200. spin_lock(&GlobalMid_Lock);
  201. list_for_each(tmp3, &server->pending_mid_q) {
  202. mid_entry = list_entry(tmp3, struct mid_q_entry,
  203. qhead);
  204. seq_printf(m, "\tState: %d com: %d pid:"
  205. " %d cbdata: %p mid %llu\n",
  206. mid_entry->mid_state,
  207. le16_to_cpu(mid_entry->command),
  208. mid_entry->pid,
  209. mid_entry->callback_data,
  210. mid_entry->mid);
  211. }
  212. spin_unlock(&GlobalMid_Lock);
  213. }
  214. }
  215. spin_unlock(&cifs_tcp_ses_lock);
  216. seq_putc(m, '\n');
  217. /* BB add code to dump additional info such as TCP session info now */
  218. return 0;
  219. }
  220. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  221. {
  222. return single_open(file, cifs_debug_data_proc_show, NULL);
  223. }
  224. static const struct file_operations cifs_debug_data_proc_fops = {
  225. .owner = THIS_MODULE,
  226. .open = cifs_debug_data_proc_open,
  227. .read = seq_read,
  228. .llseek = seq_lseek,
  229. .release = single_release,
  230. };
  231. #ifdef CONFIG_CIFS_STATS
  232. static ssize_t cifs_stats_proc_write(struct file *file,
  233. const char __user *buffer, size_t count, loff_t *ppos)
  234. {
  235. char c;
  236. bool bv;
  237. int rc;
  238. struct list_head *tmp1, *tmp2, *tmp3;
  239. struct TCP_Server_Info *server;
  240. struct cifs_ses *ses;
  241. struct cifs_tcon *tcon;
  242. rc = get_user(c, buffer);
  243. if (rc)
  244. return rc;
  245. if (strtobool(&c, &bv) == 0) {
  246. #ifdef CONFIG_CIFS_STATS2
  247. atomic_set(&totBufAllocCount, 0);
  248. atomic_set(&totSmBufAllocCount, 0);
  249. #endif /* CONFIG_CIFS_STATS2 */
  250. spin_lock(&cifs_tcp_ses_lock);
  251. list_for_each(tmp1, &cifs_tcp_ses_list) {
  252. server = list_entry(tmp1, struct TCP_Server_Info,
  253. tcp_ses_list);
  254. list_for_each(tmp2, &server->smb_ses_list) {
  255. ses = list_entry(tmp2, struct cifs_ses,
  256. smb_ses_list);
  257. list_for_each(tmp3, &ses->tcon_list) {
  258. tcon = list_entry(tmp3,
  259. struct cifs_tcon,
  260. tcon_list);
  261. atomic_set(&tcon->num_smbs_sent, 0);
  262. if (server->ops->clear_stats)
  263. server->ops->clear_stats(tcon);
  264. }
  265. }
  266. }
  267. spin_unlock(&cifs_tcp_ses_lock);
  268. }
  269. return count;
  270. }
  271. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  272. {
  273. int i;
  274. struct list_head *tmp1, *tmp2, *tmp3;
  275. struct TCP_Server_Info *server;
  276. struct cifs_ses *ses;
  277. struct cifs_tcon *tcon;
  278. seq_printf(m,
  279. "Resources in use\nCIFS Session: %d\n",
  280. sesInfoAllocCount.counter);
  281. seq_printf(m, "Share (unique mount targets): %d\n",
  282. tconInfoAllocCount.counter);
  283. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  284. bufAllocCount.counter,
  285. cifs_min_rcv + tcpSesAllocCount.counter);
  286. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  287. smBufAllocCount.counter, cifs_min_small);
  288. #ifdef CONFIG_CIFS_STATS2
  289. seq_printf(m, "Total Large %d Small %d Allocations\n",
  290. atomic_read(&totBufAllocCount),
  291. atomic_read(&totSmBufAllocCount));
  292. #endif /* CONFIG_CIFS_STATS2 */
  293. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  294. seq_printf(m,
  295. "\n%d session %d share reconnects\n",
  296. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  297. seq_printf(m,
  298. "Total vfs operations: %d maximum at one time: %d\n",
  299. GlobalCurrentXid, GlobalMaxActiveXid);
  300. i = 0;
  301. spin_lock(&cifs_tcp_ses_lock);
  302. list_for_each(tmp1, &cifs_tcp_ses_list) {
  303. server = list_entry(tmp1, struct TCP_Server_Info,
  304. tcp_ses_list);
  305. list_for_each(tmp2, &server->smb_ses_list) {
  306. ses = list_entry(tmp2, struct cifs_ses,
  307. smb_ses_list);
  308. list_for_each(tmp3, &ses->tcon_list) {
  309. tcon = list_entry(tmp3,
  310. struct cifs_tcon,
  311. tcon_list);
  312. i++;
  313. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  314. if (tcon->need_reconnect)
  315. seq_puts(m, "\tDISCONNECTED ");
  316. seq_printf(m, "\nSMBs: %d",
  317. atomic_read(&tcon->num_smbs_sent));
  318. if (server->ops->print_stats)
  319. server->ops->print_stats(m, tcon);
  320. }
  321. }
  322. }
  323. spin_unlock(&cifs_tcp_ses_lock);
  324. seq_putc(m, '\n');
  325. return 0;
  326. }
  327. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  328. {
  329. return single_open(file, cifs_stats_proc_show, NULL);
  330. }
  331. static const struct file_operations cifs_stats_proc_fops = {
  332. .owner = THIS_MODULE,
  333. .open = cifs_stats_proc_open,
  334. .read = seq_read,
  335. .llseek = seq_lseek,
  336. .release = single_release,
  337. .write = cifs_stats_proc_write,
  338. };
  339. #endif /* STATS */
  340. static struct proc_dir_entry *proc_fs_cifs;
  341. static const struct file_operations cifsFYI_proc_fops;
  342. static const struct file_operations cifs_lookup_cache_proc_fops;
  343. static const struct file_operations traceSMB_proc_fops;
  344. static const struct file_operations cifs_security_flags_proc_fops;
  345. static const struct file_operations cifs_linux_ext_proc_fops;
  346. void
  347. cifs_proc_init(void)
  348. {
  349. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  350. if (proc_fs_cifs == NULL)
  351. return;
  352. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  353. #ifdef CONFIG_CIFS_STATS
  354. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  355. #endif /* STATS */
  356. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  357. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  358. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  359. &cifs_linux_ext_proc_fops);
  360. proc_create("SecurityFlags", 0, proc_fs_cifs,
  361. &cifs_security_flags_proc_fops);
  362. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  363. &cifs_lookup_cache_proc_fops);
  364. }
  365. void
  366. cifs_proc_clean(void)
  367. {
  368. if (proc_fs_cifs == NULL)
  369. return;
  370. remove_proc_entry("DebugData", proc_fs_cifs);
  371. remove_proc_entry("cifsFYI", proc_fs_cifs);
  372. remove_proc_entry("traceSMB", proc_fs_cifs);
  373. #ifdef CONFIG_CIFS_STATS
  374. remove_proc_entry("Stats", proc_fs_cifs);
  375. #endif
  376. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  377. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  378. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  379. remove_proc_entry("fs/cifs", NULL);
  380. }
  381. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  382. {
  383. seq_printf(m, "%d\n", cifsFYI);
  384. return 0;
  385. }
  386. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  387. {
  388. return single_open(file, cifsFYI_proc_show, NULL);
  389. }
  390. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  391. size_t count, loff_t *ppos)
  392. {
  393. char c;
  394. bool bv;
  395. int rc;
  396. rc = get_user(c, buffer);
  397. if (rc)
  398. return rc;
  399. if (strtobool(&c, &bv) == 0)
  400. cifsFYI = bv;
  401. else if ((c > '1') && (c <= '9'))
  402. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  403. return count;
  404. }
  405. static const struct file_operations cifsFYI_proc_fops = {
  406. .owner = THIS_MODULE,
  407. .open = cifsFYI_proc_open,
  408. .read = seq_read,
  409. .llseek = seq_lseek,
  410. .release = single_release,
  411. .write = cifsFYI_proc_write,
  412. };
  413. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  414. {
  415. seq_printf(m, "%d\n", linuxExtEnabled);
  416. return 0;
  417. }
  418. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  419. {
  420. return single_open(file, cifs_linux_ext_proc_show, NULL);
  421. }
  422. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  423. const char __user *buffer, size_t count, loff_t *ppos)
  424. {
  425. char c;
  426. bool bv;
  427. int rc;
  428. rc = get_user(c, buffer);
  429. if (rc)
  430. return rc;
  431. rc = strtobool(&c, &bv);
  432. if (rc)
  433. return rc;
  434. linuxExtEnabled = bv;
  435. return count;
  436. }
  437. static const struct file_operations cifs_linux_ext_proc_fops = {
  438. .owner = THIS_MODULE,
  439. .open = cifs_linux_ext_proc_open,
  440. .read = seq_read,
  441. .llseek = seq_lseek,
  442. .release = single_release,
  443. .write = cifs_linux_ext_proc_write,
  444. };
  445. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  446. {
  447. seq_printf(m, "%d\n", lookupCacheEnabled);
  448. return 0;
  449. }
  450. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  451. {
  452. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  453. }
  454. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  455. const char __user *buffer, size_t count, loff_t *ppos)
  456. {
  457. char c;
  458. bool bv;
  459. int rc;
  460. rc = get_user(c, buffer);
  461. if (rc)
  462. return rc;
  463. rc = strtobool(&c, &bv);
  464. if (rc)
  465. return rc;
  466. lookupCacheEnabled = bv;
  467. return count;
  468. }
  469. static const struct file_operations cifs_lookup_cache_proc_fops = {
  470. .owner = THIS_MODULE,
  471. .open = cifs_lookup_cache_proc_open,
  472. .read = seq_read,
  473. .llseek = seq_lseek,
  474. .release = single_release,
  475. .write = cifs_lookup_cache_proc_write,
  476. };
  477. static int traceSMB_proc_show(struct seq_file *m, void *v)
  478. {
  479. seq_printf(m, "%d\n", traceSMB);
  480. return 0;
  481. }
  482. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  483. {
  484. return single_open(file, traceSMB_proc_show, NULL);
  485. }
  486. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  487. size_t count, loff_t *ppos)
  488. {
  489. char c;
  490. bool bv;
  491. int rc;
  492. rc = get_user(c, buffer);
  493. if (rc)
  494. return rc;
  495. rc = strtobool(&c, &bv);
  496. if (rc)
  497. return rc;
  498. traceSMB = bv;
  499. return count;
  500. }
  501. static const struct file_operations traceSMB_proc_fops = {
  502. .owner = THIS_MODULE,
  503. .open = traceSMB_proc_open,
  504. .read = seq_read,
  505. .llseek = seq_lseek,
  506. .release = single_release,
  507. .write = traceSMB_proc_write,
  508. };
  509. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  510. {
  511. seq_printf(m, "0x%x\n", global_secflags);
  512. return 0;
  513. }
  514. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  515. {
  516. return single_open(file, cifs_security_flags_proc_show, NULL);
  517. }
  518. /*
  519. * Ensure that if someone sets a MUST flag, that we disable all other MAY
  520. * flags except for the ones corresponding to the given MUST flag. If there are
  521. * multiple MUST flags, then try to prefer more secure ones.
  522. */
  523. static void
  524. cifs_security_flags_handle_must_flags(unsigned int *flags)
  525. {
  526. unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
  527. if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
  528. *flags = CIFSSEC_MUST_KRB5;
  529. else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
  530. *flags = CIFSSEC_MUST_NTLMSSP;
  531. else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
  532. *flags = CIFSSEC_MUST_NTLMV2;
  533. else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
  534. *flags = CIFSSEC_MUST_NTLM;
  535. else if (CIFSSEC_MUST_LANMAN &&
  536. (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
  537. *flags = CIFSSEC_MUST_LANMAN;
  538. else if (CIFSSEC_MUST_PLNTXT &&
  539. (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
  540. *flags = CIFSSEC_MUST_PLNTXT;
  541. *flags |= signflags;
  542. }
  543. static ssize_t cifs_security_flags_proc_write(struct file *file,
  544. const char __user *buffer, size_t count, loff_t *ppos)
  545. {
  546. int rc;
  547. unsigned int flags;
  548. char flags_string[12];
  549. char c;
  550. bool bv;
  551. if ((count < 1) || (count > 11))
  552. return -EINVAL;
  553. memset(flags_string, 0, 12);
  554. if (copy_from_user(flags_string, buffer, count))
  555. return -EFAULT;
  556. if (count < 3) {
  557. /* single char or single char followed by null */
  558. c = flags_string[0];
  559. if (strtobool(&c, &bv) == 0) {
  560. global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
  561. return count;
  562. } else if (!isdigit(c)) {
  563. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  564. flags_string);
  565. return -EINVAL;
  566. }
  567. }
  568. /* else we have a number */
  569. rc = kstrtouint(flags_string, 0, &flags);
  570. if (rc) {
  571. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  572. flags_string);
  573. return rc;
  574. }
  575. cifs_dbg(FYI, "sec flags 0x%x\n", flags);
  576. if (flags == 0) {
  577. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
  578. return -EINVAL;
  579. }
  580. if (flags & ~CIFSSEC_MASK) {
  581. cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
  582. flags & ~CIFSSEC_MASK);
  583. return -EINVAL;
  584. }
  585. cifs_security_flags_handle_must_flags(&flags);
  586. /* flags look ok - update the global security flags for cifs module */
  587. global_secflags = flags;
  588. if (global_secflags & CIFSSEC_MUST_SIGN) {
  589. /* requiring signing implies signing is allowed */
  590. global_secflags |= CIFSSEC_MAY_SIGN;
  591. cifs_dbg(FYI, "packet signing now required\n");
  592. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  593. cifs_dbg(FYI, "packet signing disabled\n");
  594. }
  595. /* BB should we turn on MAY flags for other MUST options? */
  596. return count;
  597. }
  598. static const struct file_operations cifs_security_flags_proc_fops = {
  599. .owner = THIS_MODULE,
  600. .open = cifs_security_flags_proc_open,
  601. .read = seq_read,
  602. .llseek = seq_lseek,
  603. .release = single_release,
  604. .write = cifs_security_flags_proc_write,
  605. };
  606. #else
  607. inline void cifs_proc_init(void)
  608. {
  609. }
  610. inline void cifs_proc_clean(void)
  611. {
  612. }
  613. #endif /* PROC_FS */