1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) International Business Machines Corp., 2000,2005
10 #include <linux/string.h>
11 #include <linux/ctype.h>
12 #include <linux/module.h>
13 #include <linux/proc_fs.h>
14 #include <linux/uaccess.h>
17 #include "cifsproto.h"
18 #include "cifs_debug.h"
20 #ifdef CONFIG_CIFS_DFS_UPCALL
21 #include "dfs_cache.h"
23 #ifdef CONFIG_CIFS_SMB_DIRECT
24 #include "smbdirect.h"
26 #ifdef CONFIG_CIFS_SWN_UPCALL
31 cifs_dump_mem(char *label, void *data, int length)
33 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
34 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
38 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
40 #ifdef CONFIG_CIFS_DEBUG2
41 struct smb_hdr *smb = (struct smb_hdr *)buf;
43 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
44 smb->Command, smb->Status.CifsError,
45 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
46 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
47 server->ops->calc_smb_size(smb, server));
48 #endif /* CONFIG_CIFS_DEBUG2 */
51 void cifs_dump_mids(struct TCP_Server_Info *server)
53 #ifdef CONFIG_CIFS_DEBUG2
54 struct list_head *tmp;
55 struct mid_q_entry *mid_entry;
60 cifs_dbg(VFS, "Dump pending requests:\n");
61 spin_lock(&GlobalMid_Lock);
62 list_for_each(tmp, &server->pending_mid_q) {
63 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
64 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
66 le16_to_cpu(mid_entry->command),
68 mid_entry->callback_data,
70 #ifdef CONFIG_CIFS_STATS2
71 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
74 mid_entry->when_received,
77 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
78 mid_entry->multiRsp, mid_entry->multiEnd);
79 if (mid_entry->resp_buf) {
80 cifs_dump_detail(mid_entry->resp_buf, server);
81 cifs_dump_mem("existing buf: ",
82 mid_entry->resp_buf, 62);
85 spin_unlock(&GlobalMid_Lock);
86 #endif /* CONFIG_CIFS_DEBUG2 */
90 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
92 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
94 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
95 if (tcon->nativeFileSystem)
96 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
97 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
98 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
99 le32_to_cpu(tcon->fsAttrInfo.Attributes),
100 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
102 if (dev_type == FILE_DEVICE_DISK)
103 seq_puts(m, " type: DISK ");
104 else if (dev_type == FILE_DEVICE_CD_ROM)
105 seq_puts(m, " type: CDROM ");
107 seq_printf(m, " type: %d ", dev_type);
109 seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
112 (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
113 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
114 seq_printf(m, " Encrypted");
116 seq_printf(m, " nocase");
118 seq_printf(m, " POSIX Extensions");
119 if (tcon->ses->server->ops->dump_share_caps)
120 tcon->ses->server->ops->dump_share_caps(m, tcon);
121 #ifdef CONFIG_CIFS_SWN_UPCALL
122 if (tcon->use_witness)
123 seq_puts(m, " Witness");
126 if (tcon->need_reconnect)
127 seq_puts(m, "\tDISCONNECTED ");
132 cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
134 struct TCP_Server_Info *server = chan->server;
136 seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
137 "\n\t\tNumber of credits: %d Dialect 0x%x"
138 "\n\t\tTCP status: %d Instance: %d"
139 "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
140 "\n\t\tIn Send: %d In MaxReq Wait: %d",
141 i+1, server->conn_id,
145 server->reconnect_instance,
149 atomic_read(&server->in_send),
150 atomic_read(&server->num_waiters));
154 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
156 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
157 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
159 seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
160 seq_puts(m, "\t\tCapabilities: ");
161 if (iface->rdma_capable)
162 seq_puts(m, "rdma ");
163 if (iface->rss_capable)
166 if (iface->sockaddr.ss_family == AF_INET)
167 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
168 else if (iface->sockaddr.ss_family == AF_INET6)
169 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
172 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
174 struct list_head *stmp, *tmp, *tmp1, *tmp2;
175 struct TCP_Server_Info *server;
176 struct cifs_ses *ses;
177 struct cifs_tcon *tcon;
178 struct cifsFileInfo *cfile;
180 seq_puts(m, "# Version:1\n");
181 seq_puts(m, "# Format:\n");
182 seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
183 #ifdef CONFIG_CIFS_DEBUG2
184 seq_printf(m, " <filename> <mid>\n");
186 seq_printf(m, " <filename>\n");
187 #endif /* CIFS_DEBUG2 */
188 spin_lock(&cifs_tcp_ses_lock);
189 list_for_each(stmp, &cifs_tcp_ses_list) {
190 server = list_entry(stmp, struct TCP_Server_Info,
192 list_for_each(tmp, &server->smb_ses_list) {
193 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
194 list_for_each(tmp1, &ses->tcon_list) {
195 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
196 spin_lock(&tcon->open_file_lock);
197 list_for_each(tmp2, &tcon->openFileList) {
198 cfile = list_entry(tmp2, struct cifsFileInfo,
201 "0x%x 0x%llx 0x%x %d %d %d %pd",
203 cfile->fid.persistent_fid,
207 from_kuid(&init_user_ns, cfile->uid),
209 #ifdef CONFIG_CIFS_DEBUG2
210 seq_printf(m, " %llu\n", cfile->fid.mid);
213 #endif /* CIFS_DEBUG2 */
215 spin_unlock(&tcon->open_file_lock);
219 spin_unlock(&cifs_tcp_ses_lock);
224 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
226 struct list_head *tmp1, *tmp2, *tmp3;
227 struct mid_q_entry *mid_entry;
228 struct TCP_Server_Info *server;
229 struct cifs_ses *ses;
230 struct cifs_tcon *tcon;
234 "Display Internal CIFS Data Structures for Debugging\n"
235 "---------------------------------------------------\n");
236 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
237 seq_printf(m, "Features:");
238 #ifdef CONFIG_CIFS_DFS_UPCALL
239 seq_printf(m, " DFS");
241 #ifdef CONFIG_CIFS_FSCACHE
242 seq_printf(m, ",FSCACHE");
244 #ifdef CONFIG_CIFS_SMB_DIRECT
245 seq_printf(m, ",SMB_DIRECT");
247 #ifdef CONFIG_CIFS_STATS2
248 seq_printf(m, ",STATS2");
250 seq_printf(m, ",STATS");
252 #ifdef CONFIG_CIFS_DEBUG2
253 seq_printf(m, ",DEBUG2");
254 #elif defined(CONFIG_CIFS_DEBUG)
255 seq_printf(m, ",DEBUG");
257 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
258 seq_printf(m, ",ALLOW_INSECURE_LEGACY");
260 #ifdef CONFIG_CIFS_WEAK_PW_HASH
261 seq_printf(m, ",WEAK_PW_HASH");
263 #ifdef CONFIG_CIFS_POSIX
264 seq_printf(m, ",CIFS_POSIX");
266 #ifdef CONFIG_CIFS_UPCALL
267 seq_printf(m, ",UPCALL(SPNEGO)");
269 #ifdef CONFIG_CIFS_XATTR
270 seq_printf(m, ",XATTR");
272 seq_printf(m, ",ACL");
273 #ifdef CONFIG_CIFS_SWN_UPCALL
274 seq_puts(m, ",WITNESS");
277 seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
278 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
280 seq_printf(m, "\nServers: ");
283 spin_lock(&cifs_tcp_ses_lock);
284 list_for_each(tmp1, &cifs_tcp_ses_list) {
285 server = list_entry(tmp1, struct TCP_Server_Info,
288 /* channel info will be printed as a part of sessions below */
289 if (server->is_channel)
293 seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
296 if (server->hostname)
297 seq_printf(m, "Hostname: %s ", server->hostname);
298 #ifdef CONFIG_CIFS_SMB_DIRECT
302 if (!server->smbd_conn) {
303 seq_printf(m, "\nSMBDirect transport not available");
307 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
308 "transport status: %x",
309 server->smbd_conn->protocol,
310 server->smbd_conn->transport_status);
311 seq_printf(m, "\nConn receive_credit_max: %x "
312 "send_credit_target: %x max_send_size: %x",
313 server->smbd_conn->receive_credit_max,
314 server->smbd_conn->send_credit_target,
315 server->smbd_conn->max_send_size);
316 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
317 "max_fragmented_send_size: %x max_receive_size:%x",
318 server->smbd_conn->max_fragmented_recv_size,
319 server->smbd_conn->max_fragmented_send_size,
320 server->smbd_conn->max_receive_size);
321 seq_printf(m, "\nConn keep_alive_interval: %x "
322 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
323 server->smbd_conn->keep_alive_interval,
324 server->smbd_conn->max_readwrite_size,
325 server->smbd_conn->rdma_readwrite_threshold);
326 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
327 "count_put_receive_buffer: %x count_send_empty: %x",
328 server->smbd_conn->count_get_receive_buffer,
329 server->smbd_conn->count_put_receive_buffer,
330 server->smbd_conn->count_send_empty);
331 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
332 "count_enqueue_reassembly_queue: %x "
333 "count_dequeue_reassembly_queue: %x "
334 "fragment_reassembly_remaining: %x "
335 "reassembly_data_length: %x "
336 "reassembly_queue_length: %x",
337 server->smbd_conn->count_reassembly_queue,
338 server->smbd_conn->count_enqueue_reassembly_queue,
339 server->smbd_conn->count_dequeue_reassembly_queue,
340 server->smbd_conn->fragment_reassembly_remaining,
341 server->smbd_conn->reassembly_data_length,
342 server->smbd_conn->reassembly_queue_length);
343 seq_printf(m, "\nCurrent Credits send_credits: %x "
344 "receive_credits: %x receive_credit_target: %x",
345 atomic_read(&server->smbd_conn->send_credits),
346 atomic_read(&server->smbd_conn->receive_credits),
347 server->smbd_conn->receive_credit_target);
348 seq_printf(m, "\nPending send_pending: %x ",
349 atomic_read(&server->smbd_conn->send_pending));
350 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
351 "count_empty_packet_queue: %x",
352 server->smbd_conn->count_receive_queue,
353 server->smbd_conn->count_empty_packet_queue);
354 seq_printf(m, "\nMR responder_resources: %x "
355 "max_frmr_depth: %x mr_type: %x",
356 server->smbd_conn->responder_resources,
357 server->smbd_conn->max_frmr_depth,
358 server->smbd_conn->mr_type);
359 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
360 atomic_read(&server->smbd_conn->mr_ready_count),
361 atomic_read(&server->smbd_conn->mr_used_count));
364 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
365 server->credits, server->dialect);
366 if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
367 seq_printf(m, " COMPRESS_LZNT1");
368 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
369 seq_printf(m, " COMPRESS_LZ77");
370 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
371 seq_printf(m, " COMPRESS_LZ77_HUFF");
373 seq_printf(m, " signed");
374 if (server->posix_ext_supported)
375 seq_printf(m, " posix");
378 seq_printf(m, "\nRDMA ");
379 seq_printf(m, "\nTCP status: %d Instance: %d"
380 "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
382 server->reconnect_instance,
384 server->sec_mode, in_flight(server));
386 seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
387 atomic_read(&server->in_send),
388 atomic_read(&server->num_waiters));
390 seq_printf(m, "\n\n\tSessions: ");
392 list_for_each(tmp2, &server->smb_ses_list) {
393 ses = list_entry(tmp2, struct cifs_ses,
396 if ((ses->serverDomain == NULL) ||
397 (ses->serverOS == NULL) ||
398 (ses->serverNOS == NULL)) {
399 seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
400 i, ses->ip_addr, ses->ses_count,
401 ses->capabilities, ses->status);
402 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
403 seq_printf(m, "Guest ");
404 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
405 seq_printf(m, "Anonymous ");
408 "\n\t%d) Name: %s Domain: %s Uses: %d OS: %s "
409 "\n\tNOS: %s\tCapability: 0x%x"
410 "\n\tSMB session status: %d ",
411 i, ses->ip_addr, ses->serverDomain,
412 ses->ses_count, ses->serverOS, ses->serverNOS,
413 ses->capabilities, ses->status);
416 seq_printf(m, "\n\tSecurity type: %s ",
417 get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
419 /* dump session id helpful for use with network trace */
420 seq_printf(m, " SessionId: 0x%llx", ses->Suid);
421 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
422 seq_puts(m, " encrypted");
424 seq_puts(m, " signed");
426 seq_printf(m, "\n\tUser: %d Cred User: %d",
427 from_kuid(&init_user_ns, ses->linux_uid),
428 from_kuid(&init_user_ns, ses->cred_uid));
430 if (ses->chan_count > 1) {
431 seq_printf(m, "\n\n\tExtra Channels: %zu ",
433 for (j = 1; j < ses->chan_count; j++)
434 cifs_dump_channel(m, j, &ses->chans[j]);
437 seq_puts(m, "\n\n\tShares: ");
440 seq_printf(m, "\n\t%d) IPC: ", j);
442 cifs_debug_tcon(m, ses->tcon_ipc);
444 seq_puts(m, "none\n");
446 list_for_each(tmp3, &ses->tcon_list) {
447 tcon = list_entry(tmp3, struct cifs_tcon,
450 seq_printf(m, "\n\t%d) ", j);
451 cifs_debug_tcon(m, tcon);
454 spin_lock(&ses->iface_lock);
455 if (ses->iface_count)
456 seq_printf(m, "\n\n\tServer interfaces: %zu",
458 for (j = 0; j < ses->iface_count; j++) {
459 struct cifs_server_iface *iface;
461 iface = &ses->iface_list[j];
462 seq_printf(m, "\n\t%d)", j+1);
463 cifs_dump_iface(m, iface);
464 if (is_ses_using_iface(ses, iface))
465 seq_puts(m, "\t\t[CONNECTED]\n");
467 spin_unlock(&ses->iface_lock);
470 seq_printf(m, "\n\t\t[NONE]");
472 seq_puts(m, "\n\n\tMIDs: ");
473 spin_lock(&GlobalMid_Lock);
474 list_for_each(tmp3, &server->pending_mid_q) {
475 mid_entry = list_entry(tmp3, struct mid_q_entry,
477 seq_printf(m, "\n\tState: %d com: %d pid:"
478 " %d cbdata: %p mid %llu\n",
479 mid_entry->mid_state,
480 le16_to_cpu(mid_entry->command),
482 mid_entry->callback_data,
485 spin_unlock(&GlobalMid_Lock);
486 seq_printf(m, "\n--\n");
489 seq_printf(m, "\n\t[NONE]");
491 spin_unlock(&cifs_tcp_ses_lock);
494 #ifdef CONFIG_CIFS_SWN_UPCALL
497 /* BB add code to dump additional info such as TCP session info now */
501 static ssize_t cifs_stats_proc_write(struct file *file,
502 const char __user *buffer, size_t count, loff_t *ppos)
506 struct list_head *tmp1, *tmp2, *tmp3;
507 struct TCP_Server_Info *server;
508 struct cifs_ses *ses;
509 struct cifs_tcon *tcon;
511 rc = kstrtobool_from_user(buffer, count, &bv);
513 #ifdef CONFIG_CIFS_STATS2
516 atomic_set(&totBufAllocCount, 0);
517 atomic_set(&totSmBufAllocCount, 0);
518 #endif /* CONFIG_CIFS_STATS2 */
519 atomic_set(&tcpSesReconnectCount, 0);
520 atomic_set(&tconInfoReconnectCount, 0);
522 spin_lock(&GlobalMid_Lock);
523 GlobalMaxActiveXid = 0;
524 GlobalCurrentXid = 0;
525 spin_unlock(&GlobalMid_Lock);
526 spin_lock(&cifs_tcp_ses_lock);
527 list_for_each(tmp1, &cifs_tcp_ses_list) {
528 server = list_entry(tmp1, struct TCP_Server_Info,
530 server->max_in_flight = 0;
531 #ifdef CONFIG_CIFS_STATS2
532 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
533 atomic_set(&server->num_cmds[i], 0);
534 atomic_set(&server->smb2slowcmd[i], 0);
535 server->time_per_cmd[i] = 0;
536 server->slowest_cmd[i] = 0;
537 server->fastest_cmd[0] = 0;
539 #endif /* CONFIG_CIFS_STATS2 */
540 list_for_each(tmp2, &server->smb_ses_list) {
541 ses = list_entry(tmp2, struct cifs_ses,
543 list_for_each(tmp3, &ses->tcon_list) {
544 tcon = list_entry(tmp3,
547 atomic_set(&tcon->num_smbs_sent, 0);
548 spin_lock(&tcon->stat_lock);
549 tcon->bytes_read = 0;
550 tcon->bytes_written = 0;
551 spin_unlock(&tcon->stat_lock);
552 if (server->ops->clear_stats)
553 server->ops->clear_stats(tcon);
557 spin_unlock(&cifs_tcp_ses_lock);
565 static int cifs_stats_proc_show(struct seq_file *m, void *v)
568 #ifdef CONFIG_CIFS_STATS2
571 struct list_head *tmp1, *tmp2, *tmp3;
572 struct TCP_Server_Info *server;
573 struct cifs_ses *ses;
574 struct cifs_tcon *tcon;
576 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
577 sesInfoAllocCount.counter);
578 seq_printf(m, "Share (unique mount targets): %d\n",
579 tconInfoAllocCount.counter);
580 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
581 bufAllocCount.counter,
582 cifs_min_rcv + tcpSesAllocCount.counter);
583 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
584 smBufAllocCount.counter, cifs_min_small);
585 #ifdef CONFIG_CIFS_STATS2
586 seq_printf(m, "Total Large %d Small %d Allocations\n",
587 atomic_read(&totBufAllocCount),
588 atomic_read(&totSmBufAllocCount));
589 #endif /* CONFIG_CIFS_STATS2 */
591 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
593 "\n%d session %d share reconnects\n",
594 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
597 "Total vfs operations: %d maximum at one time: %d\n",
598 GlobalCurrentXid, GlobalMaxActiveXid);
601 spin_lock(&cifs_tcp_ses_lock);
602 list_for_each(tmp1, &cifs_tcp_ses_list) {
603 server = list_entry(tmp1, struct TCP_Server_Info,
605 seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
606 #ifdef CONFIG_CIFS_STATS2
607 seq_puts(m, "\nTotal time spent processing by command. Time ");
608 seq_printf(m, "units are jiffies (%d per second)\n", HZ);
609 seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
610 seq_puts(m, " --------\t------\t----------\t-------\t-------\n");
611 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
612 seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j,
613 atomic_read(&server->num_cmds[j]),
614 server->time_per_cmd[j],
615 server->fastest_cmd[j],
616 server->slowest_cmd[j]);
617 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
618 if (atomic_read(&server->smb2slowcmd[j]))
619 seq_printf(m, " %d slow responses from %s for command %d\n",
620 atomic_read(&server->smb2slowcmd[j]),
621 server->hostname, j);
623 list_for_each(tmp2, &server->smb_ses_list) {
624 ses = list_entry(tmp2, struct cifs_ses,
626 list_for_each(tmp3, &ses->tcon_list) {
627 tcon = list_entry(tmp3,
631 seq_printf(m, "\n%d) %s", i, tcon->treeName);
632 if (tcon->need_reconnect)
633 seq_puts(m, "\tDISCONNECTED ");
634 seq_printf(m, "\nSMBs: %d",
635 atomic_read(&tcon->num_smbs_sent));
636 if (server->ops->print_stats)
637 server->ops->print_stats(m, tcon);
641 spin_unlock(&cifs_tcp_ses_lock);
647 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
649 return single_open(file, cifs_stats_proc_show, NULL);
652 static const struct proc_ops cifs_stats_proc_ops = {
653 .proc_open = cifs_stats_proc_open,
654 .proc_read = seq_read,
655 .proc_lseek = seq_lseek,
656 .proc_release = single_release,
657 .proc_write = cifs_stats_proc_write,
660 #ifdef CONFIG_CIFS_SMB_DIRECT
661 #define PROC_FILE_DEFINE(name) \
662 static ssize_t name##_write(struct file *file, const char __user *buffer, \
663 size_t count, loff_t *ppos) \
666 rc = kstrtoint_from_user(buffer, count, 10, & name); \
671 static int name##_proc_show(struct seq_file *m, void *v) \
673 seq_printf(m, "%d\n", name ); \
676 static int name##_open(struct inode *inode, struct file *file) \
678 return single_open(file, name##_proc_show, NULL); \
681 static const struct proc_ops cifs_##name##_proc_fops = { \
682 .proc_open = name##_open, \
683 .proc_read = seq_read, \
684 .proc_lseek = seq_lseek, \
685 .proc_release = single_release, \
686 .proc_write = name##_write, \
689 PROC_FILE_DEFINE(rdma_readwrite_threshold);
690 PROC_FILE_DEFINE(smbd_max_frmr_depth);
691 PROC_FILE_DEFINE(smbd_keep_alive_interval);
692 PROC_FILE_DEFINE(smbd_max_receive_size);
693 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
694 PROC_FILE_DEFINE(smbd_max_send_size);
695 PROC_FILE_DEFINE(smbd_send_credit_target);
696 PROC_FILE_DEFINE(smbd_receive_credit_max);
699 static struct proc_dir_entry *proc_fs_cifs;
700 static const struct proc_ops cifsFYI_proc_ops;
701 static const struct proc_ops cifs_lookup_cache_proc_ops;
702 static const struct proc_ops traceSMB_proc_ops;
703 static const struct proc_ops cifs_security_flags_proc_ops;
704 static const struct proc_ops cifs_linux_ext_proc_ops;
709 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
710 if (proc_fs_cifs == NULL)
713 proc_create_single("DebugData", 0, proc_fs_cifs,
714 cifs_debug_data_proc_show);
716 proc_create_single("open_files", 0400, proc_fs_cifs,
717 cifs_debug_files_proc_show);
719 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
720 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
721 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
722 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
723 &cifs_linux_ext_proc_ops);
724 proc_create("SecurityFlags", 0644, proc_fs_cifs,
725 &cifs_security_flags_proc_ops);
726 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
727 &cifs_lookup_cache_proc_ops);
729 #ifdef CONFIG_CIFS_DFS_UPCALL
730 proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
733 #ifdef CONFIG_CIFS_SMB_DIRECT
734 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
735 &cifs_rdma_readwrite_threshold_proc_fops);
736 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
737 &cifs_smbd_max_frmr_depth_proc_fops);
738 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
739 &cifs_smbd_keep_alive_interval_proc_fops);
740 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
741 &cifs_smbd_max_receive_size_proc_fops);
742 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
743 &cifs_smbd_max_fragmented_recv_size_proc_fops);
744 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
745 &cifs_smbd_max_send_size_proc_fops);
746 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
747 &cifs_smbd_send_credit_target_proc_fops);
748 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
749 &cifs_smbd_receive_credit_max_proc_fops);
754 cifs_proc_clean(void)
756 if (proc_fs_cifs == NULL)
759 remove_proc_entry("DebugData", proc_fs_cifs);
760 remove_proc_entry("open_files", proc_fs_cifs);
761 remove_proc_entry("cifsFYI", proc_fs_cifs);
762 remove_proc_entry("traceSMB", proc_fs_cifs);
763 remove_proc_entry("Stats", proc_fs_cifs);
764 remove_proc_entry("SecurityFlags", proc_fs_cifs);
765 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
766 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
768 #ifdef CONFIG_CIFS_DFS_UPCALL
769 remove_proc_entry("dfscache", proc_fs_cifs);
771 #ifdef CONFIG_CIFS_SMB_DIRECT
772 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
773 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
774 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
775 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
776 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
777 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
778 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
779 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
781 remove_proc_entry("fs/cifs", NULL);
784 static int cifsFYI_proc_show(struct seq_file *m, void *v)
786 seq_printf(m, "%d\n", cifsFYI);
790 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
792 return single_open(file, cifsFYI_proc_show, NULL);
795 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
796 size_t count, loff_t *ppos)
798 char c[2] = { '\0' };
802 rc = get_user(c[0], buffer);
805 if (strtobool(c, &bv) == 0)
807 else if ((c[0] > '1') && (c[0] <= '9'))
808 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
815 static const struct proc_ops cifsFYI_proc_ops = {
816 .proc_open = cifsFYI_proc_open,
817 .proc_read = seq_read,
818 .proc_lseek = seq_lseek,
819 .proc_release = single_release,
820 .proc_write = cifsFYI_proc_write,
823 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
825 seq_printf(m, "%d\n", linuxExtEnabled);
829 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
831 return single_open(file, cifs_linux_ext_proc_show, NULL);
834 static ssize_t cifs_linux_ext_proc_write(struct file *file,
835 const char __user *buffer, size_t count, loff_t *ppos)
839 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
846 static const struct proc_ops cifs_linux_ext_proc_ops = {
847 .proc_open = cifs_linux_ext_proc_open,
848 .proc_read = seq_read,
849 .proc_lseek = seq_lseek,
850 .proc_release = single_release,
851 .proc_write = cifs_linux_ext_proc_write,
854 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
856 seq_printf(m, "%d\n", lookupCacheEnabled);
860 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
862 return single_open(file, cifs_lookup_cache_proc_show, NULL);
865 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
866 const char __user *buffer, size_t count, loff_t *ppos)
870 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
877 static const struct proc_ops cifs_lookup_cache_proc_ops = {
878 .proc_open = cifs_lookup_cache_proc_open,
879 .proc_read = seq_read,
880 .proc_lseek = seq_lseek,
881 .proc_release = single_release,
882 .proc_write = cifs_lookup_cache_proc_write,
885 static int traceSMB_proc_show(struct seq_file *m, void *v)
887 seq_printf(m, "%d\n", traceSMB);
891 static int traceSMB_proc_open(struct inode *inode, struct file *file)
893 return single_open(file, traceSMB_proc_show, NULL);
896 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
897 size_t count, loff_t *ppos)
901 rc = kstrtobool_from_user(buffer, count, &traceSMB);
908 static const struct proc_ops traceSMB_proc_ops = {
909 .proc_open = traceSMB_proc_open,
910 .proc_read = seq_read,
911 .proc_lseek = seq_lseek,
912 .proc_release = single_release,
913 .proc_write = traceSMB_proc_write,
916 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
918 seq_printf(m, "0x%x\n", global_secflags);
922 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
924 return single_open(file, cifs_security_flags_proc_show, NULL);
928 * Ensure that if someone sets a MUST flag, that we disable all other MAY
929 * flags except for the ones corresponding to the given MUST flag. If there are
930 * multiple MUST flags, then try to prefer more secure ones.
933 cifs_security_flags_handle_must_flags(unsigned int *flags)
935 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
937 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
938 *flags = CIFSSEC_MUST_KRB5;
939 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
940 *flags = CIFSSEC_MUST_NTLMSSP;
941 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
942 *flags = CIFSSEC_MUST_NTLMV2;
943 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
944 *flags = CIFSSEC_MUST_NTLM;
945 else if (CIFSSEC_MUST_LANMAN &&
946 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
947 *flags = CIFSSEC_MUST_LANMAN;
948 else if (CIFSSEC_MUST_PLNTXT &&
949 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
950 *flags = CIFSSEC_MUST_PLNTXT;
955 static ssize_t cifs_security_flags_proc_write(struct file *file,
956 const char __user *buffer, size_t count, loff_t *ppos)
960 char flags_string[12];
963 if ((count < 1) || (count > 11))
966 memset(flags_string, 0, 12);
968 if (copy_from_user(flags_string, buffer, count))
972 /* single char or single char followed by null */
973 if (strtobool(flags_string, &bv) == 0) {
974 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
976 } else if (!isdigit(flags_string[0])) {
977 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
983 /* else we have a number */
984 rc = kstrtouint(flags_string, 0, &flags);
986 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
991 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
994 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
998 if (flags & ~CIFSSEC_MASK) {
999 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
1000 flags & ~CIFSSEC_MASK);
1004 cifs_security_flags_handle_must_flags(&flags);
1006 /* flags look ok - update the global security flags for cifs module */
1007 global_secflags = flags;
1008 if (global_secflags & CIFSSEC_MUST_SIGN) {
1009 /* requiring signing implies signing is allowed */
1010 global_secflags |= CIFSSEC_MAY_SIGN;
1011 cifs_dbg(FYI, "packet signing now required\n");
1012 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
1013 cifs_dbg(FYI, "packet signing disabled\n");
1015 /* BB should we turn on MAY flags for other MUST options? */
1019 static const struct proc_ops cifs_security_flags_proc_ops = {
1020 .proc_open = cifs_security_flags_proc_open,
1021 .proc_read = seq_read,
1022 .proc_lseek = seq_lseek,
1023 .proc_release = single_release,
1024 .proc_write = cifs_security_flags_proc_write,
1027 inline void cifs_proc_init(void)
1031 inline void cifs_proc_clean(void)
1034 #endif /* PROC_FS */