cifs_debug.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * Copyright (C) International Business Machines Corp., 2000,2005
  5. *
  6. * Modified by Steve French (sfrench@us.ibm.com)
  7. */
  8. #include <linux/fs.h>
  9. #include <linux/string.h>
  10. #include <linux/ctype.h>
  11. #include <linux/kstrtox.h>
  12. #include <linux/module.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/uaccess.h>
  15. #include <uapi/linux/ethtool.h>
  16. #include "cifspdu.h"
  17. #include "cifsglob.h"
  18. #include "cifsproto.h"
  19. #include "cifs_debug.h"
  20. #include "cifsfs.h"
  21. #include "fs_context.h"
  22. #ifdef CONFIG_CIFS_DFS_UPCALL
  23. #include "dfs_cache.h"
  24. #endif
  25. #ifdef CONFIG_CIFS_SMB_DIRECT
  26. #include "smbdirect.h"
  27. #endif
  28. #include "cifs_swn.h"
  29. void
  30. cifs_dump_mem(char *label, void *data, int length)
  31. {
  32. pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
  33. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
  34. data, length, true);
  35. }
  36. void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
  37. {
  38. #ifdef CONFIG_CIFS_DEBUG2
  39. struct smb_hdr *smb = buf;
  40. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n",
  41. smb->Command, smb->Status.CifsError, smb->Flags,
  42. smb->Flags2, smb->Mid, smb->Pid, smb->WordCount);
  43. if (!server->ops->check_message(buf, server->total_read, server)) {
  44. cifs_dbg(VFS, "smb buf %p len %u\n", smb,
  45. server->ops->calc_smb_size(smb));
  46. }
  47. #endif /* CONFIG_CIFS_DEBUG2 */
  48. }
  49. void cifs_dump_mids(struct TCP_Server_Info *server)
  50. {
  51. #ifdef CONFIG_CIFS_DEBUG2
  52. struct mid_q_entry *mid_entry;
  53. if (server == NULL)
  54. return;
  55. cifs_dbg(VFS, "Dump pending requests:\n");
  56. spin_lock(&server->mid_lock);
  57. list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
  58. cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
  59. mid_entry->mid_state,
  60. le16_to_cpu(mid_entry->command),
  61. mid_entry->pid,
  62. mid_entry->callback_data,
  63. mid_entry->mid);
  64. #ifdef CONFIG_CIFS_STATS2
  65. cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
  66. mid_entry->large_buf,
  67. mid_entry->resp_buf,
  68. mid_entry->when_received,
  69. jiffies);
  70. #endif /* STATS2 */
  71. cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
  72. mid_entry->multiRsp, mid_entry->multiEnd);
  73. if (mid_entry->resp_buf) {
  74. cifs_dump_detail(mid_entry->resp_buf, server);
  75. cifs_dump_mem("existing buf: ",
  76. mid_entry->resp_buf, 62);
  77. }
  78. }
  79. spin_unlock(&server->mid_lock);
  80. #endif /* CONFIG_CIFS_DEBUG2 */
  81. }
  82. #ifdef CONFIG_PROC_FS
  83. static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
  84. {
  85. __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  86. seq_printf(m, "%s Mounts: %d ", tcon->tree_name, tcon->tc_count);
  87. if (tcon->nativeFileSystem)
  88. seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
  89. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
  90. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  91. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  92. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  93. tcon->status);
  94. if (dev_type == FILE_DEVICE_DISK)
  95. seq_puts(m, " type: DISK ");
  96. else if (dev_type == FILE_DEVICE_CD_ROM)
  97. seq_puts(m, " type: CDROM ");
  98. else
  99. seq_printf(m, " type: %d ", dev_type);
  100. seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
  101. if ((tcon->seal) ||
  102. (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
  103. (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
  104. seq_puts(m, " encrypted");
  105. if (tcon->nocase)
  106. seq_printf(m, " nocase");
  107. if (tcon->unix_ext)
  108. seq_printf(m, " POSIX Extensions");
  109. if (tcon->ses->server->ops->dump_share_caps)
  110. tcon->ses->server->ops->dump_share_caps(m, tcon);
  111. if (tcon->use_witness)
  112. seq_puts(m, " Witness");
  113. if (tcon->broken_sparse_sup)
  114. seq_puts(m, " nosparse");
  115. if (tcon->need_reconnect)
  116. seq_puts(m, "\tDISCONNECTED ");
  117. spin_lock(&tcon->tc_lock);
  118. if (tcon->origin_fullpath) {
  119. seq_printf(m, "\n\tDFS origin fullpath: %s",
  120. tcon->origin_fullpath);
  121. }
  122. spin_unlock(&tcon->tc_lock);
  123. seq_putc(m, '\n');
  124. }
  125. static void
  126. cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
  127. {
  128. struct TCP_Server_Info *server = chan->server;
  129. if (!server) {
  130. seq_printf(m, "\n\n\t\tChannel: %d DISABLED", i+1);
  131. return;
  132. }
  133. seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
  134. "\n\t\tNumber of credits: %d,%d,%d Dialect 0x%x"
  135. "\n\t\tTCP status: %d Instance: %d"
  136. "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
  137. "\n\t\tIn Send: %d In MaxReq Wait: %d",
  138. i+1, server->conn_id,
  139. server->credits,
  140. server->echo_credits,
  141. server->oplock_credits,
  142. server->dialect,
  143. server->tcpStatus,
  144. server->reconnect_instance,
  145. server->srv_count,
  146. server->sec_mode,
  147. in_flight(server),
  148. atomic_read(&server->in_send),
  149. atomic_read(&server->num_waiters));
  150. #ifdef CONFIG_NET_NS
  151. if (server->net)
  152. seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
  153. #endif /* NET_NS */
  154. }
  155. static inline const char *smb_speed_to_str(size_t bps)
  156. {
  157. size_t mbps = bps / 1000 / 1000;
  158. switch (mbps) {
  159. case SPEED_10:
  160. return "10Mbps";
  161. case SPEED_100:
  162. return "100Mbps";
  163. case SPEED_1000:
  164. return "1Gbps";
  165. case SPEED_2500:
  166. return "2.5Gbps";
  167. case SPEED_5000:
  168. return "5Gbps";
  169. case SPEED_10000:
  170. return "10Gbps";
  171. case SPEED_14000:
  172. return "14Gbps";
  173. case SPEED_20000:
  174. return "20Gbps";
  175. case SPEED_25000:
  176. return "25Gbps";
  177. case SPEED_40000:
  178. return "40Gbps";
  179. case SPEED_50000:
  180. return "50Gbps";
  181. case SPEED_56000:
  182. return "56Gbps";
  183. case SPEED_100000:
  184. return "100Gbps";
  185. case SPEED_200000:
  186. return "200Gbps";
  187. case SPEED_400000:
  188. return "400Gbps";
  189. case SPEED_800000:
  190. return "800Gbps";
  191. default:
  192. return "Unknown";
  193. }
  194. }
  195. static void
  196. cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
  197. {
  198. struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
  199. struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
  200. seq_printf(m, "\tSpeed: %s\n", smb_speed_to_str(iface->speed));
  201. seq_puts(m, "\t\tCapabilities: ");
  202. if (iface->rdma_capable)
  203. seq_puts(m, "rdma ");
  204. if (iface->rss_capable)
  205. seq_puts(m, "rss ");
  206. if (!iface->rdma_capable && !iface->rss_capable)
  207. seq_puts(m, "None");
  208. seq_putc(m, '\n');
  209. if (iface->sockaddr.ss_family == AF_INET)
  210. seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
  211. else if (iface->sockaddr.ss_family == AF_INET6)
  212. seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
  213. if (!iface->is_active)
  214. seq_puts(m, "\t\t[for-cleanup]\n");
  215. }
  216. static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
  217. {
  218. struct TCP_Server_Info *server;
  219. struct cifs_ses *ses;
  220. struct cifs_tcon *tcon;
  221. struct cifsFileInfo *cfile;
  222. seq_puts(m, "# Version:1\n");
  223. seq_puts(m, "# Format:\n");
  224. seq_puts(m, "# <tree id> <ses id> <persistent fid> <flags> <count> <pid> <uid>");
  225. #ifdef CONFIG_CIFS_DEBUG2
  226. seq_printf(m, " <filename> <mid>\n");
  227. #else
  228. seq_printf(m, " <filename>\n");
  229. #endif /* CIFS_DEBUG2 */
  230. spin_lock(&cifs_tcp_ses_lock);
  231. list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
  232. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  233. if (cifs_ses_exiting(ses))
  234. continue;
  235. list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
  236. spin_lock(&tcon->open_file_lock);
  237. list_for_each_entry(cfile, &tcon->openFileList, tlist) {
  238. seq_printf(m,
  239. "0x%x 0x%llx 0x%llx 0x%x %d %d %d %pd",
  240. tcon->tid,
  241. ses->Suid,
  242. cfile->fid.persistent_fid,
  243. cfile->f_flags,
  244. cfile->count,
  245. cfile->pid,
  246. from_kuid(&init_user_ns, cfile->uid),
  247. cfile->dentry);
  248. #ifdef CONFIG_CIFS_DEBUG2
  249. seq_printf(m, " %llu\n", cfile->fid.mid);
  250. #else
  251. seq_printf(m, "\n");
  252. #endif /* CIFS_DEBUG2 */
  253. }
  254. spin_unlock(&tcon->open_file_lock);
  255. }
  256. }
  257. }
  258. spin_unlock(&cifs_tcp_ses_lock);
  259. seq_putc(m, '\n');
  260. return 0;
  261. }
  262. static __always_inline const char *compression_alg_str(__le16 alg)
  263. {
  264. switch (alg) {
  265. case SMB3_COMPRESS_NONE:
  266. return "NONE";
  267. case SMB3_COMPRESS_LZNT1:
  268. return "LZNT1";
  269. case SMB3_COMPRESS_LZ77:
  270. return "LZ77";
  271. case SMB3_COMPRESS_LZ77_HUFF:
  272. return "LZ77-Huffman";
  273. case SMB3_COMPRESS_PATTERN:
  274. return "Pattern_V1";
  275. default:
  276. return "invalid";
  277. }
  278. }
  279. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  280. {
  281. struct mid_q_entry *mid_entry;
  282. struct TCP_Server_Info *server;
  283. struct TCP_Server_Info *chan_server;
  284. struct cifs_ses *ses;
  285. struct cifs_tcon *tcon;
  286. struct cifs_server_iface *iface;
  287. size_t iface_weight = 0, iface_min_speed = 0;
  288. struct cifs_server_iface *last_iface = NULL;
  289. int c, i, j;
  290. seq_puts(m,
  291. "Display Internal CIFS Data Structures for Debugging\n"
  292. "---------------------------------------------------\n");
  293. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  294. seq_printf(m, "Features:");
  295. #ifdef CONFIG_CIFS_DFS_UPCALL
  296. seq_printf(m, " DFS");
  297. #endif
  298. #ifdef CONFIG_CIFS_FSCACHE
  299. seq_printf(m, ",FSCACHE");
  300. #endif
  301. #ifdef CONFIG_CIFS_SMB_DIRECT
  302. seq_printf(m, ",SMB_DIRECT");
  303. #endif
  304. #ifdef CONFIG_CIFS_STATS2
  305. seq_printf(m, ",STATS2");
  306. #else
  307. seq_printf(m, ",STATS");
  308. #endif
  309. #ifdef CONFIG_CIFS_DEBUG2
  310. seq_printf(m, ",DEBUG2");
  311. #elif defined(CONFIG_CIFS_DEBUG)
  312. seq_printf(m, ",DEBUG");
  313. #endif
  314. #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
  315. seq_printf(m, ",ALLOW_INSECURE_LEGACY");
  316. #endif
  317. #ifdef CONFIG_CIFS_POSIX
  318. seq_printf(m, ",CIFS_POSIX");
  319. #endif
  320. #ifdef CONFIG_CIFS_UPCALL
  321. seq_printf(m, ",UPCALL(SPNEGO)");
  322. #endif
  323. #ifdef CONFIG_CIFS_XATTR
  324. seq_printf(m, ",XATTR");
  325. #endif
  326. seq_printf(m, ",ACL");
  327. #ifdef CONFIG_CIFS_SWN_UPCALL
  328. seq_puts(m, ",WITNESS");
  329. #endif
  330. #ifdef CONFIG_CIFS_COMPRESSION
  331. seq_puts(m, ",COMPRESSION");
  332. #endif
  333. seq_putc(m, '\n');
  334. seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
  335. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  336. seq_printf(m, "\nServers: ");
  337. c = 0;
  338. spin_lock(&cifs_tcp_ses_lock);
  339. list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
  340. #ifdef CONFIG_CIFS_SMB_DIRECT
  341. struct smbdirect_socket_parameters *sp;
  342. #endif
  343. /* channel info will be printed as a part of sessions below */
  344. if (SERVER_IS_CHAN(server))
  345. continue;
  346. c++;
  347. seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
  348. c, server->conn_id);
  349. spin_lock(&server->srv_lock);
  350. if (server->hostname)
  351. seq_printf(m, "Hostname: %s ", server->hostname);
  352. seq_printf(m, "\nClientGUID: %pUL", server->client_guid);
  353. spin_unlock(&server->srv_lock);
  354. #ifdef CONFIG_CIFS_SMB_DIRECT
  355. if (!server->rdma)
  356. goto skip_rdma;
  357. if (!server->smbd_conn) {
  358. seq_printf(m, "\nSMBDirect transport not available");
  359. goto skip_rdma;
  360. }
  361. sp = &server->smbd_conn->socket.parameters;
  362. seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
  363. "transport status: %x",
  364. server->smbd_conn->protocol,
  365. server->smbd_conn->socket.status);
  366. seq_printf(m, "\nConn receive_credit_max: %x "
  367. "send_credit_target: %x max_send_size: %x",
  368. sp->recv_credit_max,
  369. sp->send_credit_target,
  370. sp->max_send_size);
  371. seq_printf(m, "\nConn max_fragmented_recv_size: %x "
  372. "max_fragmented_send_size: %x max_receive_size:%x",
  373. sp->max_fragmented_recv_size,
  374. sp->max_fragmented_send_size,
  375. sp->max_recv_size);
  376. seq_printf(m, "\nConn keep_alive_interval: %x "
  377. "max_readwrite_size: %x rdma_readwrite_threshold: %x",
  378. sp->keepalive_interval_msec * 1000,
  379. sp->max_read_write_size,
  380. server->smbd_conn->rdma_readwrite_threshold);
  381. seq_printf(m, "\nDebug count_get_receive_buffer: %x "
  382. "count_put_receive_buffer: %x count_send_empty: %x",
  383. server->smbd_conn->count_get_receive_buffer,
  384. server->smbd_conn->count_put_receive_buffer,
  385. server->smbd_conn->count_send_empty);
  386. seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
  387. "count_enqueue_reassembly_queue: %x "
  388. "count_dequeue_reassembly_queue: %x "
  389. "fragment_reassembly_remaining: %x "
  390. "reassembly_data_length: %x "
  391. "reassembly_queue_length: %x",
  392. server->smbd_conn->count_reassembly_queue,
  393. server->smbd_conn->count_enqueue_reassembly_queue,
  394. server->smbd_conn->count_dequeue_reassembly_queue,
  395. server->smbd_conn->fragment_reassembly_remaining,
  396. server->smbd_conn->reassembly_data_length,
  397. server->smbd_conn->reassembly_queue_length);
  398. seq_printf(m, "\nCurrent Credits send_credits: %x "
  399. "receive_credits: %x receive_credit_target: %x",
  400. atomic_read(&server->smbd_conn->send_credits),
  401. atomic_read(&server->smbd_conn->receive_credits),
  402. server->smbd_conn->receive_credit_target);
  403. seq_printf(m, "\nPending send_pending: %x ",
  404. atomic_read(&server->smbd_conn->send_pending));
  405. seq_printf(m, "\nReceive buffers count_receive_queue: %x ",
  406. server->smbd_conn->count_receive_queue);
  407. seq_printf(m, "\nMR responder_resources: %x "
  408. "max_frmr_depth: %x mr_type: %x",
  409. server->smbd_conn->responder_resources,
  410. server->smbd_conn->max_frmr_depth,
  411. server->smbd_conn->mr_type);
  412. seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
  413. atomic_read(&server->smbd_conn->mr_ready_count),
  414. atomic_read(&server->smbd_conn->mr_used_count));
  415. skip_rdma:
  416. #endif
  417. seq_printf(m, "\nNumber of credits: %d,%d,%d Dialect 0x%x",
  418. server->credits,
  419. server->echo_credits,
  420. server->oplock_credits,
  421. server->dialect);
  422. if (server->sign)
  423. seq_printf(m, " signed");
  424. if (server->posix_ext_supported)
  425. seq_printf(m, " posix");
  426. if (server->nosharesock)
  427. seq_printf(m, " nosharesock");
  428. seq_printf(m, "\nServer capabilities: 0x%x", server->capabilities);
  429. if (server->rdma)
  430. seq_printf(m, "\nRDMA ");
  431. seq_printf(m, "\nTCP status: %d Instance: %d"
  432. "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
  433. server->tcpStatus,
  434. server->reconnect_instance,
  435. server->srv_count,
  436. server->sec_mode, in_flight(server));
  437. #ifdef CONFIG_NET_NS
  438. if (server->net)
  439. seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
  440. #endif /* NET_NS */
  441. seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
  442. atomic_read(&server->in_send),
  443. atomic_read(&server->num_waiters));
  444. if (server->leaf_fullpath) {
  445. seq_printf(m, "\nDFS leaf full path: %s",
  446. server->leaf_fullpath);
  447. }
  448. seq_puts(m, "\nCompression: ");
  449. if (!IS_ENABLED(CONFIG_CIFS_COMPRESSION))
  450. seq_puts(m, "no built-in support");
  451. else if (!server->compression.requested)
  452. seq_puts(m, "disabled on mount");
  453. else if (server->compression.enabled)
  454. seq_printf(m, "enabled (%s)", compression_alg_str(server->compression.alg));
  455. else
  456. seq_puts(m, "disabled (not supported by this server)");
  457. seq_printf(m, "\n\n\tSessions: ");
  458. i = 0;
  459. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  460. spin_lock(&ses->ses_lock);
  461. if (ses->ses_status == SES_EXITING) {
  462. spin_unlock(&ses->ses_lock);
  463. continue;
  464. }
  465. i++;
  466. if ((ses->serverDomain == NULL) ||
  467. (ses->serverOS == NULL) ||
  468. (ses->serverNOS == NULL)) {
  469. seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
  470. i, ses->ip_addr, ses->ses_count,
  471. ses->capabilities, ses->ses_status);
  472. if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
  473. seq_printf(m, "Guest ");
  474. else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
  475. seq_printf(m, "Anonymous ");
  476. } else {
  477. seq_printf(m,
  478. "\n\t%d) Name: %s Domain: %s Uses: %d OS: %s "
  479. "\n\tNOS: %s\tCapability: 0x%x"
  480. "\n\tSMB session status: %d ",
  481. i, ses->ip_addr, ses->serverDomain,
  482. ses->ses_count, ses->serverOS, ses->serverNOS,
  483. ses->capabilities, ses->ses_status);
  484. }
  485. if (ses->expired_pwd)
  486. seq_puts(m, "password no longer valid ");
  487. spin_unlock(&ses->ses_lock);
  488. seq_printf(m, "\n\tSecurity type: %s ",
  489. get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
  490. /* dump session id helpful for use with network trace */
  491. seq_printf(m, " SessionId: 0x%llx", ses->Suid);
  492. if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) {
  493. seq_puts(m, " encrypted");
  494. /* can help in debugging to show encryption type */
  495. if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
  496. seq_puts(m, "(gcm256)");
  497. }
  498. if (ses->sign)
  499. seq_puts(m, " signed");
  500. seq_printf(m, "\n\tUser: %d Cred User: %d",
  501. from_kuid(&init_user_ns, ses->linux_uid),
  502. from_kuid(&init_user_ns, ses->cred_uid));
  503. if (ses->dfs_root_ses) {
  504. seq_printf(m, "\n\tDFS root session id: 0x%llx",
  505. ses->dfs_root_ses->Suid);
  506. }
  507. spin_lock(&ses->chan_lock);
  508. if (CIFS_CHAN_NEEDS_RECONNECT(ses, 0))
  509. seq_puts(m, "\tPrimary channel: DISCONNECTED ");
  510. if (CIFS_CHAN_IN_RECONNECT(ses, 0))
  511. seq_puts(m, "\t[RECONNECTING] ");
  512. if (ses->chan_count > 1) {
  513. seq_printf(m, "\n\n\tExtra Channels: %zu ",
  514. ses->chan_count-1);
  515. for (j = 1; j < ses->chan_count; j++) {
  516. cifs_dump_channel(m, j, &ses->chans[j]);
  517. if (CIFS_CHAN_NEEDS_RECONNECT(ses, j))
  518. seq_puts(m, "\tDISCONNECTED ");
  519. if (CIFS_CHAN_IN_RECONNECT(ses, j))
  520. seq_puts(m, "\t[RECONNECTING] ");
  521. }
  522. }
  523. spin_unlock(&ses->chan_lock);
  524. seq_puts(m, "\n\n\tShares: ");
  525. j = 0;
  526. seq_printf(m, "\n\t%d) IPC: ", j);
  527. if (ses->tcon_ipc)
  528. cifs_debug_tcon(m, ses->tcon_ipc);
  529. else
  530. seq_puts(m, "none\n");
  531. list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
  532. ++j;
  533. seq_printf(m, "\n\t%d) ", j);
  534. cifs_debug_tcon(m, tcon);
  535. }
  536. spin_lock(&ses->iface_lock);
  537. if (ses->iface_count)
  538. seq_printf(m, "\n\n\tServer interfaces: %zu"
  539. "\tLast updated: %lu seconds ago",
  540. ses->iface_count,
  541. (jiffies - ses->iface_last_update) / HZ);
  542. last_iface = list_last_entry(&ses->iface_list,
  543. struct cifs_server_iface,
  544. iface_head);
  545. iface_min_speed = last_iface->speed;
  546. j = 0;
  547. list_for_each_entry(iface, &ses->iface_list,
  548. iface_head) {
  549. seq_printf(m, "\n\t%d)", ++j);
  550. cifs_dump_iface(m, iface);
  551. iface_weight = iface->speed / iface_min_speed;
  552. seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)"
  553. "\n\t\tAllocated channels: %u\n",
  554. iface->weight_fulfilled,
  555. iface_weight,
  556. iface->num_channels);
  557. if (is_ses_using_iface(ses, iface))
  558. seq_puts(m, "\t\t[CONNECTED]\n");
  559. }
  560. spin_unlock(&ses->iface_lock);
  561. seq_puts(m, "\n\n\tMIDs: ");
  562. spin_lock(&ses->chan_lock);
  563. for (j = 0; j < ses->chan_count; j++) {
  564. chan_server = ses->chans[j].server;
  565. if (!chan_server)
  566. continue;
  567. if (list_empty(&chan_server->pending_mid_q))
  568. continue;
  569. seq_printf(m, "\n\tServer ConnectionId: 0x%llx",
  570. chan_server->conn_id);
  571. spin_lock(&chan_server->mid_lock);
  572. list_for_each_entry(mid_entry, &chan_server->pending_mid_q, qhead) {
  573. seq_printf(m, "\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu",
  574. mid_entry->mid_state,
  575. le16_to_cpu(mid_entry->command),
  576. mid_entry->pid,
  577. mid_entry->callback_data,
  578. mid_entry->mid);
  579. }
  580. spin_unlock(&chan_server->mid_lock);
  581. }
  582. spin_unlock(&ses->chan_lock);
  583. seq_puts(m, "\n--\n");
  584. }
  585. if (i == 0)
  586. seq_printf(m, "\n\t\t[NONE]");
  587. }
  588. if (c == 0)
  589. seq_printf(m, "\n\t[NONE]");
  590. spin_unlock(&cifs_tcp_ses_lock);
  591. seq_putc(m, '\n');
  592. cifs_swn_dump(m);
  593. /* BB add code to dump additional info such as TCP session info now */
  594. return 0;
  595. }
  596. static ssize_t cifs_stats_proc_write(struct file *file,
  597. const char __user *buffer, size_t count, loff_t *ppos)
  598. {
  599. bool bv;
  600. int rc;
  601. struct TCP_Server_Info *server;
  602. struct cifs_ses *ses;
  603. struct cifs_tcon *tcon;
  604. rc = kstrtobool_from_user(buffer, count, &bv);
  605. if (rc == 0) {
  606. #ifdef CONFIG_CIFS_STATS2
  607. int i;
  608. atomic_set(&total_buf_alloc_count, 0);
  609. atomic_set(&total_small_buf_alloc_count, 0);
  610. #endif /* CONFIG_CIFS_STATS2 */
  611. atomic_set(&tcpSesReconnectCount, 0);
  612. atomic_set(&tconInfoReconnectCount, 0);
  613. spin_lock(&GlobalMid_Lock);
  614. GlobalMaxActiveXid = 0;
  615. GlobalCurrentXid = 0;
  616. spin_unlock(&GlobalMid_Lock);
  617. spin_lock(&cifs_tcp_ses_lock);
  618. list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
  619. server->max_in_flight = 0;
  620. #ifdef CONFIG_CIFS_STATS2
  621. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  622. atomic_set(&server->num_cmds[i], 0);
  623. atomic_set(&server->smb2slowcmd[i], 0);
  624. server->time_per_cmd[i] = 0;
  625. server->slowest_cmd[i] = 0;
  626. server->fastest_cmd[0] = 0;
  627. }
  628. #endif /* CONFIG_CIFS_STATS2 */
  629. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  630. if (cifs_ses_exiting(ses))
  631. continue;
  632. list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
  633. atomic_set(&tcon->num_smbs_sent, 0);
  634. spin_lock(&tcon->stat_lock);
  635. tcon->bytes_read = 0;
  636. tcon->bytes_written = 0;
  637. tcon->stats_from_time = ktime_get_real_seconds();
  638. spin_unlock(&tcon->stat_lock);
  639. if (server->ops->clear_stats)
  640. server->ops->clear_stats(tcon);
  641. }
  642. }
  643. }
  644. spin_unlock(&cifs_tcp_ses_lock);
  645. } else {
  646. return rc;
  647. }
  648. return count;
  649. }
  650. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  651. {
  652. int i;
  653. #ifdef CONFIG_CIFS_STATS2
  654. int j;
  655. #endif /* STATS2 */
  656. struct TCP_Server_Info *server;
  657. struct cifs_ses *ses;
  658. struct cifs_tcon *tcon;
  659. seq_printf(m, "Resources in use\nCIFS Session: %d\n",
  660. sesInfoAllocCount.counter);
  661. seq_printf(m, "Share (unique mount targets): %d\n",
  662. tconInfoAllocCount.counter);
  663. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  664. buf_alloc_count.counter,
  665. cifs_min_rcv + tcpSesAllocCount.counter);
  666. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  667. small_buf_alloc_count.counter, cifs_min_small);
  668. #ifdef CONFIG_CIFS_STATS2
  669. seq_printf(m, "Total Large %d Small %d Allocations\n",
  670. atomic_read(&total_buf_alloc_count),
  671. atomic_read(&total_small_buf_alloc_count));
  672. #endif /* CONFIG_CIFS_STATS2 */
  673. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
  674. seq_printf(m,
  675. "\n%d session %d share reconnects\n",
  676. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  677. seq_printf(m,
  678. "Total vfs operations: %d maximum at one time: %d\n",
  679. GlobalCurrentXid, GlobalMaxActiveXid);
  680. i = 0;
  681. spin_lock(&cifs_tcp_ses_lock);
  682. list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
  683. seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
  684. #ifdef CONFIG_CIFS_STATS2
  685. seq_puts(m, "\nTotal time spent processing by command. Time ");
  686. seq_printf(m, "units are jiffies (%d per second)\n", HZ);
  687. seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
  688. seq_puts(m, " --------\t------\t----------\t-------\t-------\n");
  689. for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
  690. seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j,
  691. atomic_read(&server->num_cmds[j]),
  692. server->time_per_cmd[j],
  693. server->fastest_cmd[j],
  694. server->slowest_cmd[j]);
  695. for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
  696. if (atomic_read(&server->smb2slowcmd[j])) {
  697. spin_lock(&server->srv_lock);
  698. seq_printf(m, " %d slow responses from %s for command %d\n",
  699. atomic_read(&server->smb2slowcmd[j]),
  700. server->hostname, j);
  701. spin_unlock(&server->srv_lock);
  702. }
  703. #endif /* STATS2 */
  704. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  705. if (cifs_ses_exiting(ses))
  706. continue;
  707. list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
  708. i++;
  709. seq_printf(m, "\n%d) %s", i, tcon->tree_name);
  710. if (tcon->need_reconnect)
  711. seq_puts(m, "\tDISCONNECTED ");
  712. seq_printf(m, "\nSMBs: %d since %ptTs UTC",
  713. atomic_read(&tcon->num_smbs_sent),
  714. &tcon->stats_from_time);
  715. if (server->ops->print_stats)
  716. server->ops->print_stats(m, tcon);
  717. }
  718. }
  719. }
  720. spin_unlock(&cifs_tcp_ses_lock);
  721. seq_putc(m, '\n');
  722. return 0;
  723. }
  724. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  725. {
  726. return single_open(file, cifs_stats_proc_show, NULL);
  727. }
  728. static const struct proc_ops cifs_stats_proc_ops = {
  729. .proc_open = cifs_stats_proc_open,
  730. .proc_read = seq_read,
  731. .proc_lseek = seq_lseek,
  732. .proc_release = single_release,
  733. .proc_write = cifs_stats_proc_write,
  734. };
  735. #ifdef CONFIG_CIFS_SMB_DIRECT
  736. #define PROC_FILE_DEFINE(name) \
  737. static ssize_t name##_write(struct file *file, const char __user *buffer, \
  738. size_t count, loff_t *ppos) \
  739. { \
  740. int rc; \
  741. rc = kstrtoint_from_user(buffer, count, 10, &name); \
  742. if (rc) \
  743. return rc; \
  744. return count; \
  745. } \
  746. static int name##_proc_show(struct seq_file *m, void *v) \
  747. { \
  748. seq_printf(m, "%d\n", name); \
  749. return 0; \
  750. } \
  751. static int name##_open(struct inode *inode, struct file *file) \
  752. { \
  753. return single_open(file, name##_proc_show, NULL); \
  754. } \
  755. \
  756. static const struct proc_ops cifs_##name##_proc_fops = { \
  757. .proc_open = name##_open, \
  758. .proc_read = seq_read, \
  759. .proc_lseek = seq_lseek, \
  760. .proc_release = single_release, \
  761. .proc_write = name##_write, \
  762. }
  763. PROC_FILE_DEFINE(rdma_readwrite_threshold);
  764. PROC_FILE_DEFINE(smbd_max_frmr_depth);
  765. PROC_FILE_DEFINE(smbd_keep_alive_interval);
  766. PROC_FILE_DEFINE(smbd_max_receive_size);
  767. PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
  768. PROC_FILE_DEFINE(smbd_max_send_size);
  769. PROC_FILE_DEFINE(smbd_send_credit_target);
  770. PROC_FILE_DEFINE(smbd_receive_credit_max);
  771. #endif
  772. static struct proc_dir_entry *proc_fs_cifs;
  773. static const struct proc_ops cifsFYI_proc_ops;
  774. static const struct proc_ops cifs_lookup_cache_proc_ops;
  775. static const struct proc_ops traceSMB_proc_ops;
  776. static const struct proc_ops cifs_security_flags_proc_ops;
  777. static const struct proc_ops cifs_linux_ext_proc_ops;
  778. static const struct proc_ops cifs_mount_params_proc_ops;
  779. void
  780. cifs_proc_init(void)
  781. {
  782. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  783. if (proc_fs_cifs == NULL)
  784. return;
  785. proc_create_single("DebugData", 0, proc_fs_cifs,
  786. cifs_debug_data_proc_show);
  787. proc_create_single("open_files", 0400, proc_fs_cifs,
  788. cifs_debug_files_proc_show);
  789. proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
  790. proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
  791. proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
  792. proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
  793. &cifs_linux_ext_proc_ops);
  794. proc_create("SecurityFlags", 0644, proc_fs_cifs,
  795. &cifs_security_flags_proc_ops);
  796. proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
  797. &cifs_lookup_cache_proc_ops);
  798. proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
  799. #ifdef CONFIG_CIFS_DFS_UPCALL
  800. proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
  801. #endif
  802. #ifdef CONFIG_CIFS_SMB_DIRECT
  803. proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
  804. &cifs_rdma_readwrite_threshold_proc_fops);
  805. proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
  806. &cifs_smbd_max_frmr_depth_proc_fops);
  807. proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
  808. &cifs_smbd_keep_alive_interval_proc_fops);
  809. proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
  810. &cifs_smbd_max_receive_size_proc_fops);
  811. proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
  812. &cifs_smbd_max_fragmented_recv_size_proc_fops);
  813. proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
  814. &cifs_smbd_max_send_size_proc_fops);
  815. proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
  816. &cifs_smbd_send_credit_target_proc_fops);
  817. proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
  818. &cifs_smbd_receive_credit_max_proc_fops);
  819. #endif
  820. }
  821. void
  822. cifs_proc_clean(void)
  823. {
  824. if (proc_fs_cifs == NULL)
  825. return;
  826. remove_proc_entry("DebugData", proc_fs_cifs);
  827. remove_proc_entry("open_files", proc_fs_cifs);
  828. remove_proc_entry("cifsFYI", proc_fs_cifs);
  829. remove_proc_entry("traceSMB", proc_fs_cifs);
  830. remove_proc_entry("Stats", proc_fs_cifs);
  831. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  832. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  833. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  834. remove_proc_entry("mount_params", proc_fs_cifs);
  835. #ifdef CONFIG_CIFS_DFS_UPCALL
  836. remove_proc_entry("dfscache", proc_fs_cifs);
  837. #endif
  838. #ifdef CONFIG_CIFS_SMB_DIRECT
  839. remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
  840. remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
  841. remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
  842. remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
  843. remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
  844. remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
  845. remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
  846. remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
  847. #endif
  848. remove_proc_entry("fs/cifs", NULL);
  849. }
  850. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  851. {
  852. seq_printf(m, "%d\n", cifsFYI);
  853. return 0;
  854. }
  855. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  856. {
  857. return single_open(file, cifsFYI_proc_show, NULL);
  858. }
  859. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  860. size_t count, loff_t *ppos)
  861. {
  862. char c[2] = { '\0' };
  863. bool bv;
  864. int rc;
  865. rc = get_user(c[0], buffer);
  866. if (rc)
  867. return rc;
  868. if (kstrtobool(c, &bv) == 0)
  869. cifsFYI = bv;
  870. else if ((c[0] > '1') && (c[0] <= '9'))
  871. cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
  872. else
  873. return -EINVAL;
  874. return count;
  875. }
  876. static const struct proc_ops cifsFYI_proc_ops = {
  877. .proc_open = cifsFYI_proc_open,
  878. .proc_read = seq_read,
  879. .proc_lseek = seq_lseek,
  880. .proc_release = single_release,
  881. .proc_write = cifsFYI_proc_write,
  882. };
  883. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  884. {
  885. seq_printf(m, "%d\n", linuxExtEnabled);
  886. return 0;
  887. }
  888. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  889. {
  890. return single_open(file, cifs_linux_ext_proc_show, NULL);
  891. }
  892. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  893. const char __user *buffer, size_t count, loff_t *ppos)
  894. {
  895. int rc;
  896. rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
  897. if (rc)
  898. return rc;
  899. return count;
  900. }
  901. static const struct proc_ops cifs_linux_ext_proc_ops = {
  902. .proc_open = cifs_linux_ext_proc_open,
  903. .proc_read = seq_read,
  904. .proc_lseek = seq_lseek,
  905. .proc_release = single_release,
  906. .proc_write = cifs_linux_ext_proc_write,
  907. };
  908. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  909. {
  910. seq_printf(m, "%d\n", lookupCacheEnabled);
  911. return 0;
  912. }
  913. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  914. {
  915. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  916. }
  917. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  918. const char __user *buffer, size_t count, loff_t *ppos)
  919. {
  920. int rc;
  921. rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
  922. if (rc)
  923. return rc;
  924. return count;
  925. }
  926. static const struct proc_ops cifs_lookup_cache_proc_ops = {
  927. .proc_open = cifs_lookup_cache_proc_open,
  928. .proc_read = seq_read,
  929. .proc_lseek = seq_lseek,
  930. .proc_release = single_release,
  931. .proc_write = cifs_lookup_cache_proc_write,
  932. };
  933. static int traceSMB_proc_show(struct seq_file *m, void *v)
  934. {
  935. seq_printf(m, "%d\n", traceSMB);
  936. return 0;
  937. }
  938. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  939. {
  940. return single_open(file, traceSMB_proc_show, NULL);
  941. }
  942. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  943. size_t count, loff_t *ppos)
  944. {
  945. int rc;
  946. rc = kstrtobool_from_user(buffer, count, &traceSMB);
  947. if (rc)
  948. return rc;
  949. return count;
  950. }
  951. static const struct proc_ops traceSMB_proc_ops = {
  952. .proc_open = traceSMB_proc_open,
  953. .proc_read = seq_read,
  954. .proc_lseek = seq_lseek,
  955. .proc_release = single_release,
  956. .proc_write = traceSMB_proc_write,
  957. };
  958. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  959. {
  960. seq_printf(m, "0x%x\n", global_secflags);
  961. return 0;
  962. }
  963. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  964. {
  965. return single_open(file, cifs_security_flags_proc_show, NULL);
  966. }
  967. /*
  968. * Ensure that if someone sets a MUST flag, that we disable all other MAY
  969. * flags except for the ones corresponding to the given MUST flag. If there are
  970. * multiple MUST flags, then try to prefer more secure ones.
  971. */
  972. static void
  973. cifs_security_flags_handle_must_flags(unsigned int *flags)
  974. {
  975. unsigned int signflags = *flags & (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL);
  976. if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
  977. *flags = CIFSSEC_MUST_KRB5;
  978. else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
  979. *flags = CIFSSEC_MUST_NTLMSSP;
  980. else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
  981. *flags = CIFSSEC_MUST_NTLMV2;
  982. *flags |= signflags;
  983. }
  984. static ssize_t cifs_security_flags_proc_write(struct file *file,
  985. const char __user *buffer, size_t count, loff_t *ppos)
  986. {
  987. int rc;
  988. unsigned int flags;
  989. char flags_string[12];
  990. bool bv;
  991. if ((count < 1) || (count > 11))
  992. return -EINVAL;
  993. memset(flags_string, 0, 12);
  994. if (copy_from_user(flags_string, buffer, count))
  995. return -EFAULT;
  996. if (count < 3) {
  997. /* single char or single char followed by null */
  998. if (kstrtobool(flags_string, &bv) == 0) {
  999. global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
  1000. return count;
  1001. } else if (!isdigit(flags_string[0])) {
  1002. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  1003. flags_string);
  1004. return -EINVAL;
  1005. }
  1006. }
  1007. /* else we have a number */
  1008. rc = kstrtouint(flags_string, 0, &flags);
  1009. if (rc) {
  1010. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  1011. flags_string);
  1012. return rc;
  1013. }
  1014. cifs_dbg(FYI, "sec flags 0x%x\n", flags);
  1015. if (flags == 0) {
  1016. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
  1017. return -EINVAL;
  1018. }
  1019. if (flags & ~CIFSSEC_MASK) {
  1020. cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
  1021. flags & ~CIFSSEC_MASK);
  1022. return -EINVAL;
  1023. }
  1024. cifs_security_flags_handle_must_flags(&flags);
  1025. /* flags look ok - update the global security flags for cifs module */
  1026. global_secflags = flags;
  1027. if (global_secflags & CIFSSEC_MUST_SIGN) {
  1028. /* requiring signing implies signing is allowed */
  1029. global_secflags |= CIFSSEC_MAY_SIGN;
  1030. cifs_dbg(FYI, "packet signing now required\n");
  1031. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  1032. cifs_dbg(FYI, "packet signing disabled\n");
  1033. }
  1034. /* BB should we turn on MAY flags for other MUST options? */
  1035. return count;
  1036. }
  1037. static const struct proc_ops cifs_security_flags_proc_ops = {
  1038. .proc_open = cifs_security_flags_proc_open,
  1039. .proc_read = seq_read,
  1040. .proc_lseek = seq_lseek,
  1041. .proc_release = single_release,
  1042. .proc_write = cifs_security_flags_proc_write,
  1043. };
  1044. /* To make it easier to debug, can help to show mount params */
  1045. static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
  1046. {
  1047. const struct fs_parameter_spec *p;
  1048. const char *type;
  1049. for (p = smb3_fs_parameters; p->name; p++) {
  1050. /* cannot use switch with pointers... */
  1051. if (!p->type) {
  1052. if (p->flags == fs_param_neg_with_no)
  1053. type = "noflag";
  1054. else
  1055. type = "flag";
  1056. } else if (p->type == fs_param_is_bool)
  1057. type = "bool";
  1058. else if (p->type == fs_param_is_u32)
  1059. type = "u32";
  1060. else if (p->type == fs_param_is_u64)
  1061. type = "u64";
  1062. else if (p->type == fs_param_is_string)
  1063. type = "string";
  1064. else
  1065. type = "unknown";
  1066. seq_printf(m, "%s:%s\n", p->name, type);
  1067. }
  1068. return 0;
  1069. }
  1070. static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
  1071. {
  1072. return single_open(file, cifs_mount_params_proc_show, NULL);
  1073. }
  1074. static const struct proc_ops cifs_mount_params_proc_ops = {
  1075. .proc_open = cifs_mount_params_proc_open,
  1076. .proc_read = seq_read,
  1077. .proc_lseek = seq_lseek,
  1078. .proc_release = single_release,
  1079. /* No need for write for now */
  1080. /* .proc_write = cifs_mount_params_proc_write, */
  1081. };
  1082. #else
  1083. inline void cifs_proc_init(void)
  1084. {
  1085. }
  1086. inline void cifs_proc_clean(void)
  1087. {
  1088. }
  1089. #endif /* PROC_FS */