4 * Copyright (C) International Business Machines Corp., 2000,2005
6 * Modified by Steve French (sfrench@us.ibm.com)
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.
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.
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
23 #include <linux/string.h>
24 #include <linux/ctype.h>
25 #include <linux/module.h>
26 #include <linux/proc_fs.h>
27 #include <linux/uaccess.h>
30 #include "cifsproto.h"
31 #include "cifs_debug.h"
33 #ifdef CONFIG_CIFS_SMB_DIRECT
34 #include "smbdirect.h"
38 cifs_dump_mem(char *label, void *data, int length)
40 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
41 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
45 #ifdef CONFIG_CIFS_DEBUG
46 void cifs_vfs_err(const char *fmt, ...)
56 pr_err_ratelimited("CIFS VFS: %pV", &vaf);
62 void cifs_dump_detail(void *buf)
64 #ifdef CONFIG_CIFS_DEBUG2
65 struct smb_hdr *smb = (struct smb_hdr *)buf;
67 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
68 smb->Command, smb->Status.CifsError,
69 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
70 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
71 #endif /* CONFIG_CIFS_DEBUG2 */
74 void cifs_dump_mids(struct TCP_Server_Info *server)
76 #ifdef CONFIG_CIFS_DEBUG2
77 struct list_head *tmp;
78 struct mid_q_entry *mid_entry;
83 cifs_dbg(VFS, "Dump pending requests:\n");
84 spin_lock(&GlobalMid_Lock);
85 list_for_each(tmp, &server->pending_mid_q) {
86 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
87 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
89 le16_to_cpu(mid_entry->command),
91 mid_entry->callback_data,
93 #ifdef CONFIG_CIFS_STATS2
94 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
97 mid_entry->when_received,
100 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
101 mid_entry->multiRsp, mid_entry->multiEnd);
102 if (mid_entry->resp_buf) {
103 cifs_dump_detail(mid_entry->resp_buf);
104 cifs_dump_mem("existing buf: ",
105 mid_entry->resp_buf, 62);
108 spin_unlock(&GlobalMid_Lock);
109 #endif /* CONFIG_CIFS_DEBUG2 */
112 #ifdef CONFIG_PROC_FS
113 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
115 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
117 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
118 if (tcon->nativeFileSystem)
119 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
120 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
121 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
122 le32_to_cpu(tcon->fsAttrInfo.Attributes),
123 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
125 if (dev_type == FILE_DEVICE_DISK)
126 seq_puts(m, " type: DISK ");
127 else if (dev_type == FILE_DEVICE_CD_ROM)
128 seq_puts(m, " type: CDROM ");
130 seq_printf(m, " type: %d ", dev_type);
131 if (tcon->ses->server->ops->dump_share_caps)
132 tcon->ses->server->ops->dump_share_caps(m, tcon);
134 if (tcon->need_reconnect)
135 seq_puts(m, "\tDISCONNECTED ");
139 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
141 struct list_head *tmp1, *tmp2, *tmp3;
142 struct mid_q_entry *mid_entry;
143 struct TCP_Server_Info *server;
144 struct cifs_ses *ses;
145 struct cifs_tcon *tcon;
149 "Display Internal CIFS Data Structures for Debugging\n"
150 "---------------------------------------------------\n");
151 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
152 seq_printf(m, "Features:");
153 #ifdef CONFIG_CIFS_DFS_UPCALL
154 seq_printf(m, " dfs");
156 #ifdef CONFIG_CIFS_FSCACHE
157 seq_printf(m, " fscache");
159 #ifdef CONFIG_CIFS_WEAK_PW_HASH
160 seq_printf(m, " lanman");
162 #ifdef CONFIG_CIFS_POSIX
163 seq_printf(m, " posix");
165 #ifdef CONFIG_CIFS_UPCALL
166 seq_printf(m, " spnego");
168 #ifdef CONFIG_CIFS_XATTR
169 seq_printf(m, " xattr");
171 #ifdef CONFIG_CIFS_ACL
172 seq_printf(m, " acl");
175 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
176 seq_printf(m, "Servers:");
179 spin_lock(&cifs_tcp_ses_lock);
180 list_for_each(tmp1, &cifs_tcp_ses_list) {
181 server = list_entry(tmp1, struct TCP_Server_Info,
184 #ifdef CONFIG_CIFS_SMB_DIRECT
188 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
189 "transport status: %x",
190 server->smbd_conn->protocol,
191 server->smbd_conn->transport_status);
192 seq_printf(m, "\nConn receive_credit_max: %x "
193 "send_credit_target: %x max_send_size: %x",
194 server->smbd_conn->receive_credit_max,
195 server->smbd_conn->send_credit_target,
196 server->smbd_conn->max_send_size);
197 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
198 "max_fragmented_send_size: %x max_receive_size:%x",
199 server->smbd_conn->max_fragmented_recv_size,
200 server->smbd_conn->max_fragmented_send_size,
201 server->smbd_conn->max_receive_size);
202 seq_printf(m, "\nConn keep_alive_interval: %x "
203 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
204 server->smbd_conn->keep_alive_interval,
205 server->smbd_conn->max_readwrite_size,
206 server->smbd_conn->rdma_readwrite_threshold);
207 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
208 "count_put_receive_buffer: %x count_send_empty: %x",
209 server->smbd_conn->count_get_receive_buffer,
210 server->smbd_conn->count_put_receive_buffer,
211 server->smbd_conn->count_send_empty);
212 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
213 "count_enqueue_reassembly_queue: %x "
214 "count_dequeue_reassembly_queue: %x "
215 "fragment_reassembly_remaining: %x "
216 "reassembly_data_length: %x "
217 "reassembly_queue_length: %x",
218 server->smbd_conn->count_reassembly_queue,
219 server->smbd_conn->count_enqueue_reassembly_queue,
220 server->smbd_conn->count_dequeue_reassembly_queue,
221 server->smbd_conn->fragment_reassembly_remaining,
222 server->smbd_conn->reassembly_data_length,
223 server->smbd_conn->reassembly_queue_length);
224 seq_printf(m, "\nCurrent Credits send_credits: %x "
225 "receive_credits: %x receive_credit_target: %x",
226 atomic_read(&server->smbd_conn->send_credits),
227 atomic_read(&server->smbd_conn->receive_credits),
228 server->smbd_conn->receive_credit_target);
229 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
230 " %x smbd_send_pending: %x smbd_recv_pending: %x",
231 atomic_read(&server->smbd_conn->send_pending),
232 atomic_read(&server->smbd_conn->send_payload_pending),
233 server->smbd_conn->smbd_send_pending,
234 server->smbd_conn->smbd_recv_pending);
235 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
236 "count_empty_packet_queue: %x",
237 server->smbd_conn->count_receive_queue,
238 server->smbd_conn->count_empty_packet_queue);
239 seq_printf(m, "\nMR responder_resources: %x "
240 "max_frmr_depth: %x mr_type: %x",
241 server->smbd_conn->responder_resources,
242 server->smbd_conn->max_frmr_depth,
243 server->smbd_conn->mr_type);
244 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
245 atomic_read(&server->smbd_conn->mr_ready_count),
246 atomic_read(&server->smbd_conn->mr_used_count));
249 seq_printf(m, "\nNumber of credits: %d", server->credits);
251 list_for_each(tmp2, &server->smb_ses_list) {
252 ses = list_entry(tmp2, struct cifs_ses,
254 if ((ses->serverDomain == NULL) ||
255 (ses->serverOS == NULL) ||
256 (ses->serverNOS == NULL)) {
257 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
258 i, ses->serverName, ses->ses_count,
259 ses->capabilities, ses->status);
260 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
261 seq_printf(m, "Guest\t");
262 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
263 seq_printf(m, "Anonymous\t");
266 "\n%d) Name: %s Domain: %s Uses: %d OS:"
267 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
268 " session status: %d\t",
269 i, ses->serverName, ses->serverDomain,
270 ses->ses_count, ses->serverOS, ses->serverNOS,
271 ses->capabilities, ses->status);
274 seq_printf(m, "RDMA\n\t");
275 seq_printf(m, "TCP status: %d\n\tLocal Users To "
276 "Server: %d SecMode: 0x%x Req On Wire: %d",
277 server->tcpStatus, server->srv_count,
278 server->sec_mode, in_flight(server));
280 #ifdef CONFIG_CIFS_STATS2
281 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
282 atomic_read(&server->in_send),
283 atomic_read(&server->num_waiters));
286 seq_puts(m, "\n\tShares:");
289 seq_printf(m, "\n\t%d) IPC: ", j);
291 cifs_debug_tcon(m, ses->tcon_ipc);
293 seq_puts(m, "none\n");
295 list_for_each(tmp3, &ses->tcon_list) {
296 tcon = list_entry(tmp3, struct cifs_tcon,
299 seq_printf(m, "\n\t%d) ", j);
300 cifs_debug_tcon(m, tcon);
303 seq_puts(m, "\n\tMIDs:\n");
305 spin_lock(&GlobalMid_Lock);
306 list_for_each(tmp3, &server->pending_mid_q) {
307 mid_entry = list_entry(tmp3, struct mid_q_entry,
309 seq_printf(m, "\tState: %d com: %d pid:"
310 " %d cbdata: %p mid %llu\n",
311 mid_entry->mid_state,
312 le16_to_cpu(mid_entry->command),
314 mid_entry->callback_data,
317 spin_unlock(&GlobalMid_Lock);
320 spin_unlock(&cifs_tcp_ses_lock);
323 /* BB add code to dump additional info such as TCP session info now */
327 static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
329 return single_open(file, cifs_debug_data_proc_show, NULL);
332 static const struct file_operations cifs_debug_data_proc_fops = {
333 .open = cifs_debug_data_proc_open,
336 .release = single_release,
339 #ifdef CONFIG_CIFS_STATS
340 static ssize_t cifs_stats_proc_write(struct file *file,
341 const char __user *buffer, size_t count, loff_t *ppos)
345 struct list_head *tmp1, *tmp2, *tmp3;
346 struct TCP_Server_Info *server;
347 struct cifs_ses *ses;
348 struct cifs_tcon *tcon;
350 rc = kstrtobool_from_user(buffer, count, &bv);
352 #ifdef CONFIG_CIFS_STATS2
353 atomic_set(&totBufAllocCount, 0);
354 atomic_set(&totSmBufAllocCount, 0);
355 #endif /* CONFIG_CIFS_STATS2 */
356 spin_lock(&cifs_tcp_ses_lock);
357 list_for_each(tmp1, &cifs_tcp_ses_list) {
358 server = list_entry(tmp1, struct TCP_Server_Info,
360 list_for_each(tmp2, &server->smb_ses_list) {
361 ses = list_entry(tmp2, struct cifs_ses,
363 list_for_each(tmp3, &ses->tcon_list) {
364 tcon = list_entry(tmp3,
367 atomic_set(&tcon->num_smbs_sent, 0);
368 if (server->ops->clear_stats)
369 server->ops->clear_stats(tcon);
373 spin_unlock(&cifs_tcp_ses_lock);
381 static int cifs_stats_proc_show(struct seq_file *m, void *v)
384 struct list_head *tmp1, *tmp2, *tmp3;
385 struct TCP_Server_Info *server;
386 struct cifs_ses *ses;
387 struct cifs_tcon *tcon;
390 "Resources in use\nCIFS Session: %d\n",
391 sesInfoAllocCount.counter);
392 seq_printf(m, "Share (unique mount targets): %d\n",
393 tconInfoAllocCount.counter);
394 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
395 bufAllocCount.counter,
396 cifs_min_rcv + tcpSesAllocCount.counter);
397 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
398 smBufAllocCount.counter, cifs_min_small);
399 #ifdef CONFIG_CIFS_STATS2
400 seq_printf(m, "Total Large %d Small %d Allocations\n",
401 atomic_read(&totBufAllocCount),
402 atomic_read(&totSmBufAllocCount));
403 #endif /* CONFIG_CIFS_STATS2 */
405 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
407 "\n%d session %d share reconnects\n",
408 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
411 "Total vfs operations: %d maximum at one time: %d\n",
412 GlobalCurrentXid, GlobalMaxActiveXid);
415 spin_lock(&cifs_tcp_ses_lock);
416 list_for_each(tmp1, &cifs_tcp_ses_list) {
417 server = list_entry(tmp1, struct TCP_Server_Info,
419 list_for_each(tmp2, &server->smb_ses_list) {
420 ses = list_entry(tmp2, struct cifs_ses,
422 list_for_each(tmp3, &ses->tcon_list) {
423 tcon = list_entry(tmp3,
427 seq_printf(m, "\n%d) %s", i, tcon->treeName);
428 if (tcon->need_reconnect)
429 seq_puts(m, "\tDISCONNECTED ");
430 seq_printf(m, "\nSMBs: %d",
431 atomic_read(&tcon->num_smbs_sent));
432 if (server->ops->print_stats)
433 server->ops->print_stats(m, tcon);
437 spin_unlock(&cifs_tcp_ses_lock);
443 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
445 return single_open(file, cifs_stats_proc_show, NULL);
448 static const struct file_operations cifs_stats_proc_fops = {
449 .open = cifs_stats_proc_open,
452 .release = single_release,
453 .write = cifs_stats_proc_write,
457 #ifdef CONFIG_CIFS_SMB_DIRECT
458 #define PROC_FILE_DEFINE(name) \
459 static ssize_t name##_write(struct file *file, const char __user *buffer, \
460 size_t count, loff_t *ppos) \
463 rc = kstrtoint_from_user(buffer, count, 10, & name); \
468 static int name##_proc_show(struct seq_file *m, void *v) \
470 seq_printf(m, "%d\n", name ); \
473 static int name##_open(struct inode *inode, struct file *file) \
475 return single_open(file, name##_proc_show, NULL); \
478 static const struct file_operations cifs_##name##_proc_fops = { \
479 .open = name##_open, \
481 .llseek = seq_lseek, \
482 .release = single_release, \
483 .write = name##_write, \
486 PROC_FILE_DEFINE(rdma_readwrite_threshold);
487 PROC_FILE_DEFINE(smbd_max_frmr_depth);
488 PROC_FILE_DEFINE(smbd_keep_alive_interval);
489 PROC_FILE_DEFINE(smbd_max_receive_size);
490 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
491 PROC_FILE_DEFINE(smbd_max_send_size);
492 PROC_FILE_DEFINE(smbd_send_credit_target);
493 PROC_FILE_DEFINE(smbd_receive_credit_max);
496 static struct proc_dir_entry *proc_fs_cifs;
497 static const struct file_operations cifsFYI_proc_fops;
498 static const struct file_operations cifs_lookup_cache_proc_fops;
499 static const struct file_operations traceSMB_proc_fops;
500 static const struct file_operations cifs_security_flags_proc_fops;
501 static const struct file_operations cifs_linux_ext_proc_fops;
506 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
507 if (proc_fs_cifs == NULL)
510 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
512 #ifdef CONFIG_CIFS_STATS
513 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
515 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
516 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
517 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
518 &cifs_linux_ext_proc_fops);
519 proc_create("SecurityFlags", 0, proc_fs_cifs,
520 &cifs_security_flags_proc_fops);
521 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
522 &cifs_lookup_cache_proc_fops);
523 #ifdef CONFIG_CIFS_SMB_DIRECT
524 proc_create("rdma_readwrite_threshold", 0, proc_fs_cifs,
525 &cifs_rdma_readwrite_threshold_proc_fops);
526 proc_create("smbd_max_frmr_depth", 0, proc_fs_cifs,
527 &cifs_smbd_max_frmr_depth_proc_fops);
528 proc_create("smbd_keep_alive_interval", 0, proc_fs_cifs,
529 &cifs_smbd_keep_alive_interval_proc_fops);
530 proc_create("smbd_max_receive_size", 0, proc_fs_cifs,
531 &cifs_smbd_max_receive_size_proc_fops);
532 proc_create("smbd_max_fragmented_recv_size", 0, proc_fs_cifs,
533 &cifs_smbd_max_fragmented_recv_size_proc_fops);
534 proc_create("smbd_max_send_size", 0, proc_fs_cifs,
535 &cifs_smbd_max_send_size_proc_fops);
536 proc_create("smbd_send_credit_target", 0, proc_fs_cifs,
537 &cifs_smbd_send_credit_target_proc_fops);
538 proc_create("smbd_receive_credit_max", 0, proc_fs_cifs,
539 &cifs_smbd_receive_credit_max_proc_fops);
544 cifs_proc_clean(void)
546 if (proc_fs_cifs == NULL)
549 remove_proc_entry("DebugData", proc_fs_cifs);
550 remove_proc_entry("cifsFYI", proc_fs_cifs);
551 remove_proc_entry("traceSMB", proc_fs_cifs);
552 #ifdef CONFIG_CIFS_STATS
553 remove_proc_entry("Stats", proc_fs_cifs);
555 remove_proc_entry("SecurityFlags", proc_fs_cifs);
556 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
557 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
558 #ifdef CONFIG_CIFS_SMB_DIRECT
559 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
560 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
561 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
562 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
563 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
564 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
565 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
566 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
568 remove_proc_entry("fs/cifs", NULL);
571 static int cifsFYI_proc_show(struct seq_file *m, void *v)
573 seq_printf(m, "%d\n", cifsFYI);
577 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
579 return single_open(file, cifsFYI_proc_show, NULL);
582 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
583 size_t count, loff_t *ppos)
585 char c[2] = { '\0' };
589 rc = get_user(c[0], buffer);
592 if (strtobool(c, &bv) == 0)
594 else if ((c[0] > '1') && (c[0] <= '9'))
595 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
600 static const struct file_operations cifsFYI_proc_fops = {
601 .open = cifsFYI_proc_open,
604 .release = single_release,
605 .write = cifsFYI_proc_write,
608 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
610 seq_printf(m, "%d\n", linuxExtEnabled);
614 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
616 return single_open(file, cifs_linux_ext_proc_show, NULL);
619 static ssize_t cifs_linux_ext_proc_write(struct file *file,
620 const char __user *buffer, size_t count, loff_t *ppos)
624 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
631 static const struct file_operations cifs_linux_ext_proc_fops = {
632 .open = cifs_linux_ext_proc_open,
635 .release = single_release,
636 .write = cifs_linux_ext_proc_write,
639 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
641 seq_printf(m, "%d\n", lookupCacheEnabled);
645 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
647 return single_open(file, cifs_lookup_cache_proc_show, NULL);
650 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
651 const char __user *buffer, size_t count, loff_t *ppos)
655 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
662 static const struct file_operations cifs_lookup_cache_proc_fops = {
663 .open = cifs_lookup_cache_proc_open,
666 .release = single_release,
667 .write = cifs_lookup_cache_proc_write,
670 static int traceSMB_proc_show(struct seq_file *m, void *v)
672 seq_printf(m, "%d\n", traceSMB);
676 static int traceSMB_proc_open(struct inode *inode, struct file *file)
678 return single_open(file, traceSMB_proc_show, NULL);
681 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
682 size_t count, loff_t *ppos)
686 rc = kstrtobool_from_user(buffer, count, &traceSMB);
693 static const struct file_operations traceSMB_proc_fops = {
694 .open = traceSMB_proc_open,
697 .release = single_release,
698 .write = traceSMB_proc_write,
701 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
703 seq_printf(m, "0x%x\n", global_secflags);
707 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
709 return single_open(file, cifs_security_flags_proc_show, NULL);
713 * Ensure that if someone sets a MUST flag, that we disable all other MAY
714 * flags except for the ones corresponding to the given MUST flag. If there are
715 * multiple MUST flags, then try to prefer more secure ones.
718 cifs_security_flags_handle_must_flags(unsigned int *flags)
720 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
722 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
723 *flags = CIFSSEC_MUST_KRB5;
724 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
725 *flags = CIFSSEC_MUST_NTLMSSP;
726 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
727 *flags = CIFSSEC_MUST_NTLMV2;
728 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
729 *flags = CIFSSEC_MUST_NTLM;
730 else if (CIFSSEC_MUST_LANMAN &&
731 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
732 *flags = CIFSSEC_MUST_LANMAN;
733 else if (CIFSSEC_MUST_PLNTXT &&
734 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
735 *flags = CIFSSEC_MUST_PLNTXT;
740 static ssize_t cifs_security_flags_proc_write(struct file *file,
741 const char __user *buffer, size_t count, loff_t *ppos)
745 char flags_string[12];
748 if ((count < 1) || (count > 11))
751 memset(flags_string, 0, 12);
753 if (copy_from_user(flags_string, buffer, count))
757 /* single char or single char followed by null */
758 if (strtobool(flags_string, &bv) == 0) {
759 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
761 } else if (!isdigit(flags_string[0])) {
762 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
768 /* else we have a number */
769 rc = kstrtouint(flags_string, 0, &flags);
771 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
776 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
779 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
783 if (flags & ~CIFSSEC_MASK) {
784 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
785 flags & ~CIFSSEC_MASK);
789 cifs_security_flags_handle_must_flags(&flags);
791 /* flags look ok - update the global security flags for cifs module */
792 global_secflags = flags;
793 if (global_secflags & CIFSSEC_MUST_SIGN) {
794 /* requiring signing implies signing is allowed */
795 global_secflags |= CIFSSEC_MAY_SIGN;
796 cifs_dbg(FYI, "packet signing now required\n");
797 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
798 cifs_dbg(FYI, "packet signing disabled\n");
800 /* BB should we turn on MAY flags for other MUST options? */
804 static const struct file_operations cifs_security_flags_proc_fops = {
805 .open = cifs_security_flags_proc_open,
808 .release = single_release,
809 .write = cifs_security_flags_proc_write,
812 inline void cifs_proc_init(void)
816 inline void cifs_proc_clean(void)