1 /*
2 * fs/cifs_debug.c
3 *
4 * Copyright (C) International Business Machines Corp., 2000,2005
5 *
6 * Modified by Steve French (sfrench@us.ibm.com)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 * the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 #include <linux/fs.h>
23 #include <linux/string.h>
24 #include <linux/ctype.h>
25 #include <linux/module.h>
26 #include <linux/proc_fs.h>
27 #include <linux/uaccess.h>
28 #include "cifspdu.h"
29 #include "cifsglob.h"
30 #include "cifsproto.h"
31 #include "cifs_debug.h"
32 #include "cifsfs.h"
33 #ifdef CONFIG_CIFS_SMB_DIRECT
34 #include "smbdirect.h"
35 #endif
36
37 void
cifs_dump_mem(char * label,void * data,int length)38 cifs_dump_mem(char *label, void *data, int length)
39 {
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,
42 data, length, true);
43 }
44
cifs_dump_detail(void * buf,struct TCP_Server_Info * server)45 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
46 {
47 #ifdef CONFIG_CIFS_DEBUG2
48 struct smb_hdr *smb = (struct smb_hdr *)buf;
49
50 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
51 smb->Command, smb->Status.CifsError,
52 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
53 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
54 server->ops->calc_smb_size(smb, server));
55 #endif /* CONFIG_CIFS_DEBUG2 */
56 }
57
cifs_dump_mids(struct TCP_Server_Info * server)58 void cifs_dump_mids(struct TCP_Server_Info *server)
59 {
60 #ifdef CONFIG_CIFS_DEBUG2
61 struct list_head *tmp;
62 struct mid_q_entry *mid_entry;
63
64 if (server == NULL)
65 return;
66
67 cifs_dbg(VFS, "Dump pending requests:\n");
68 spin_lock(&GlobalMid_Lock);
69 list_for_each(tmp, &server->pending_mid_q) {
70 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
71 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
72 mid_entry->mid_state,
73 le16_to_cpu(mid_entry->command),
74 mid_entry->pid,
75 mid_entry->callback_data,
76 mid_entry->mid);
77 #ifdef CONFIG_CIFS_STATS2
78 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
79 mid_entry->large_buf,
80 mid_entry->resp_buf,
81 mid_entry->when_received,
82 jiffies);
83 #endif /* STATS2 */
84 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
85 mid_entry->multiRsp, mid_entry->multiEnd);
86 if (mid_entry->resp_buf) {
87 cifs_dump_detail(mid_entry->resp_buf, server);
88 cifs_dump_mem("existing buf: ",
89 mid_entry->resp_buf, 62);
90 }
91 }
92 spin_unlock(&GlobalMid_Lock);
93 #endif /* CONFIG_CIFS_DEBUG2 */
94 }
95
96 #ifdef CONFIG_PROC_FS
cifs_debug_tcon(struct seq_file * m,struct cifs_tcon * tcon)97 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
98 {
99 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
100
101 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
102 if (tcon->nativeFileSystem)
103 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
104 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
105 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
106 le32_to_cpu(tcon->fsAttrInfo.Attributes),
107 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
108 tcon->tidStatus);
109 if (dev_type == FILE_DEVICE_DISK)
110 seq_puts(m, " type: DISK ");
111 else if (dev_type == FILE_DEVICE_CD_ROM)
112 seq_puts(m, " type: CDROM ");
113 else
114 seq_printf(m, " type: %d ", dev_type);
115 if (tcon->seal)
116 seq_printf(m, " Encrypted");
117 if (tcon->nocase)
118 seq_printf(m, " nocase");
119 if (tcon->unix_ext)
120 seq_printf(m, " POSIX Extensions");
121 if (tcon->ses->server->ops->dump_share_caps)
122 tcon->ses->server->ops->dump_share_caps(m, tcon);
123
124 if (tcon->need_reconnect)
125 seq_puts(m, "\tDISCONNECTED ");
126 seq_putc(m, '\n');
127 }
128
129 static void
cifs_dump_iface(struct seq_file * m,struct cifs_server_iface * iface)130 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
131 {
132 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
133 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
134
135 seq_printf(m, "\t\tSpeed: %zu bps\n", iface->speed);
136 seq_puts(m, "\t\tCapabilities: ");
137 if (iface->rdma_capable)
138 seq_puts(m, "rdma ");
139 if (iface->rss_capable)
140 seq_puts(m, "rss ");
141 seq_putc(m, '\n');
142 if (iface->sockaddr.ss_family == AF_INET)
143 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
144 else if (iface->sockaddr.ss_family == AF_INET6)
145 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
146 }
147
cifs_debug_data_proc_show(struct seq_file * m,void * v)148 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
149 {
150 struct list_head *tmp1, *tmp2, *tmp3;
151 struct mid_q_entry *mid_entry;
152 struct TCP_Server_Info *server;
153 struct cifs_ses *ses;
154 struct cifs_tcon *tcon;
155 int i, j;
156
157 seq_puts(m,
158 "Display Internal CIFS Data Structures for Debugging\n"
159 "---------------------------------------------------\n");
160 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
161 seq_printf(m, "Features:");
162 #ifdef CONFIG_CIFS_DFS_UPCALL
163 seq_printf(m, " DFS");
164 #endif
165 #ifdef CONFIG_CIFS_FSCACHE
166 seq_printf(m, ",FSCACHE");
167 #endif
168 #ifdef CONFIG_CIFS_SMB_DIRECT
169 seq_printf(m, ",SMB_DIRECT");
170 #endif
171 #ifdef CONFIG_CIFS_STATS2
172 seq_printf(m, ",STATS2");
173 #else
174 seq_printf(m, ",STATS");
175 #endif
176 #ifdef CONFIG_CIFS_DEBUG2
177 seq_printf(m, ",DEBUG2");
178 #elif defined(CONFIG_CIFS_DEBUG)
179 seq_printf(m, ",DEBUG");
180 #endif
181 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
182 seq_printf(m, ",ALLOW_INSECURE_LEGACY");
183 #endif
184 #ifdef CONFIG_CIFS_WEAK_PW_HASH
185 seq_printf(m, ",WEAK_PW_HASH");
186 #endif
187 #ifdef CONFIG_CIFS_POSIX
188 seq_printf(m, ",CIFS_POSIX");
189 #endif
190 #ifdef CONFIG_CIFS_UPCALL
191 seq_printf(m, ",UPCALL(SPNEGO)");
192 #endif
193 #ifdef CONFIG_CIFS_XATTR
194 seq_printf(m, ",XATTR");
195 #endif
196 #ifdef CONFIG_CIFS_ACL
197 seq_printf(m, ",ACL");
198 #endif
199 seq_putc(m, '\n');
200 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
201 seq_printf(m, "Servers:");
202
203 i = 0;
204 spin_lock(&cifs_tcp_ses_lock);
205 list_for_each(tmp1, &cifs_tcp_ses_list) {
206 server = list_entry(tmp1, struct TCP_Server_Info,
207 tcp_ses_list);
208
209 #ifdef CONFIG_CIFS_SMB_DIRECT
210 if (!server->rdma)
211 goto skip_rdma;
212
213 if (!server->smbd_conn) {
214 seq_printf(m, "\nSMBDirect transport not available");
215 goto skip_rdma;
216 }
217
218 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
219 "transport status: %x",
220 server->smbd_conn->protocol,
221 server->smbd_conn->transport_status);
222 seq_printf(m, "\nConn receive_credit_max: %x "
223 "send_credit_target: %x max_send_size: %x",
224 server->smbd_conn->receive_credit_max,
225 server->smbd_conn->send_credit_target,
226 server->smbd_conn->max_send_size);
227 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
228 "max_fragmented_send_size: %x max_receive_size:%x",
229 server->smbd_conn->max_fragmented_recv_size,
230 server->smbd_conn->max_fragmented_send_size,
231 server->smbd_conn->max_receive_size);
232 seq_printf(m, "\nConn keep_alive_interval: %x "
233 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
234 server->smbd_conn->keep_alive_interval,
235 server->smbd_conn->max_readwrite_size,
236 server->smbd_conn->rdma_readwrite_threshold);
237 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
238 "count_put_receive_buffer: %x count_send_empty: %x",
239 server->smbd_conn->count_get_receive_buffer,
240 server->smbd_conn->count_put_receive_buffer,
241 server->smbd_conn->count_send_empty);
242 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
243 "count_enqueue_reassembly_queue: %x "
244 "count_dequeue_reassembly_queue: %x "
245 "fragment_reassembly_remaining: %x "
246 "reassembly_data_length: %x "
247 "reassembly_queue_length: %x",
248 server->smbd_conn->count_reassembly_queue,
249 server->smbd_conn->count_enqueue_reassembly_queue,
250 server->smbd_conn->count_dequeue_reassembly_queue,
251 server->smbd_conn->fragment_reassembly_remaining,
252 server->smbd_conn->reassembly_data_length,
253 server->smbd_conn->reassembly_queue_length);
254 seq_printf(m, "\nCurrent Credits send_credits: %x "
255 "receive_credits: %x receive_credit_target: %x",
256 atomic_read(&server->smbd_conn->send_credits),
257 atomic_read(&server->smbd_conn->receive_credits),
258 server->smbd_conn->receive_credit_target);
259 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
260 " %x smbd_send_pending: %x smbd_recv_pending: %x",
261 atomic_read(&server->smbd_conn->send_pending),
262 atomic_read(&server->smbd_conn->send_payload_pending),
263 server->smbd_conn->smbd_send_pending,
264 server->smbd_conn->smbd_recv_pending);
265 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
266 "count_empty_packet_queue: %x",
267 server->smbd_conn->count_receive_queue,
268 server->smbd_conn->count_empty_packet_queue);
269 seq_printf(m, "\nMR responder_resources: %x "
270 "max_frmr_depth: %x mr_type: %x",
271 server->smbd_conn->responder_resources,
272 server->smbd_conn->max_frmr_depth,
273 server->smbd_conn->mr_type);
274 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
275 atomic_read(&server->smbd_conn->mr_ready_count),
276 atomic_read(&server->smbd_conn->mr_used_count));
277 skip_rdma:
278 #endif
279 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
280 server->credits, server->dialect);
281 if (server->sign)
282 seq_printf(m, " signed");
283 if (server->posix_ext_supported)
284 seq_printf(m, " posix");
285
286 i++;
287 list_for_each(tmp2, &server->smb_ses_list) {
288 ses = list_entry(tmp2, struct cifs_ses,
289 smb_ses_list);
290 if ((ses->serverDomain == NULL) ||
291 (ses->serverOS == NULL) ||
292 (ses->serverNOS == NULL)) {
293 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
294 i, ses->serverName, ses->ses_count,
295 ses->capabilities, ses->status);
296 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
297 seq_printf(m, "Guest\t");
298 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
299 seq_printf(m, "Anonymous\t");
300 } else {
301 seq_printf(m,
302 "\n%d) Name: %s Domain: %s Uses: %d OS:"
303 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
304 " session status: %d\t",
305 i, ses->serverName, ses->serverDomain,
306 ses->ses_count, ses->serverOS, ses->serverNOS,
307 ses->capabilities, ses->status);
308 }
309 if (server->rdma)
310 seq_printf(m, "RDMA\n\t");
311 seq_printf(m, "TCP status: %d\n\tLocal Users To "
312 "Server: %d SecMode: 0x%x Req On Wire: %d",
313 server->tcpStatus, server->srv_count,
314 server->sec_mode, in_flight(server));
315
316 #ifdef CONFIG_CIFS_STATS2
317 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
318 atomic_read(&server->in_send),
319 atomic_read(&server->num_waiters));
320 #endif
321
322 seq_puts(m, "\n\tShares:");
323 j = 0;
324
325 seq_printf(m, "\n\t%d) IPC: ", j);
326 if (ses->tcon_ipc)
327 cifs_debug_tcon(m, ses->tcon_ipc);
328 else
329 seq_puts(m, "none\n");
330
331 list_for_each(tmp3, &ses->tcon_list) {
332 tcon = list_entry(tmp3, struct cifs_tcon,
333 tcon_list);
334 ++j;
335 seq_printf(m, "\n\t%d) ", j);
336 cifs_debug_tcon(m, tcon);
337 }
338
339 seq_puts(m, "\n\tMIDs:\n");
340
341 spin_lock(&GlobalMid_Lock);
342 list_for_each(tmp3, &server->pending_mid_q) {
343 mid_entry = list_entry(tmp3, struct mid_q_entry,
344 qhead);
345 seq_printf(m, "\tState: %d com: %d pid:"
346 " %d cbdata: %p mid %llu\n",
347 mid_entry->mid_state,
348 le16_to_cpu(mid_entry->command),
349 mid_entry->pid,
350 mid_entry->callback_data,
351 mid_entry->mid);
352 }
353 spin_unlock(&GlobalMid_Lock);
354
355 spin_lock(&ses->iface_lock);
356 if (ses->iface_count)
357 seq_printf(m, "\n\tServer interfaces: %zu\n",
358 ses->iface_count);
359 for (j = 0; j < ses->iface_count; j++) {
360 seq_printf(m, "\t%d)\n", j);
361 cifs_dump_iface(m, &ses->iface_list[j]);
362 }
363 spin_unlock(&ses->iface_lock);
364 }
365 }
366 spin_unlock(&cifs_tcp_ses_lock);
367 seq_putc(m, '\n');
368
369 /* BB add code to dump additional info such as TCP session info now */
370 return 0;
371 }
372
cifs_stats_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)373 static ssize_t cifs_stats_proc_write(struct file *file,
374 const char __user *buffer, size_t count, loff_t *ppos)
375 {
376 bool bv;
377 int rc;
378 struct list_head *tmp1, *tmp2, *tmp3;
379 struct TCP_Server_Info *server;
380 struct cifs_ses *ses;
381 struct cifs_tcon *tcon;
382
383 rc = kstrtobool_from_user(buffer, count, &bv);
384 if (rc == 0) {
385 #ifdef CONFIG_CIFS_STATS2
386 int i;
387
388 atomic_set(&totBufAllocCount, 0);
389 atomic_set(&totSmBufAllocCount, 0);
390 #endif /* CONFIG_CIFS_STATS2 */
391 atomic_set(&tcpSesReconnectCount, 0);
392 atomic_set(&tconInfoReconnectCount, 0);
393
394 spin_lock(&GlobalMid_Lock);
395 GlobalMaxActiveXid = 0;
396 GlobalCurrentXid = 0;
397 spin_unlock(&GlobalMid_Lock);
398 spin_lock(&cifs_tcp_ses_lock);
399 list_for_each(tmp1, &cifs_tcp_ses_list) {
400 server = list_entry(tmp1, struct TCP_Server_Info,
401 tcp_ses_list);
402 #ifdef CONFIG_CIFS_STATS2
403 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++)
404 atomic_set(&server->smb2slowcmd[i], 0);
405 #endif /* CONFIG_CIFS_STATS2 */
406 list_for_each(tmp2, &server->smb_ses_list) {
407 ses = list_entry(tmp2, struct cifs_ses,
408 smb_ses_list);
409 list_for_each(tmp3, &ses->tcon_list) {
410 tcon = list_entry(tmp3,
411 struct cifs_tcon,
412 tcon_list);
413 atomic_set(&tcon->num_smbs_sent, 0);
414 spin_lock(&tcon->stat_lock);
415 tcon->bytes_read = 0;
416 tcon->bytes_written = 0;
417 spin_unlock(&tcon->stat_lock);
418 if (server->ops->clear_stats)
419 server->ops->clear_stats(tcon);
420 }
421 }
422 }
423 spin_unlock(&cifs_tcp_ses_lock);
424 } else {
425 return rc;
426 }
427
428 return count;
429 }
430
cifs_stats_proc_show(struct seq_file * m,void * v)431 static int cifs_stats_proc_show(struct seq_file *m, void *v)
432 {
433 int i;
434 #ifdef CONFIG_CIFS_STATS2
435 int j;
436 #endif /* STATS2 */
437 struct list_head *tmp1, *tmp2, *tmp3;
438 struct TCP_Server_Info *server;
439 struct cifs_ses *ses;
440 struct cifs_tcon *tcon;
441
442 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
443 sesInfoAllocCount.counter);
444 seq_printf(m, "Share (unique mount targets): %d\n",
445 tconInfoAllocCount.counter);
446 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
447 bufAllocCount.counter,
448 cifs_min_rcv + tcpSesAllocCount.counter);
449 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
450 smBufAllocCount.counter, cifs_min_small);
451 #ifdef CONFIG_CIFS_STATS2
452 seq_printf(m, "Total Large %d Small %d Allocations\n",
453 atomic_read(&totBufAllocCount),
454 atomic_read(&totSmBufAllocCount));
455 #endif /* CONFIG_CIFS_STATS2 */
456
457 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
458 seq_printf(m,
459 "\n%d session %d share reconnects\n",
460 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
461
462 seq_printf(m,
463 "Total vfs operations: %d maximum at one time: %d\n",
464 GlobalCurrentXid, GlobalMaxActiveXid);
465
466 i = 0;
467 spin_lock(&cifs_tcp_ses_lock);
468 list_for_each(tmp1, &cifs_tcp_ses_list) {
469 server = list_entry(tmp1, struct TCP_Server_Info,
470 tcp_ses_list);
471 #ifdef CONFIG_CIFS_STATS2
472 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
473 if (atomic_read(&server->smb2slowcmd[j]))
474 seq_printf(m, "%d slow responses from %s for command %d\n",
475 atomic_read(&server->smb2slowcmd[j]),
476 server->hostname, j);
477 #endif /* STATS2 */
478 list_for_each(tmp2, &server->smb_ses_list) {
479 ses = list_entry(tmp2, struct cifs_ses,
480 smb_ses_list);
481 list_for_each(tmp3, &ses->tcon_list) {
482 tcon = list_entry(tmp3,
483 struct cifs_tcon,
484 tcon_list);
485 i++;
486 seq_printf(m, "\n%d) %s", i, tcon->treeName);
487 if (tcon->need_reconnect)
488 seq_puts(m, "\tDISCONNECTED ");
489 seq_printf(m, "\nSMBs: %d",
490 atomic_read(&tcon->num_smbs_sent));
491 if (server->ops->print_stats)
492 server->ops->print_stats(m, tcon);
493 }
494 }
495 }
496 spin_unlock(&cifs_tcp_ses_lock);
497
498 seq_putc(m, '\n');
499 return 0;
500 }
501
cifs_stats_proc_open(struct inode * inode,struct file * file)502 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
503 {
504 return single_open(file, cifs_stats_proc_show, NULL);
505 }
506
507 static const struct file_operations cifs_stats_proc_fops = {
508 .open = cifs_stats_proc_open,
509 .read = seq_read,
510 .llseek = seq_lseek,
511 .release = single_release,
512 .write = cifs_stats_proc_write,
513 };
514
515 #ifdef CONFIG_CIFS_SMB_DIRECT
516 #define PROC_FILE_DEFINE(name) \
517 static ssize_t name##_write(struct file *file, const char __user *buffer, \
518 size_t count, loff_t *ppos) \
519 { \
520 int rc; \
521 rc = kstrtoint_from_user(buffer, count, 10, & name); \
522 if (rc) \
523 return rc; \
524 return count; \
525 } \
526 static int name##_proc_show(struct seq_file *m, void *v) \
527 { \
528 seq_printf(m, "%d\n", name ); \
529 return 0; \
530 } \
531 static int name##_open(struct inode *inode, struct file *file) \
532 { \
533 return single_open(file, name##_proc_show, NULL); \
534 } \
535 \
536 static const struct file_operations cifs_##name##_proc_fops = { \
537 .open = name##_open, \
538 .read = seq_read, \
539 .llseek = seq_lseek, \
540 .release = single_release, \
541 .write = name##_write, \
542 }
543
544 PROC_FILE_DEFINE(rdma_readwrite_threshold);
545 PROC_FILE_DEFINE(smbd_max_frmr_depth);
546 PROC_FILE_DEFINE(smbd_keep_alive_interval);
547 PROC_FILE_DEFINE(smbd_max_receive_size);
548 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
549 PROC_FILE_DEFINE(smbd_max_send_size);
550 PROC_FILE_DEFINE(smbd_send_credit_target);
551 PROC_FILE_DEFINE(smbd_receive_credit_max);
552 #endif
553
554 static struct proc_dir_entry *proc_fs_cifs;
555 static const struct file_operations cifsFYI_proc_fops;
556 static const struct file_operations cifs_lookup_cache_proc_fops;
557 static const struct file_operations traceSMB_proc_fops;
558 static const struct file_operations cifs_security_flags_proc_fops;
559 static const struct file_operations cifs_linux_ext_proc_fops;
560
561 void
cifs_proc_init(void)562 cifs_proc_init(void)
563 {
564 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
565 if (proc_fs_cifs == NULL)
566 return;
567
568 proc_create_single("DebugData", 0, proc_fs_cifs,
569 cifs_debug_data_proc_show);
570
571 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
572 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
573 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
574 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
575 &cifs_linux_ext_proc_fops);
576 proc_create("SecurityFlags", 0644, proc_fs_cifs,
577 &cifs_security_flags_proc_fops);
578 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
579 &cifs_lookup_cache_proc_fops);
580 #ifdef CONFIG_CIFS_SMB_DIRECT
581 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
582 &cifs_rdma_readwrite_threshold_proc_fops);
583 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
584 &cifs_smbd_max_frmr_depth_proc_fops);
585 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
586 &cifs_smbd_keep_alive_interval_proc_fops);
587 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
588 &cifs_smbd_max_receive_size_proc_fops);
589 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
590 &cifs_smbd_max_fragmented_recv_size_proc_fops);
591 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
592 &cifs_smbd_max_send_size_proc_fops);
593 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
594 &cifs_smbd_send_credit_target_proc_fops);
595 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
596 &cifs_smbd_receive_credit_max_proc_fops);
597 #endif
598 }
599
600 void
cifs_proc_clean(void)601 cifs_proc_clean(void)
602 {
603 if (proc_fs_cifs == NULL)
604 return;
605
606 remove_proc_entry("DebugData", proc_fs_cifs);
607 remove_proc_entry("cifsFYI", proc_fs_cifs);
608 remove_proc_entry("traceSMB", proc_fs_cifs);
609 remove_proc_entry("Stats", proc_fs_cifs);
610 remove_proc_entry("SecurityFlags", proc_fs_cifs);
611 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
612 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
613 #ifdef CONFIG_CIFS_SMB_DIRECT
614 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
615 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
616 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
617 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
618 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
619 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
620 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
621 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
622 #endif
623 remove_proc_entry("fs/cifs", NULL);
624 }
625
cifsFYI_proc_show(struct seq_file * m,void * v)626 static int cifsFYI_proc_show(struct seq_file *m, void *v)
627 {
628 seq_printf(m, "%d\n", cifsFYI);
629 return 0;
630 }
631
cifsFYI_proc_open(struct inode * inode,struct file * file)632 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
633 {
634 return single_open(file, cifsFYI_proc_show, NULL);
635 }
636
cifsFYI_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)637 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
638 size_t count, loff_t *ppos)
639 {
640 char c[2] = { '\0' };
641 bool bv;
642 int rc;
643
644 rc = get_user(c[0], buffer);
645 if (rc)
646 return rc;
647 if (strtobool(c, &bv) == 0)
648 cifsFYI = bv;
649 else if ((c[0] > '1') && (c[0] <= '9'))
650 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
651 else
652 return -EINVAL;
653
654 return count;
655 }
656
657 static const struct file_operations cifsFYI_proc_fops = {
658 .open = cifsFYI_proc_open,
659 .read = seq_read,
660 .llseek = seq_lseek,
661 .release = single_release,
662 .write = cifsFYI_proc_write,
663 };
664
cifs_linux_ext_proc_show(struct seq_file * m,void * v)665 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
666 {
667 seq_printf(m, "%d\n", linuxExtEnabled);
668 return 0;
669 }
670
cifs_linux_ext_proc_open(struct inode * inode,struct file * file)671 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
672 {
673 return single_open(file, cifs_linux_ext_proc_show, NULL);
674 }
675
cifs_linux_ext_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)676 static ssize_t cifs_linux_ext_proc_write(struct file *file,
677 const char __user *buffer, size_t count, loff_t *ppos)
678 {
679 int rc;
680
681 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
682 if (rc)
683 return rc;
684
685 return count;
686 }
687
688 static const struct file_operations cifs_linux_ext_proc_fops = {
689 .open = cifs_linux_ext_proc_open,
690 .read = seq_read,
691 .llseek = seq_lseek,
692 .release = single_release,
693 .write = cifs_linux_ext_proc_write,
694 };
695
cifs_lookup_cache_proc_show(struct seq_file * m,void * v)696 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
697 {
698 seq_printf(m, "%d\n", lookupCacheEnabled);
699 return 0;
700 }
701
cifs_lookup_cache_proc_open(struct inode * inode,struct file * file)702 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
703 {
704 return single_open(file, cifs_lookup_cache_proc_show, NULL);
705 }
706
cifs_lookup_cache_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)707 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
708 const char __user *buffer, size_t count, loff_t *ppos)
709 {
710 int rc;
711
712 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
713 if (rc)
714 return rc;
715
716 return count;
717 }
718
719 static const struct file_operations cifs_lookup_cache_proc_fops = {
720 .open = cifs_lookup_cache_proc_open,
721 .read = seq_read,
722 .llseek = seq_lseek,
723 .release = single_release,
724 .write = cifs_lookup_cache_proc_write,
725 };
726
traceSMB_proc_show(struct seq_file * m,void * v)727 static int traceSMB_proc_show(struct seq_file *m, void *v)
728 {
729 seq_printf(m, "%d\n", traceSMB);
730 return 0;
731 }
732
traceSMB_proc_open(struct inode * inode,struct file * file)733 static int traceSMB_proc_open(struct inode *inode, struct file *file)
734 {
735 return single_open(file, traceSMB_proc_show, NULL);
736 }
737
traceSMB_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)738 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
739 size_t count, loff_t *ppos)
740 {
741 int rc;
742
743 rc = kstrtobool_from_user(buffer, count, &traceSMB);
744 if (rc)
745 return rc;
746
747 return count;
748 }
749
750 static const struct file_operations traceSMB_proc_fops = {
751 .open = traceSMB_proc_open,
752 .read = seq_read,
753 .llseek = seq_lseek,
754 .release = single_release,
755 .write = traceSMB_proc_write,
756 };
757
cifs_security_flags_proc_show(struct seq_file * m,void * v)758 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
759 {
760 seq_printf(m, "0x%x\n", global_secflags);
761 return 0;
762 }
763
cifs_security_flags_proc_open(struct inode * inode,struct file * file)764 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
765 {
766 return single_open(file, cifs_security_flags_proc_show, NULL);
767 }
768
769 /*
770 * Ensure that if someone sets a MUST flag, that we disable all other MAY
771 * flags except for the ones corresponding to the given MUST flag. If there are
772 * multiple MUST flags, then try to prefer more secure ones.
773 */
774 static void
cifs_security_flags_handle_must_flags(unsigned int * flags)775 cifs_security_flags_handle_must_flags(unsigned int *flags)
776 {
777 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
778
779 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
780 *flags = CIFSSEC_MUST_KRB5;
781 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
782 *flags = CIFSSEC_MUST_NTLMSSP;
783 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
784 *flags = CIFSSEC_MUST_NTLMV2;
785 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
786 *flags = CIFSSEC_MUST_NTLM;
787 else if (CIFSSEC_MUST_LANMAN &&
788 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
789 *flags = CIFSSEC_MUST_LANMAN;
790 else if (CIFSSEC_MUST_PLNTXT &&
791 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
792 *flags = CIFSSEC_MUST_PLNTXT;
793
794 *flags |= signflags;
795 }
796
cifs_security_flags_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)797 static ssize_t cifs_security_flags_proc_write(struct file *file,
798 const char __user *buffer, size_t count, loff_t *ppos)
799 {
800 int rc;
801 unsigned int flags;
802 char flags_string[12];
803 bool bv;
804
805 if ((count < 1) || (count > 11))
806 return -EINVAL;
807
808 memset(flags_string, 0, 12);
809
810 if (copy_from_user(flags_string, buffer, count))
811 return -EFAULT;
812
813 if (count < 3) {
814 /* single char or single char followed by null */
815 if (strtobool(flags_string, &bv) == 0) {
816 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
817 return count;
818 } else if (!isdigit(flags_string[0])) {
819 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
820 flags_string);
821 return -EINVAL;
822 }
823 }
824
825 /* else we have a number */
826 rc = kstrtouint(flags_string, 0, &flags);
827 if (rc) {
828 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
829 flags_string);
830 return rc;
831 }
832
833 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
834
835 if (flags == 0) {
836 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
837 return -EINVAL;
838 }
839
840 if (flags & ~CIFSSEC_MASK) {
841 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
842 flags & ~CIFSSEC_MASK);
843 return -EINVAL;
844 }
845
846 cifs_security_flags_handle_must_flags(&flags);
847
848 /* flags look ok - update the global security flags for cifs module */
849 global_secflags = flags;
850 if (global_secflags & CIFSSEC_MUST_SIGN) {
851 /* requiring signing implies signing is allowed */
852 global_secflags |= CIFSSEC_MAY_SIGN;
853 cifs_dbg(FYI, "packet signing now required\n");
854 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
855 cifs_dbg(FYI, "packet signing disabled\n");
856 }
857 /* BB should we turn on MAY flags for other MUST options? */
858 return count;
859 }
860
861 static const struct file_operations cifs_security_flags_proc_fops = {
862 .open = cifs_security_flags_proc_open,
863 .read = seq_read,
864 .llseek = seq_lseek,
865 .release = single_release,
866 .write = cifs_security_flags_proc_write,
867 };
868 #else
cifs_proc_init(void)869 inline void cifs_proc_init(void)
870 {
871 }
872
cifs_proc_clean(void)873 inline void cifs_proc_clean(void)
874 {
875 }
876 #endif /* PROC_FS */
877