cifs_debug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * fs/cifs_debug.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2000,2005
  5. *
  6. * Modified by Steve French ([email protected])
  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_ratelimited("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_SMB_DIRECT
  119. seq_printf(m, ",SMB_DIRECT");
  120. #endif
  121. #ifdef CONFIG_CIFS_STATS2
  122. seq_printf(m, ",STATS2");
  123. #elif defined(CONFIG_CIFS_STATS)
  124. seq_printf(m, ",STATS");
  125. #endif
  126. #ifdef CONFIG_CIFS_DEBUG2
  127. seq_printf(m, ",DEBUG2");
  128. #elif defined(CONFIG_CIFS_DEBUG)
  129. seq_printf(m, ",DEBUG");
  130. #endif
  131. #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
  132. seq_printf(m, ",ALLOW_INSECURE_LEGACY");
  133. #endif
  134. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  135. seq_printf(m, ",WEAK_PW_HASH");
  136. #endif
  137. #ifdef CONFIG_CIFS_POSIX
  138. seq_printf(m, ",CIFS_POSIX");
  139. #endif
  140. #ifdef CONFIG_CIFS_UPCALL
  141. seq_printf(m, ",UPCALL(SPNEGO)");
  142. #endif
  143. #ifdef CONFIG_CIFS_XATTR
  144. seq_printf(m, ",XATTR");
  145. #endif
  146. #ifdef CONFIG_CIFS_ACL
  147. seq_printf(m, ",ACL");
  148. #endif
  149. seq_putc(m, '\n');
  150. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  151. seq_printf(m, "Servers:");
  152. i = 0;
  153. spin_lock(&cifs_tcp_ses_lock);
  154. list_for_each(tmp1, &cifs_tcp_ses_list) {
  155. server = list_entry(tmp1, struct TCP_Server_Info,
  156. tcp_ses_list);
  157. seq_printf(m, "\nNumber of credits: %d", server->credits);
  158. i++;
  159. list_for_each(tmp2, &server->smb_ses_list) {
  160. ses = list_entry(tmp2, struct cifs_ses,
  161. smb_ses_list);
  162. if ((ses->serverDomain == NULL) ||
  163. (ses->serverOS == NULL) ||
  164. (ses->serverNOS == NULL)) {
  165. seq_printf(m, "\n%d) entry for %s not fully "
  166. "displayed\n\t", i, ses->serverName);
  167. } else {
  168. seq_printf(m,
  169. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  170. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  171. " session status: %d\t",
  172. i, ses->serverName, ses->serverDomain,
  173. ses->ses_count, ses->serverOS, ses->serverNOS,
  174. ses->capabilities, ses->status);
  175. }
  176. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  177. "Server: %d SecMode: 0x%x Req On Wire: %d",
  178. server->tcpStatus, server->srv_count,
  179. server->sec_mode, in_flight(server));
  180. #ifdef CONFIG_CIFS_STATS2
  181. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  182. atomic_read(&server->in_send),
  183. atomic_read(&server->num_waiters));
  184. #endif
  185. seq_puts(m, "\n\tShares:");
  186. j = 0;
  187. list_for_each(tmp3, &ses->tcon_list) {
  188. tcon = list_entry(tmp3, struct cifs_tcon,
  189. tcon_list);
  190. ++j;
  191. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  192. seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
  193. tcon->treeName, tcon->tc_count);
  194. if (tcon->nativeFileSystem) {
  195. seq_printf(m, "Type: %s ",
  196. tcon->nativeFileSystem);
  197. }
  198. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  199. "\n\tPathComponentMax: %d Status: %d",
  200. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  201. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  202. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  203. tcon->tidStatus);
  204. if (dev_type == FILE_DEVICE_DISK)
  205. seq_puts(m, " type: DISK ");
  206. else if (dev_type == FILE_DEVICE_CD_ROM)
  207. seq_puts(m, " type: CDROM ");
  208. else
  209. seq_printf(m, " type: %d ", dev_type);
  210. if (server->ops->dump_share_caps)
  211. server->ops->dump_share_caps(m, tcon);
  212. if (tcon->need_reconnect)
  213. seq_puts(m, "\tDISCONNECTED ");
  214. seq_putc(m, '\n');
  215. }
  216. seq_puts(m, "\n\tMIDs:\n");
  217. spin_lock(&GlobalMid_Lock);
  218. list_for_each(tmp3, &server->pending_mid_q) {
  219. mid_entry = list_entry(tmp3, struct mid_q_entry,
  220. qhead);
  221. seq_printf(m, "\tState: %d com: %d pid:"
  222. " %d cbdata: %p mid %llu\n",
  223. mid_entry->mid_state,
  224. le16_to_cpu(mid_entry->command),
  225. mid_entry->pid,
  226. mid_entry->callback_data,
  227. mid_entry->mid);
  228. }
  229. spin_unlock(&GlobalMid_Lock);
  230. }
  231. }
  232. spin_unlock(&cifs_tcp_ses_lock);
  233. seq_putc(m, '\n');
  234. /* BB add code to dump additional info such as TCP session info now */
  235. return 0;
  236. }
  237. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  238. {
  239. return single_open(file, cifs_debug_data_proc_show, NULL);
  240. }
  241. static const struct file_operations cifs_debug_data_proc_fops = {
  242. .open = cifs_debug_data_proc_open,
  243. .read = seq_read,
  244. .llseek = seq_lseek,
  245. .release = single_release,
  246. };
  247. #ifdef CONFIG_CIFS_STATS
  248. static ssize_t cifs_stats_proc_write(struct file *file,
  249. const char __user *buffer, size_t count, loff_t *ppos)
  250. {
  251. bool bv;
  252. int rc;
  253. struct list_head *tmp1, *tmp2, *tmp3;
  254. struct TCP_Server_Info *server;
  255. struct cifs_ses *ses;
  256. struct cifs_tcon *tcon;
  257. rc = kstrtobool_from_user(buffer, count, &bv);
  258. if (rc == 0) {
  259. #ifdef CONFIG_CIFS_STATS2
  260. atomic_set(&totBufAllocCount, 0);
  261. atomic_set(&totSmBufAllocCount, 0);
  262. #endif /* CONFIG_CIFS_STATS2 */
  263. atomic_set(&tcpSesReconnectCount, 0);
  264. atomic_set(&tconInfoReconnectCount, 0);
  265. spin_lock(&GlobalMid_Lock);
  266. GlobalMaxActiveXid = 0;
  267. GlobalCurrentXid = 0;
  268. spin_unlock(&GlobalMid_Lock);
  269. spin_lock(&cifs_tcp_ses_lock);
  270. list_for_each(tmp1, &cifs_tcp_ses_list) {
  271. server = list_entry(tmp1, struct TCP_Server_Info,
  272. tcp_ses_list);
  273. list_for_each(tmp2, &server->smb_ses_list) {
  274. ses = list_entry(tmp2, struct cifs_ses,
  275. smb_ses_list);
  276. list_for_each(tmp3, &ses->tcon_list) {
  277. tcon = list_entry(tmp3,
  278. struct cifs_tcon,
  279. tcon_list);
  280. atomic_set(&tcon->num_smbs_sent, 0);
  281. spin_lock(&tcon->stat_lock);
  282. tcon->bytes_read = 0;
  283. tcon->bytes_written = 0;
  284. spin_unlock(&tcon->stat_lock);
  285. if (server->ops->clear_stats)
  286. server->ops->clear_stats(tcon);
  287. }
  288. }
  289. }
  290. spin_unlock(&cifs_tcp_ses_lock);
  291. } else {
  292. return rc;
  293. }
  294. return count;
  295. }
  296. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  297. {
  298. int i;
  299. struct list_head *tmp1, *tmp2, *tmp3;
  300. struct TCP_Server_Info *server;
  301. struct cifs_ses *ses;
  302. struct cifs_tcon *tcon;
  303. seq_printf(m,
  304. "Resources in use\nCIFS Session: %d\n",
  305. sesInfoAllocCount.counter);
  306. seq_printf(m, "Share (unique mount targets): %d\n",
  307. tconInfoAllocCount.counter);
  308. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  309. bufAllocCount.counter,
  310. cifs_min_rcv + tcpSesAllocCount.counter);
  311. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  312. smBufAllocCount.counter, cifs_min_small);
  313. #ifdef CONFIG_CIFS_STATS2
  314. seq_printf(m, "Total Large %d Small %d Allocations\n",
  315. atomic_read(&totBufAllocCount),
  316. atomic_read(&totSmBufAllocCount));
  317. #endif /* CONFIG_CIFS_STATS2 */
  318. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  319. seq_printf(m,
  320. "\n%d session %d share reconnects\n",
  321. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  322. seq_printf(m,
  323. "Total vfs operations: %d maximum at one time: %d\n",
  324. GlobalCurrentXid, GlobalMaxActiveXid);
  325. i = 0;
  326. spin_lock(&cifs_tcp_ses_lock);
  327. list_for_each(tmp1, &cifs_tcp_ses_list) {
  328. server = list_entry(tmp1, struct TCP_Server_Info,
  329. tcp_ses_list);
  330. list_for_each(tmp2, &server->smb_ses_list) {
  331. ses = list_entry(tmp2, struct cifs_ses,
  332. smb_ses_list);
  333. list_for_each(tmp3, &ses->tcon_list) {
  334. tcon = list_entry(tmp3,
  335. struct cifs_tcon,
  336. tcon_list);
  337. i++;
  338. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  339. if (tcon->need_reconnect)
  340. seq_puts(m, "\tDISCONNECTED ");
  341. seq_printf(m, "\nSMBs: %d",
  342. atomic_read(&tcon->num_smbs_sent));
  343. if (server->ops->print_stats)
  344. server->ops->print_stats(m, tcon);
  345. }
  346. }
  347. }
  348. spin_unlock(&cifs_tcp_ses_lock);
  349. seq_putc(m, '\n');
  350. return 0;
  351. }
  352. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  353. {
  354. return single_open(file, cifs_stats_proc_show, NULL);
  355. }
  356. static const struct file_operations cifs_stats_proc_fops = {
  357. .open = cifs_stats_proc_open,
  358. .read = seq_read,
  359. .llseek = seq_lseek,
  360. .release = single_release,
  361. .write = cifs_stats_proc_write,
  362. };
  363. #endif /* STATS */
  364. static struct proc_dir_entry *proc_fs_cifs;
  365. static const struct file_operations cifsFYI_proc_fops;
  366. static const struct file_operations cifs_lookup_cache_proc_fops;
  367. static const struct file_operations traceSMB_proc_fops;
  368. static const struct file_operations cifs_security_flags_proc_fops;
  369. static const struct file_operations cifs_linux_ext_proc_fops;
  370. void
  371. cifs_proc_init(void)
  372. {
  373. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  374. if (proc_fs_cifs == NULL)
  375. return;
  376. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  377. #ifdef CONFIG_CIFS_STATS
  378. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  379. #endif /* STATS */
  380. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  381. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  382. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  383. &cifs_linux_ext_proc_fops);
  384. proc_create("SecurityFlags", 0, proc_fs_cifs,
  385. &cifs_security_flags_proc_fops);
  386. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  387. &cifs_lookup_cache_proc_fops);
  388. }
  389. void
  390. cifs_proc_clean(void)
  391. {
  392. if (proc_fs_cifs == NULL)
  393. return;
  394. remove_proc_entry("DebugData", proc_fs_cifs);
  395. remove_proc_entry("cifsFYI", proc_fs_cifs);
  396. remove_proc_entry("traceSMB", proc_fs_cifs);
  397. #ifdef CONFIG_CIFS_STATS
  398. remove_proc_entry("Stats", proc_fs_cifs);
  399. #endif
  400. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  401. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  402. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  403. remove_proc_entry("fs/cifs", NULL);
  404. }
  405. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  406. {
  407. seq_printf(m, "%d\n", cifsFYI);
  408. return 0;
  409. }
  410. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  411. {
  412. return single_open(file, cifsFYI_proc_show, NULL);
  413. }
  414. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  415. size_t count, loff_t *ppos)
  416. {
  417. char c[2] = { '\0' };
  418. bool bv;
  419. int rc;
  420. rc = get_user(c[0], buffer);
  421. if (rc)
  422. return rc;
  423. if (strtobool(c, &bv) == 0)
  424. cifsFYI = bv;
  425. else if ((c[0] > '1') && (c[0] <= '9'))
  426. cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
  427. return count;
  428. }
  429. static const struct file_operations cifsFYI_proc_fops = {
  430. .open = cifsFYI_proc_open,
  431. .read = seq_read,
  432. .llseek = seq_lseek,
  433. .release = single_release,
  434. .write = cifsFYI_proc_write,
  435. };
  436. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  437. {
  438. seq_printf(m, "%d\n", linuxExtEnabled);
  439. return 0;
  440. }
  441. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  442. {
  443. return single_open(file, cifs_linux_ext_proc_show, NULL);
  444. }
  445. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  446. const char __user *buffer, size_t count, loff_t *ppos)
  447. {
  448. int rc;
  449. rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
  450. if (rc)
  451. return rc;
  452. return count;
  453. }
  454. static const struct file_operations cifs_linux_ext_proc_fops = {
  455. .open = cifs_linux_ext_proc_open,
  456. .read = seq_read,
  457. .llseek = seq_lseek,
  458. .release = single_release,
  459. .write = cifs_linux_ext_proc_write,
  460. };
  461. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  462. {
  463. seq_printf(m, "%d\n", lookupCacheEnabled);
  464. return 0;
  465. }
  466. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  467. {
  468. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  469. }
  470. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  471. const char __user *buffer, size_t count, loff_t *ppos)
  472. {
  473. int rc;
  474. rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
  475. if (rc)
  476. return rc;
  477. return count;
  478. }
  479. static const struct file_operations cifs_lookup_cache_proc_fops = {
  480. .open = cifs_lookup_cache_proc_open,
  481. .read = seq_read,
  482. .llseek = seq_lseek,
  483. .release = single_release,
  484. .write = cifs_lookup_cache_proc_write,
  485. };
  486. static int traceSMB_proc_show(struct seq_file *m, void *v)
  487. {
  488. seq_printf(m, "%d\n", traceSMB);
  489. return 0;
  490. }
  491. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  492. {
  493. return single_open(file, traceSMB_proc_show, NULL);
  494. }
  495. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  496. size_t count, loff_t *ppos)
  497. {
  498. int rc;
  499. rc = kstrtobool_from_user(buffer, count, &traceSMB);
  500. if (rc)
  501. return rc;
  502. return count;
  503. }
  504. static const struct file_operations traceSMB_proc_fops = {
  505. .open = traceSMB_proc_open,
  506. .read = seq_read,
  507. .llseek = seq_lseek,
  508. .release = single_release,
  509. .write = traceSMB_proc_write,
  510. };
  511. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  512. {
  513. seq_printf(m, "0x%x\n", global_secflags);
  514. return 0;
  515. }
  516. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  517. {
  518. return single_open(file, cifs_security_flags_proc_show, NULL);
  519. }
  520. /*
  521. * Ensure that if someone sets a MUST flag, that we disable all other MAY
  522. * flags except for the ones corresponding to the given MUST flag. If there are
  523. * multiple MUST flags, then try to prefer more secure ones.
  524. */
  525. static void
  526. cifs_security_flags_handle_must_flags(unsigned int *flags)
  527. {
  528. unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
  529. if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
  530. *flags = CIFSSEC_MUST_KRB5;
  531. else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
  532. *flags = CIFSSEC_MUST_NTLMSSP;
  533. else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
  534. *flags = CIFSSEC_MUST_NTLMV2;
  535. else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
  536. *flags = CIFSSEC_MUST_NTLM;
  537. else if (CIFSSEC_MUST_LANMAN &&
  538. (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
  539. *flags = CIFSSEC_MUST_LANMAN;
  540. else if (CIFSSEC_MUST_PLNTXT &&
  541. (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
  542. *flags = CIFSSEC_MUST_PLNTXT;
  543. *flags |= signflags;
  544. }
  545. static ssize_t cifs_security_flags_proc_write(struct file *file,
  546. const char __user *buffer, size_t count, loff_t *ppos)
  547. {
  548. int rc;
  549. unsigned int flags;
  550. char flags_string[12];
  551. bool bv;
  552. if ((count < 1) || (count > 11))
  553. return -EINVAL;
  554. memset(flags_string, 0, 12);
  555. if (copy_from_user(flags_string, buffer, count))
  556. return -EFAULT;
  557. if (count < 3) {
  558. /* single char or single char followed by null */
  559. if (strtobool(flags_string, &bv) == 0) {
  560. global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
  561. return count;
  562. } else if (!isdigit(flags_string[0])) {
  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. .open = cifs_security_flags_proc_open,
  600. .read = seq_read,
  601. .llseek = seq_lseek,
  602. .release = single_release,
  603. .write = cifs_security_flags_proc_write,
  604. };
  605. #else
  606. inline void cifs_proc_init(void)
  607. {
  608. }
  609. inline void cifs_proc_clean(void)
  610. {
  611. }
  612. #endif /* PROC_FS */