]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - fs/cifs/cifs_debug.c
treewide: kmalloc() -> kmalloc_array()
[mirror_ubuntu-hirsute-kernel.git] / fs / cifs / cifs_debug.c
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
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
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
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
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 int cifs_debug_data_proc_show(struct seq_file *m, void *v)
130 {
131 struct list_head *tmp1, *tmp2, *tmp3;
132 struct mid_q_entry *mid_entry;
133 struct TCP_Server_Info *server;
134 struct cifs_ses *ses;
135 struct cifs_tcon *tcon;
136 int i, j;
137
138 seq_puts(m,
139 "Display Internal CIFS Data Structures for Debugging\n"
140 "---------------------------------------------------\n");
141 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
142 seq_printf(m, "Features:");
143 #ifdef CONFIG_CIFS_DFS_UPCALL
144 seq_printf(m, " dfs");
145 #endif
146 #ifdef CONFIG_CIFS_FSCACHE
147 seq_printf(m, " fscache");
148 #endif
149 #ifdef CONFIG_CIFS_WEAK_PW_HASH
150 seq_printf(m, " lanman");
151 #endif
152 #ifdef CONFIG_CIFS_POSIX
153 seq_printf(m, " posix");
154 #endif
155 #ifdef CONFIG_CIFS_UPCALL
156 seq_printf(m, " spnego");
157 #endif
158 #ifdef CONFIG_CIFS_XATTR
159 seq_printf(m, " xattr");
160 #endif
161 #ifdef CONFIG_CIFS_ACL
162 seq_printf(m, " acl");
163 #endif
164 seq_putc(m, '\n');
165 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
166 seq_printf(m, "Servers:");
167
168 i = 0;
169 spin_lock(&cifs_tcp_ses_lock);
170 list_for_each(tmp1, &cifs_tcp_ses_list) {
171 server = list_entry(tmp1, struct TCP_Server_Info,
172 tcp_ses_list);
173
174 #ifdef CONFIG_CIFS_SMB_DIRECT
175 if (!server->rdma)
176 goto skip_rdma;
177
178 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
179 "transport status: %x",
180 server->smbd_conn->protocol,
181 server->smbd_conn->transport_status);
182 seq_printf(m, "\nConn receive_credit_max: %x "
183 "send_credit_target: %x max_send_size: %x",
184 server->smbd_conn->receive_credit_max,
185 server->smbd_conn->send_credit_target,
186 server->smbd_conn->max_send_size);
187 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
188 "max_fragmented_send_size: %x max_receive_size:%x",
189 server->smbd_conn->max_fragmented_recv_size,
190 server->smbd_conn->max_fragmented_send_size,
191 server->smbd_conn->max_receive_size);
192 seq_printf(m, "\nConn keep_alive_interval: %x "
193 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
194 server->smbd_conn->keep_alive_interval,
195 server->smbd_conn->max_readwrite_size,
196 server->smbd_conn->rdma_readwrite_threshold);
197 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
198 "count_put_receive_buffer: %x count_send_empty: %x",
199 server->smbd_conn->count_get_receive_buffer,
200 server->smbd_conn->count_put_receive_buffer,
201 server->smbd_conn->count_send_empty);
202 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
203 "count_enqueue_reassembly_queue: %x "
204 "count_dequeue_reassembly_queue: %x "
205 "fragment_reassembly_remaining: %x "
206 "reassembly_data_length: %x "
207 "reassembly_queue_length: %x",
208 server->smbd_conn->count_reassembly_queue,
209 server->smbd_conn->count_enqueue_reassembly_queue,
210 server->smbd_conn->count_dequeue_reassembly_queue,
211 server->smbd_conn->fragment_reassembly_remaining,
212 server->smbd_conn->reassembly_data_length,
213 server->smbd_conn->reassembly_queue_length);
214 seq_printf(m, "\nCurrent Credits send_credits: %x "
215 "receive_credits: %x receive_credit_target: %x",
216 atomic_read(&server->smbd_conn->send_credits),
217 atomic_read(&server->smbd_conn->receive_credits),
218 server->smbd_conn->receive_credit_target);
219 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
220 " %x smbd_send_pending: %x smbd_recv_pending: %x",
221 atomic_read(&server->smbd_conn->send_pending),
222 atomic_read(&server->smbd_conn->send_payload_pending),
223 server->smbd_conn->smbd_send_pending,
224 server->smbd_conn->smbd_recv_pending);
225 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
226 "count_empty_packet_queue: %x",
227 server->smbd_conn->count_receive_queue,
228 server->smbd_conn->count_empty_packet_queue);
229 seq_printf(m, "\nMR responder_resources: %x "
230 "max_frmr_depth: %x mr_type: %x",
231 server->smbd_conn->responder_resources,
232 server->smbd_conn->max_frmr_depth,
233 server->smbd_conn->mr_type);
234 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
235 atomic_read(&server->smbd_conn->mr_ready_count),
236 atomic_read(&server->smbd_conn->mr_used_count));
237 skip_rdma:
238 #endif
239 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
240 server->credits, server->dialect);
241 if (server->sign)
242 seq_printf(m, " signed");
243 #ifdef CONFIG_CIFS_SMB311
244 if (server->posix_ext_supported)
245 seq_printf(m, " posix");
246 #endif /* 3.1.1 */
247 i++;
248 list_for_each(tmp2, &server->smb_ses_list) {
249 ses = list_entry(tmp2, struct cifs_ses,
250 smb_ses_list);
251 if ((ses->serverDomain == NULL) ||
252 (ses->serverOS == NULL) ||
253 (ses->serverNOS == NULL)) {
254 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
255 i, ses->serverName, ses->ses_count,
256 ses->capabilities, ses->status);
257 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
258 seq_printf(m, "Guest\t");
259 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
260 seq_printf(m, "Anonymous\t");
261 } else {
262 seq_printf(m,
263 "\n%d) Name: %s Domain: %s Uses: %d OS:"
264 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
265 " session status: %d\t",
266 i, ses->serverName, ses->serverDomain,
267 ses->ses_count, ses->serverOS, ses->serverNOS,
268 ses->capabilities, ses->status);
269 }
270 if (server->rdma)
271 seq_printf(m, "RDMA\n\t");
272 seq_printf(m, "TCP status: %d\n\tLocal Users To "
273 "Server: %d SecMode: 0x%x Req On Wire: %d",
274 server->tcpStatus, server->srv_count,
275 server->sec_mode, in_flight(server));
276
277 #ifdef CONFIG_CIFS_STATS2
278 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
279 atomic_read(&server->in_send),
280 atomic_read(&server->num_waiters));
281 #endif
282
283 seq_puts(m, "\n\tShares:");
284 j = 0;
285
286 seq_printf(m, "\n\t%d) IPC: ", j);
287 if (ses->tcon_ipc)
288 cifs_debug_tcon(m, ses->tcon_ipc);
289 else
290 seq_puts(m, "none\n");
291
292 list_for_each(tmp3, &ses->tcon_list) {
293 tcon = list_entry(tmp3, struct cifs_tcon,
294 tcon_list);
295 ++j;
296 seq_printf(m, "\n\t%d) ", j);
297 cifs_debug_tcon(m, tcon);
298 }
299
300 seq_puts(m, "\n\tMIDs:\n");
301
302 spin_lock(&GlobalMid_Lock);
303 list_for_each(tmp3, &server->pending_mid_q) {
304 mid_entry = list_entry(tmp3, struct mid_q_entry,
305 qhead);
306 seq_printf(m, "\tState: %d com: %d pid:"
307 " %d cbdata: %p mid %llu\n",
308 mid_entry->mid_state,
309 le16_to_cpu(mid_entry->command),
310 mid_entry->pid,
311 mid_entry->callback_data,
312 mid_entry->mid);
313 }
314 spin_unlock(&GlobalMid_Lock);
315 }
316 }
317 spin_unlock(&cifs_tcp_ses_lock);
318 seq_putc(m, '\n');
319
320 /* BB add code to dump additional info such as TCP session info now */
321 return 0;
322 }
323
324 #ifdef CONFIG_CIFS_STATS
325 static ssize_t cifs_stats_proc_write(struct file *file,
326 const char __user *buffer, size_t count, loff_t *ppos)
327 {
328 bool bv;
329 int rc;
330 struct list_head *tmp1, *tmp2, *tmp3;
331 struct TCP_Server_Info *server;
332 struct cifs_ses *ses;
333 struct cifs_tcon *tcon;
334
335 rc = kstrtobool_from_user(buffer, count, &bv);
336 if (rc == 0) {
337 #ifdef CONFIG_CIFS_STATS2
338 atomic_set(&totBufAllocCount, 0);
339 atomic_set(&totSmBufAllocCount, 0);
340 #endif /* CONFIG_CIFS_STATS2 */
341 spin_lock(&cifs_tcp_ses_lock);
342 list_for_each(tmp1, &cifs_tcp_ses_list) {
343 server = list_entry(tmp1, struct TCP_Server_Info,
344 tcp_ses_list);
345 list_for_each(tmp2, &server->smb_ses_list) {
346 ses = list_entry(tmp2, struct cifs_ses,
347 smb_ses_list);
348 list_for_each(tmp3, &ses->tcon_list) {
349 tcon = list_entry(tmp3,
350 struct cifs_tcon,
351 tcon_list);
352 atomic_set(&tcon->num_smbs_sent, 0);
353 if (server->ops->clear_stats)
354 server->ops->clear_stats(tcon);
355 }
356 }
357 }
358 spin_unlock(&cifs_tcp_ses_lock);
359 } else {
360 return rc;
361 }
362
363 return count;
364 }
365
366 static int cifs_stats_proc_show(struct seq_file *m, void *v)
367 {
368 int i;
369 struct list_head *tmp1, *tmp2, *tmp3;
370 struct TCP_Server_Info *server;
371 struct cifs_ses *ses;
372 struct cifs_tcon *tcon;
373
374 seq_printf(m,
375 "Resources in use\nCIFS Session: %d\n",
376 sesInfoAllocCount.counter);
377 seq_printf(m, "Share (unique mount targets): %d\n",
378 tconInfoAllocCount.counter);
379 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
380 bufAllocCount.counter,
381 cifs_min_rcv + tcpSesAllocCount.counter);
382 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
383 smBufAllocCount.counter, cifs_min_small);
384 #ifdef CONFIG_CIFS_STATS2
385 seq_printf(m, "Total Large %d Small %d Allocations\n",
386 atomic_read(&totBufAllocCount),
387 atomic_read(&totSmBufAllocCount));
388 #endif /* CONFIG_CIFS_STATS2 */
389
390 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
391 seq_printf(m,
392 "\n%d session %d share reconnects\n",
393 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
394
395 seq_printf(m,
396 "Total vfs operations: %d maximum at one time: %d\n",
397 GlobalCurrentXid, GlobalMaxActiveXid);
398
399 i = 0;
400 spin_lock(&cifs_tcp_ses_lock);
401 list_for_each(tmp1, &cifs_tcp_ses_list) {
402 server = list_entry(tmp1, struct TCP_Server_Info,
403 tcp_ses_list);
404 list_for_each(tmp2, &server->smb_ses_list) {
405 ses = list_entry(tmp2, struct cifs_ses,
406 smb_ses_list);
407 list_for_each(tmp3, &ses->tcon_list) {
408 tcon = list_entry(tmp3,
409 struct cifs_tcon,
410 tcon_list);
411 i++;
412 seq_printf(m, "\n%d) %s", i, tcon->treeName);
413 if (tcon->need_reconnect)
414 seq_puts(m, "\tDISCONNECTED ");
415 seq_printf(m, "\nSMBs: %d",
416 atomic_read(&tcon->num_smbs_sent));
417 if (server->ops->print_stats)
418 server->ops->print_stats(m, tcon);
419 }
420 }
421 }
422 spin_unlock(&cifs_tcp_ses_lock);
423
424 seq_putc(m, '\n');
425 return 0;
426 }
427
428 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
429 {
430 return single_open(file, cifs_stats_proc_show, NULL);
431 }
432
433 static const struct file_operations cifs_stats_proc_fops = {
434 .open = cifs_stats_proc_open,
435 .read = seq_read,
436 .llseek = seq_lseek,
437 .release = single_release,
438 .write = cifs_stats_proc_write,
439 };
440 #endif /* STATS */
441
442 #ifdef CONFIG_CIFS_SMB_DIRECT
443 #define PROC_FILE_DEFINE(name) \
444 static ssize_t name##_write(struct file *file, const char __user *buffer, \
445 size_t count, loff_t *ppos) \
446 { \
447 int rc; \
448 rc = kstrtoint_from_user(buffer, count, 10, & name); \
449 if (rc) \
450 return rc; \
451 return count; \
452 } \
453 static int name##_proc_show(struct seq_file *m, void *v) \
454 { \
455 seq_printf(m, "%d\n", name ); \
456 return 0; \
457 } \
458 static int name##_open(struct inode *inode, struct file *file) \
459 { \
460 return single_open(file, name##_proc_show, NULL); \
461 } \
462 \
463 static const struct file_operations cifs_##name##_proc_fops = { \
464 .open = name##_open, \
465 .read = seq_read, \
466 .llseek = seq_lseek, \
467 .release = single_release, \
468 .write = name##_write, \
469 }
470
471 PROC_FILE_DEFINE(rdma_readwrite_threshold);
472 PROC_FILE_DEFINE(smbd_max_frmr_depth);
473 PROC_FILE_DEFINE(smbd_keep_alive_interval);
474 PROC_FILE_DEFINE(smbd_max_receive_size);
475 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
476 PROC_FILE_DEFINE(smbd_max_send_size);
477 PROC_FILE_DEFINE(smbd_send_credit_target);
478 PROC_FILE_DEFINE(smbd_receive_credit_max);
479 #endif
480
481 static struct proc_dir_entry *proc_fs_cifs;
482 static const struct file_operations cifsFYI_proc_fops;
483 static const struct file_operations cifs_lookup_cache_proc_fops;
484 static const struct file_operations traceSMB_proc_fops;
485 static const struct file_operations cifs_security_flags_proc_fops;
486 static const struct file_operations cifs_linux_ext_proc_fops;
487
488 void
489 cifs_proc_init(void)
490 {
491 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
492 if (proc_fs_cifs == NULL)
493 return;
494
495 proc_create_single("DebugData", 0, proc_fs_cifs,
496 cifs_debug_data_proc_show);
497
498 #ifdef CONFIG_CIFS_STATS
499 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
500 #endif /* STATS */
501 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
502 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
503 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
504 &cifs_linux_ext_proc_fops);
505 proc_create("SecurityFlags", 0644, proc_fs_cifs,
506 &cifs_security_flags_proc_fops);
507 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
508 &cifs_lookup_cache_proc_fops);
509 #ifdef CONFIG_CIFS_SMB_DIRECT
510 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
511 &cifs_rdma_readwrite_threshold_proc_fops);
512 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
513 &cifs_smbd_max_frmr_depth_proc_fops);
514 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
515 &cifs_smbd_keep_alive_interval_proc_fops);
516 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
517 &cifs_smbd_max_receive_size_proc_fops);
518 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
519 &cifs_smbd_max_fragmented_recv_size_proc_fops);
520 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
521 &cifs_smbd_max_send_size_proc_fops);
522 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
523 &cifs_smbd_send_credit_target_proc_fops);
524 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
525 &cifs_smbd_receive_credit_max_proc_fops);
526 #endif
527 }
528
529 void
530 cifs_proc_clean(void)
531 {
532 if (proc_fs_cifs == NULL)
533 return;
534
535 remove_proc_entry("DebugData", proc_fs_cifs);
536 remove_proc_entry("cifsFYI", proc_fs_cifs);
537 remove_proc_entry("traceSMB", proc_fs_cifs);
538 #ifdef CONFIG_CIFS_STATS
539 remove_proc_entry("Stats", proc_fs_cifs);
540 #endif
541 remove_proc_entry("SecurityFlags", proc_fs_cifs);
542 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
543 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
544 #ifdef CONFIG_CIFS_SMB_DIRECT
545 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
546 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
547 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
548 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
549 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
550 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
551 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
552 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
553 #endif
554 remove_proc_entry("fs/cifs", NULL);
555 }
556
557 static int cifsFYI_proc_show(struct seq_file *m, void *v)
558 {
559 seq_printf(m, "%d\n", cifsFYI);
560 return 0;
561 }
562
563 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
564 {
565 return single_open(file, cifsFYI_proc_show, NULL);
566 }
567
568 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
569 size_t count, loff_t *ppos)
570 {
571 char c[2] = { '\0' };
572 bool bv;
573 int rc;
574
575 rc = get_user(c[0], buffer);
576 if (rc)
577 return rc;
578 if (strtobool(c, &bv) == 0)
579 cifsFYI = bv;
580 else if ((c[0] > '1') && (c[0] <= '9'))
581 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
582 else
583 return -EINVAL;
584
585 return count;
586 }
587
588 static const struct file_operations cifsFYI_proc_fops = {
589 .open = cifsFYI_proc_open,
590 .read = seq_read,
591 .llseek = seq_lseek,
592 .release = single_release,
593 .write = cifsFYI_proc_write,
594 };
595
596 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
597 {
598 seq_printf(m, "%d\n", linuxExtEnabled);
599 return 0;
600 }
601
602 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
603 {
604 return single_open(file, cifs_linux_ext_proc_show, NULL);
605 }
606
607 static ssize_t cifs_linux_ext_proc_write(struct file *file,
608 const char __user *buffer, size_t count, loff_t *ppos)
609 {
610 int rc;
611
612 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
613 if (rc)
614 return rc;
615
616 return count;
617 }
618
619 static const struct file_operations cifs_linux_ext_proc_fops = {
620 .open = cifs_linux_ext_proc_open,
621 .read = seq_read,
622 .llseek = seq_lseek,
623 .release = single_release,
624 .write = cifs_linux_ext_proc_write,
625 };
626
627 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
628 {
629 seq_printf(m, "%d\n", lookupCacheEnabled);
630 return 0;
631 }
632
633 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
634 {
635 return single_open(file, cifs_lookup_cache_proc_show, NULL);
636 }
637
638 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
639 const char __user *buffer, size_t count, loff_t *ppos)
640 {
641 int rc;
642
643 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
644 if (rc)
645 return rc;
646
647 return count;
648 }
649
650 static const struct file_operations cifs_lookup_cache_proc_fops = {
651 .open = cifs_lookup_cache_proc_open,
652 .read = seq_read,
653 .llseek = seq_lseek,
654 .release = single_release,
655 .write = cifs_lookup_cache_proc_write,
656 };
657
658 static int traceSMB_proc_show(struct seq_file *m, void *v)
659 {
660 seq_printf(m, "%d\n", traceSMB);
661 return 0;
662 }
663
664 static int traceSMB_proc_open(struct inode *inode, struct file *file)
665 {
666 return single_open(file, traceSMB_proc_show, NULL);
667 }
668
669 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
670 size_t count, loff_t *ppos)
671 {
672 int rc;
673
674 rc = kstrtobool_from_user(buffer, count, &traceSMB);
675 if (rc)
676 return rc;
677
678 return count;
679 }
680
681 static const struct file_operations traceSMB_proc_fops = {
682 .open = traceSMB_proc_open,
683 .read = seq_read,
684 .llseek = seq_lseek,
685 .release = single_release,
686 .write = traceSMB_proc_write,
687 };
688
689 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
690 {
691 seq_printf(m, "0x%x\n", global_secflags);
692 return 0;
693 }
694
695 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
696 {
697 return single_open(file, cifs_security_flags_proc_show, NULL);
698 }
699
700 /*
701 * Ensure that if someone sets a MUST flag, that we disable all other MAY
702 * flags except for the ones corresponding to the given MUST flag. If there are
703 * multiple MUST flags, then try to prefer more secure ones.
704 */
705 static void
706 cifs_security_flags_handle_must_flags(unsigned int *flags)
707 {
708 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
709
710 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
711 *flags = CIFSSEC_MUST_KRB5;
712 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
713 *flags = CIFSSEC_MUST_NTLMSSP;
714 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
715 *flags = CIFSSEC_MUST_NTLMV2;
716 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
717 *flags = CIFSSEC_MUST_NTLM;
718 else if (CIFSSEC_MUST_LANMAN &&
719 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
720 *flags = CIFSSEC_MUST_LANMAN;
721 else if (CIFSSEC_MUST_PLNTXT &&
722 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
723 *flags = CIFSSEC_MUST_PLNTXT;
724
725 *flags |= signflags;
726 }
727
728 static ssize_t cifs_security_flags_proc_write(struct file *file,
729 const char __user *buffer, size_t count, loff_t *ppos)
730 {
731 int rc;
732 unsigned int flags;
733 char flags_string[12];
734 bool bv;
735
736 if ((count < 1) || (count > 11))
737 return -EINVAL;
738
739 memset(flags_string, 0, 12);
740
741 if (copy_from_user(flags_string, buffer, count))
742 return -EFAULT;
743
744 if (count < 3) {
745 /* single char or single char followed by null */
746 if (strtobool(flags_string, &bv) == 0) {
747 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
748 return count;
749 } else if (!isdigit(flags_string[0])) {
750 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
751 flags_string);
752 return -EINVAL;
753 }
754 }
755
756 /* else we have a number */
757 rc = kstrtouint(flags_string, 0, &flags);
758 if (rc) {
759 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
760 flags_string);
761 return rc;
762 }
763
764 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
765
766 if (flags == 0) {
767 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
768 return -EINVAL;
769 }
770
771 if (flags & ~CIFSSEC_MASK) {
772 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
773 flags & ~CIFSSEC_MASK);
774 return -EINVAL;
775 }
776
777 cifs_security_flags_handle_must_flags(&flags);
778
779 /* flags look ok - update the global security flags for cifs module */
780 global_secflags = flags;
781 if (global_secflags & CIFSSEC_MUST_SIGN) {
782 /* requiring signing implies signing is allowed */
783 global_secflags |= CIFSSEC_MAY_SIGN;
784 cifs_dbg(FYI, "packet signing now required\n");
785 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
786 cifs_dbg(FYI, "packet signing disabled\n");
787 }
788 /* BB should we turn on MAY flags for other MUST options? */
789 return count;
790 }
791
792 static const struct file_operations cifs_security_flags_proc_fops = {
793 .open = cifs_security_flags_proc_open,
794 .read = seq_read,
795 .llseek = seq_lseek,
796 .release = single_release,
797 .write = cifs_security_flags_proc_write,
798 };
799 #else
800 inline void cifs_proc_init(void)
801 {
802 }
803
804 inline void cifs_proc_clean(void)
805 {
806 }
807 #endif /* PROC_FS */