blob: ba178b09de0b48f1ce0e2285899f66de91cd2741 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs_debug.c
3 *
Steve Frenchb8643e12005-04-28 22:41:07 -07004 * Copyright (C) International Business Machines Corp., 2000,2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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
Steve French221601c2007-06-05 20:35:06 +000010 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * (at your option) any later version.
Steve French221601c2007-06-05 20:35:06 +000012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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
Steve French221601c2007-06-05 20:35:06 +000019 * along with this program; if not, write to the Free Software
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * 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>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080027#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "cifspdu.h"
29#include "cifsglob.h"
30#include "cifsproto.h"
31#include "cifs_debug.h"
Steve French6c91d362005-04-28 22:41:06 -070032#include "cifsfs.h"
Long Lid8ec9132017-11-07 01:54:58 -070033#ifdef CONFIG_CIFS_SMB_DIRECT
34#include "smbdirect.h"
35#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37void
38cifs_dump_mem(char *label, void *data, int length)
39{
Andy Shevchenko0b456f02014-08-27 16:49:44 +030040 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
Andy Shevchenko55d83e02014-08-27 16:49:43 +030041 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
42 data, length, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Ronnie Sahlberg14547f72018-04-22 14:45:53 -060045void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000046{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040047#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040048 struct smb_hdr *smb = (struct smb_hdr *)buf;
49
Joe Perchesf96637b2013-05-04 22:12:25 -050050 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);
Ronnie Sahlberg14547f72018-04-22 14:45:53 -060053 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
Steve French71992e622018-05-06 15:58:51 -050054 server->ops->calc_smb_size(smb, server));
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040055#endif /* CONFIG_CIFS_DEBUG2 */
Steve French39798772006-05-31 22:40:51 +000056}
57
Steve Frenchffdd6e42007-06-24 21:15:44 +000058void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000059{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040060#ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +000061 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000062 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000063
Steve French221601c2007-06-05 20:35:06 +000064 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000065 return;
66
Joe Perchesf96637b2013-05-04 22:12:25 -050067 cifs_dbg(VFS, "Dump pending requests:\n");
Steve French39798772006-05-31 22:40:51 +000068 spin_lock(&GlobalMid_Lock);
69 list_for_each(tmp, &server->pending_mid_q) {
70 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesf96637b2013-05-04 22:12:25 -050071 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);
Steve French39798772006-05-31 22:40:51 +000077#ifdef CONFIG_CIFS_STATS2
Joe Perchesf96637b2013-05-04 22:12:25 -050078 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);
Steve French39798772006-05-31 22:40:51 +000083#endif /* STATS2 */
Joe Perchesf96637b2013-05-04 22:12:25 -050084 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
85 mid_entry->multiRsp, mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +000086 if (mid_entry->resp_buf) {
Steve French71992e622018-05-06 15:58:51 -050087 cifs_dump_detail(mid_entry->resp_buf, server);
Steve Frenchad8b15f2008-08-08 21:10:16 +000088 cifs_dump_mem("existing buf: ",
89 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +000090 }
91 }
92 spin_unlock(&GlobalMid_Lock);
Steve French39798772006-05-31 22:40:51 +000093#endif /* CONFIG_CIFS_DEBUG2 */
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040094}
Steve French39798772006-05-31 22:40:51 +000095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#ifdef CONFIG_PROC_FS
Aurelien Aptel02cf5902018-01-24 13:46:12 +010097static 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);
Steve Frenchede2e522018-01-31 14:34:37 -0600115 if (tcon->seal)
116 seq_printf(m, " Encrypted");
Steve French5c5a41b2018-05-30 17:11:55 -0500117 if (tcon->nocase)
118 seq_printf(m, " nocase");
Steve Frenchede2e522018-01-31 14:34:37 -0600119 if (tcon->unix_ext)
120 seq_printf(m, " POSIX Extensions");
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100121 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
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200129static void
130cifs_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
Steve French35a90802018-10-19 21:21:37 -0500135 seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200136 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
Steve Frenchdfe33f92018-10-30 19:50:31 -0500148static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
149{
150 struct list_head *stmp, *tmp, *tmp1, *tmp2;
151 struct TCP_Server_Info *server;
152 struct cifs_ses *ses;
153 struct cifs_tcon *tcon;
154 struct cifsFileInfo *cfile;
155
156 seq_puts(m, "# Version:1\n");
157 seq_puts(m, "# Format:\n");
158 seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
159#ifdef CONFIG_CIFS_DEBUG2
160 seq_printf(m, " <filename> <mid>\n");
161#else
162 seq_printf(m, " <filename>\n");
163#endif /* CIFS_DEBUG2 */
164 spin_lock(&cifs_tcp_ses_lock);
165 list_for_each(stmp, &cifs_tcp_ses_list) {
166 server = list_entry(stmp, struct TCP_Server_Info,
167 tcp_ses_list);
168 list_for_each(tmp, &server->smb_ses_list) {
169 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
170 list_for_each(tmp1, &ses->tcon_list) {
171 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
172 spin_lock(&tcon->open_file_lock);
173 list_for_each(tmp2, &tcon->openFileList) {
174 cfile = list_entry(tmp2, struct cifsFileInfo,
175 tlist);
176 seq_printf(m,
177 "0x%x 0x%llx 0x%x %d %d %d %s",
178 tcon->tid,
179 cfile->fid.persistent_fid,
180 cfile->f_flags,
181 cfile->count,
182 cfile->pid,
183 from_kuid(&init_user_ns, cfile->uid),
184 cfile->dentry->d_name.name);
185#ifdef CONFIG_CIFS_DEBUG2
186 seq_printf(m, " 0x%llx\n", cfile->fid.mid);
187#else
188 seq_printf(m, "\n");
189#endif /* CIFS_DEBUG2 */
190 }
191 spin_unlock(&tcon->open_file_lock);
192 }
193 }
194 }
195 spin_unlock(&cifs_tcp_ses_lock);
196 seq_putc(m, '\n');
197 return 0;
198}
199
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000200static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500202 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000203 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500204 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000205 struct cifs_ses *ses;
206 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500207 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000209 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 "Display Internal CIFS Data Structures for Debugging\n"
211 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000212 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500213 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530214#ifdef CONFIG_CIFS_DFS_UPCALL
Steve French950132a2018-06-28 18:46:40 -0500215 seq_printf(m, " DFS");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530216#endif
217#ifdef CONFIG_CIFS_FSCACHE
Steve French950132a2018-06-28 18:46:40 -0500218 seq_printf(m, ",FSCACHE");
219#endif
220#ifdef CONFIG_CIFS_SMB_DIRECT
221 seq_printf(m, ",SMB_DIRECT");
222#endif
223#ifdef CONFIG_CIFS_STATS2
224 seq_printf(m, ",STATS2");
Steve Frenchd2586502018-08-01 22:34:04 -0500225#else
Steve French950132a2018-06-28 18:46:40 -0500226 seq_printf(m, ",STATS");
227#endif
228#ifdef CONFIG_CIFS_DEBUG2
229 seq_printf(m, ",DEBUG2");
230#elif defined(CONFIG_CIFS_DEBUG)
231 seq_printf(m, ",DEBUG");
232#endif
233#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
234 seq_printf(m, ",ALLOW_INSECURE_LEGACY");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530235#endif
236#ifdef CONFIG_CIFS_WEAK_PW_HASH
Steve French950132a2018-06-28 18:46:40 -0500237 seq_printf(m, ",WEAK_PW_HASH");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530238#endif
239#ifdef CONFIG_CIFS_POSIX
Steve French950132a2018-06-28 18:46:40 -0500240 seq_printf(m, ",CIFS_POSIX");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530241#endif
242#ifdef CONFIG_CIFS_UPCALL
Steve French950132a2018-06-28 18:46:40 -0500243 seq_printf(m, ",UPCALL(SPNEGO)");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530244#endif
245#ifdef CONFIG_CIFS_XATTR
Steve French950132a2018-06-28 18:46:40 -0500246 seq_printf(m, ",XATTR");
Jeff Laytonca40b712011-01-07 11:30:29 -0500247#endif
248#ifdef CONFIG_CIFS_ACL
Steve French950132a2018-06-28 18:46:40 -0500249 seq_printf(m, ",ACL");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530250#endif
251 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000252 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
253 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530256 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500257 list_for_each(tmp1, &cifs_tcp_ses_list) {
258 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500259 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700260
261#ifdef CONFIG_CIFS_SMB_DIRECT
262 if (!server->rdma)
263 goto skip_rdma;
264
265 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
266 "transport status: %x",
267 server->smbd_conn->protocol,
268 server->smbd_conn->transport_status);
269 seq_printf(m, "\nConn receive_credit_max: %x "
270 "send_credit_target: %x max_send_size: %x",
271 server->smbd_conn->receive_credit_max,
272 server->smbd_conn->send_credit_target,
273 server->smbd_conn->max_send_size);
274 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
275 "max_fragmented_send_size: %x max_receive_size:%x",
276 server->smbd_conn->max_fragmented_recv_size,
277 server->smbd_conn->max_fragmented_send_size,
278 server->smbd_conn->max_receive_size);
279 seq_printf(m, "\nConn keep_alive_interval: %x "
280 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
281 server->smbd_conn->keep_alive_interval,
282 server->smbd_conn->max_readwrite_size,
283 server->smbd_conn->rdma_readwrite_threshold);
284 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
285 "count_put_receive_buffer: %x count_send_empty: %x",
286 server->smbd_conn->count_get_receive_buffer,
287 server->smbd_conn->count_put_receive_buffer,
288 server->smbd_conn->count_send_empty);
289 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
290 "count_enqueue_reassembly_queue: %x "
291 "count_dequeue_reassembly_queue: %x "
292 "fragment_reassembly_remaining: %x "
293 "reassembly_data_length: %x "
294 "reassembly_queue_length: %x",
295 server->smbd_conn->count_reassembly_queue,
296 server->smbd_conn->count_enqueue_reassembly_queue,
297 server->smbd_conn->count_dequeue_reassembly_queue,
298 server->smbd_conn->fragment_reassembly_remaining,
299 server->smbd_conn->reassembly_data_length,
300 server->smbd_conn->reassembly_queue_length);
301 seq_printf(m, "\nCurrent Credits send_credits: %x "
302 "receive_credits: %x receive_credit_target: %x",
303 atomic_read(&server->smbd_conn->send_credits),
304 atomic_read(&server->smbd_conn->receive_credits),
305 server->smbd_conn->receive_credit_target);
306 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
307 " %x smbd_send_pending: %x smbd_recv_pending: %x",
308 atomic_read(&server->smbd_conn->send_pending),
309 atomic_read(&server->smbd_conn->send_payload_pending),
310 server->smbd_conn->smbd_send_pending,
311 server->smbd_conn->smbd_recv_pending);
312 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
313 "count_empty_packet_queue: %x",
314 server->smbd_conn->count_receive_queue,
315 server->smbd_conn->count_empty_packet_queue);
316 seq_printf(m, "\nMR responder_resources: %x "
317 "max_frmr_depth: %x mr_type: %x",
318 server->smbd_conn->responder_resources,
319 server->smbd_conn->max_frmr_depth,
320 server->smbd_conn->mr_type);
321 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
322 atomic_read(&server->smbd_conn->mr_ready_count),
323 atomic_read(&server->smbd_conn->mr_used_count));
324skip_rdma:
325#endif
Steve Frenchede2e522018-01-31 14:34:37 -0600326 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
327 server->credits, server->dialect);
328 if (server->sign)
329 seq_printf(m, " signed");
Steve Frenchfcef0db2018-05-19 20:45:27 -0500330 if (server->posix_ext_supported)
331 seq_printf(m, " posix");
Steve French0fdfef92018-06-28 19:30:23 -0500332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500334 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000335 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500336 smb_ses_list);
337 if ((ses->serverDomain == NULL) ||
338 (ses->serverOS == NULL) ||
339 (ses->serverNOS == NULL)) {
Steve French9e1a37d2018-09-19 02:38:17 -0500340 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
Steve French1fa089e2017-09-20 16:46:49 -0500341 i, ses->serverName, ses->ses_count,
342 ses->capabilities, ses->status);
343 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
344 seq_printf(m, "Guest\t");
345 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
346 seq_printf(m, "Anonymous\t");
Jeff Layton14fbf502008-11-14 13:53:46 -0500347 } else {
348 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500349 "\n%d) Name: %s Domain: %s Uses: %d OS:"
350 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French9e1a37d2018-09-19 02:38:17 -0500351 " session status: %d ",
Steve Frenchb8643e12005-04-28 22:41:07 -0700352 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500353 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000354 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500355 }
Long Li8339dd32017-11-07 01:54:55 -0700356 if (server->rdma)
357 seq_printf(m, "RDMA\n\t");
Steve French9e1a37d2018-09-19 02:38:17 -0500358 seq_printf(m, "TCP status: %d Instance: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500359 "Server: %d SecMode: 0x%x Req On Wire: %d",
Steve French9e1a37d2018-09-19 02:38:17 -0500360 server->tcpStatus,
361 server->reconnect_instance,
362 server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300363 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700364
365#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000366 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000367 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500368 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700369#endif
370
Jeff Laytonf1987b42008-11-15 11:12:47 -0500371 seq_puts(m, "\n\tShares:");
372 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100373
374 seq_printf(m, "\n\t%d) IPC: ", j);
375 if (ses->tcon_ipc)
376 cifs_debug_tcon(m, ses->tcon_ipc);
377 else
378 seq_puts(m, "none\n");
379
Jeff Laytonf1987b42008-11-15 11:12:47 -0500380 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000381 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500382 tcon_list);
383 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100384 seq_printf(m, "\n\t%d) ", j);
385 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500386 }
387
388 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500391 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500392 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500394 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400395 " %d cbdata: %p mid %llu\n",
396 mid_entry->mid_state,
397 le16_to_cpu(mid_entry->command),
398 mid_entry->pid,
399 mid_entry->callback_data,
400 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
Steve French221601c2007-06-05 20:35:06 +0000402 spin_unlock(&GlobalMid_Lock);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200403
404 spin_lock(&ses->iface_lock);
Steve French115d5d22018-06-14 21:59:31 -0500405 if (ses->iface_count)
406 seq_printf(m, "\n\tServer interfaces: %zu\n",
407 ses->iface_count);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200408 for (j = 0; j < ses->iface_count; j++) {
Steve French35a90802018-10-19 21:21:37 -0500409 seq_printf(m, "\t%d)", j);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200410 cifs_dump_iface(m, &ses->iface_list[j]);
411 }
412 spin_unlock(&ses->iface_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530415 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000416 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000419 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000422static ssize_t cifs_stats_proc_write(struct file *file,
423 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700424{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300425 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000426 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500427 struct list_head *tmp1, *tmp2, *tmp3;
428 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000429 struct cifs_ses *ses;
430 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700431
Kees Cook14042972016-03-17 14:22:54 -0700432 rc = kstrtobool_from_user(buffer, count, &bv);
433 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800434#ifdef CONFIG_CIFS_STATS2
Steve French468d6772018-08-04 05:24:34 -0500435 int i;
436
Steve French4498eed52005-12-03 13:58:57 -0800437 atomic_set(&totBufAllocCount, 0);
438 atomic_set(&totSmBufAllocCount, 0);
439#endif /* CONFIG_CIFS_STATS2 */
Steve French2c8876352018-09-15 23:04:41 -0500440 atomic_set(&tcpSesReconnectCount, 0);
441 atomic_set(&tconInfoReconnectCount, 0);
442
Steve Frenchc281bc02018-08-01 00:56:12 -0500443 spin_lock(&GlobalMid_Lock);
444 GlobalMaxActiveXid = 0;
445 GlobalCurrentXid = 0;
446 spin_unlock(&GlobalMid_Lock);
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530447 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500448 list_for_each(tmp1, &cifs_tcp_ses_list) {
449 server = list_entry(tmp1, struct TCP_Server_Info,
450 tcp_ses_list);
Steve French468d6772018-08-04 05:24:34 -0500451#ifdef CONFIG_CIFS_STATS2
452 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++)
453 atomic_set(&server->smb2slowcmd[i], 0);
454#endif /* CONFIG_CIFS_STATS2 */
Steve Frenchc2b33822008-11-17 03:57:13 +0000455 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000456 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000457 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500458 list_for_each(tmp3, &ses->tcon_list) {
459 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000460 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500461 tcon_list);
462 atomic_set(&tcon->num_smbs_sent, 0);
Steve Frenchc281bc02018-08-01 00:56:12 -0500463 spin_lock(&tcon->stat_lock);
464 tcon->bytes_read = 0;
465 tcon->bytes_written = 0;
466 spin_unlock(&tcon->stat_lock);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400467 if (server->ops->clear_stats)
468 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500469 }
470 }
Steve French1047abc2005-10-11 19:58:06 -0700471 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530472 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700473 } else {
474 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700475 }
476
Steve French221601c2007-06-05 20:35:06 +0000477 return count;
Steve French1047abc2005-10-11 19:58:06 -0700478}
479
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000480static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000482 int i;
Steve French468d6772018-08-04 05:24:34 -0500483#ifdef CONFIG_CIFS_STATS2
484 int j;
485#endif /* STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500486 struct list_head *tmp1, *tmp2, *tmp3;
487 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000488 struct cifs_ses *ses;
489 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Steve French468d6772018-08-04 05:24:34 -0500491 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000493 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000495 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700496 bufAllocCount.counter,
497 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000498 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000499 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800500#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000501 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800502 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000503 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800504#endif /* CONFIG_CIFS_STATS2 */
505
Jeff Layton80975312011-01-11 07:24:02 -0500506 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000507 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000509 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000511 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000513 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530516 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500517 list_for_each(tmp1, &cifs_tcp_ses_list) {
518 server = list_entry(tmp1, struct TCP_Server_Info,
519 tcp_ses_list);
Steve French468d6772018-08-04 05:24:34 -0500520#ifdef CONFIG_CIFS_STATS2
521 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
522 if (atomic_read(&server->smb2slowcmd[j]))
523 seq_printf(m, "%d slow responses from %s for command %d\n",
524 atomic_read(&server->smb2slowcmd[j]),
525 server->hostname, j);
526#endif /* STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500527 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000528 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500529 smb_ses_list);
530 list_for_each(tmp3, &ses->tcon_list) {
531 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000532 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500533 tcon_list);
534 i++;
535 seq_printf(m, "\n%d) %s", i, tcon->treeName);
536 if (tcon->need_reconnect)
537 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400538 seq_printf(m, "\nSMBs: %d",
539 atomic_read(&tcon->num_smbs_sent));
540 if (server->ops->print_stats)
541 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500542 }
543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530545 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000547 seq_putc(m, '\n');
548 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000550
551static int cifs_stats_proc_open(struct inode *inode, struct file *file)
552{
553 return single_open(file, cifs_stats_proc_show, NULL);
554}
555
556static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000557 .open = cifs_stats_proc_open,
558 .read = seq_read,
559 .llseek = seq_lseek,
560 .release = single_release,
561 .write = cifs_stats_proc_write,
562};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Long Lid8ec9132017-11-07 01:54:58 -0700564#ifdef CONFIG_CIFS_SMB_DIRECT
565#define PROC_FILE_DEFINE(name) \
566static ssize_t name##_write(struct file *file, const char __user *buffer, \
567 size_t count, loff_t *ppos) \
568{ \
569 int rc; \
570 rc = kstrtoint_from_user(buffer, count, 10, & name); \
571 if (rc) \
572 return rc; \
573 return count; \
574} \
575static int name##_proc_show(struct seq_file *m, void *v) \
576{ \
577 seq_printf(m, "%d\n", name ); \
578 return 0; \
579} \
580static int name##_open(struct inode *inode, struct file *file) \
581{ \
582 return single_open(file, name##_proc_show, NULL); \
583} \
584\
585static const struct file_operations cifs_##name##_proc_fops = { \
586 .open = name##_open, \
587 .read = seq_read, \
588 .llseek = seq_lseek, \
589 .release = single_release, \
590 .write = name##_write, \
591}
592
Long Lid8ec9132017-11-07 01:54:58 -0700593PROC_FILE_DEFINE(rdma_readwrite_threshold);
594PROC_FILE_DEFINE(smbd_max_frmr_depth);
595PROC_FILE_DEFINE(smbd_keep_alive_interval);
596PROC_FILE_DEFINE(smbd_max_receive_size);
597PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
598PROC_FILE_DEFINE(smbd_max_send_size);
599PROC_FILE_DEFINE(smbd_send_credit_target);
600PROC_FILE_DEFINE(smbd_receive_credit_max);
601#endif
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000604static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000605static const struct file_operations cifs_lookup_cache_proc_fops;
606static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000607static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000608static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610void
611cifs_proc_init(void)
612{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700613 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 if (proc_fs_cifs == NULL)
615 return;
616
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200617 proc_create_single("DebugData", 0, proc_fs_cifs,
618 cifs_debug_data_proc_show);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Steve Frenchdfe33f92018-10-30 19:50:31 -0500620 proc_create_single("open_files", 0400, proc_fs_cifs,
621 cifs_debug_files_proc_show);
622
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000623 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000624 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
625 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
626 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000627 &cifs_linux_ext_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000628 proc_create("SecurityFlags", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000629 &cifs_security_flags_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000630 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000631 &cifs_lookup_cache_proc_fops);
Long Lid8ec9132017-11-07 01:54:58 -0700632#ifdef CONFIG_CIFS_SMB_DIRECT
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000633 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700634 &cifs_rdma_readwrite_threshold_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000635 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700636 &cifs_smbd_max_frmr_depth_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000637 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700638 &cifs_smbd_keep_alive_interval_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000639 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700640 &cifs_smbd_max_receive_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000641 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700642 &cifs_smbd_max_fragmented_recv_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000643 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700644 &cifs_smbd_max_send_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000645 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700646 &cifs_smbd_send_credit_target_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000647 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700648 &cifs_smbd_receive_credit_max_proc_fops);
649#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652void
653cifs_proc_clean(void)
654{
655 if (proc_fs_cifs == NULL)
656 return;
657
658 remove_proc_entry("DebugData", proc_fs_cifs);
Steve Frenchdfe33f92018-10-30 19:50:31 -0500659 remove_proc_entry("open_files", proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 remove_proc_entry("cifsFYI", proc_fs_cifs);
661 remove_proc_entry("traceSMB", proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 remove_proc_entry("Stats", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000663 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000664 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000665 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Long Lid8ec9132017-11-07 01:54:58 -0700666#ifdef CONFIG_CIFS_SMB_DIRECT
667 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
668 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
669 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
670 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
671 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
672 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
673 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
674 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
675#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700676 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000679static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000681 seq_printf(m, "%d\n", cifsFYI);
682 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000684
685static int cifsFYI_proc_open(struct inode *inode, struct file *file)
686{
687 return single_open(file, cifsFYI_proc_show, NULL);
688}
689
690static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
691 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692{
Kees Cook14042972016-03-17 14:22:54 -0700693 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300694 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 int rc;
696
Kees Cook14042972016-03-17 14:22:54 -0700697 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (rc)
699 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700700 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300701 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700702 else if ((c[0] > '1') && (c[0] <= '9'))
703 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Ronnie Sahlberg25ad1cb2018-05-24 09:53:39 +1000704 else
705 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 return count;
708}
709
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000710static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000711 .open = cifsFYI_proc_open,
712 .read = seq_read,
713 .llseek = seq_lseek,
714 .release = single_release,
715 .write = cifsFYI_proc_write,
716};
717
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000718static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000720 seq_printf(m, "%d\n", linuxExtEnabled);
721 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000723
724static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
725{
726 return single_open(file, cifs_linux_ext_proc_show, NULL);
727}
728
729static ssize_t cifs_linux_ext_proc_write(struct file *file,
730 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
Steve French221601c2007-06-05 20:35:06 +0000732 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Kees Cook14042972016-03-17 14:22:54 -0700734 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000735 if (rc)
736 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300737
Steve French221601c2007-06-05 20:35:06 +0000738 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000741static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000742 .open = cifs_linux_ext_proc_open,
743 .read = seq_read,
744 .llseek = seq_lseek,
745 .release = single_release,
746 .write = cifs_linux_ext_proc_write,
747};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000749static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000751 seq_printf(m, "%d\n", lookupCacheEnabled);
752 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000754
755static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
756{
757 return single_open(file, cifs_lookup_cache_proc_show, NULL);
758}
759
760static ssize_t cifs_lookup_cache_proc_write(struct file *file,
761 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 int rc;
764
Kees Cook14042972016-03-17 14:22:54 -0700765 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 if (rc)
767 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 return count;
770}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000771
772static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000773 .open = cifs_lookup_cache_proc_open,
774 .read = seq_read,
775 .llseek = seq_lseek,
776 .release = single_release,
777 .write = cifs_lookup_cache_proc_write,
778};
779
780static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000782 seq_printf(m, "%d\n", traceSMB);
783 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000785
786static int traceSMB_proc_open(struct inode *inode, struct file *file)
787{
788 return single_open(file, traceSMB_proc_show, NULL);
789}
790
791static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
792 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 int rc;
795
Kees Cook14042972016-03-17 14:22:54 -0700796 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (rc)
798 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return count;
801}
802
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000803static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000804 .open = traceSMB_proc_open,
805 .read = seq_read,
806 .llseek = seq_lseek,
807 .release = single_release,
808 .write = traceSMB_proc_write,
809};
810
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000811static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
Jeff Layton04912d62010-04-24 07:57:45 -0400813 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000814 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000816
817static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
818{
819 return single_open(file, cifs_security_flags_proc_show, NULL);
820}
821
Jeff Layton52dfb442013-05-26 07:01:02 -0400822/*
823 * Ensure that if someone sets a MUST flag, that we disable all other MAY
824 * flags except for the ones corresponding to the given MUST flag. If there are
825 * multiple MUST flags, then try to prefer more secure ones.
826 */
827static void
828cifs_security_flags_handle_must_flags(unsigned int *flags)
829{
830 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
831
832 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
833 *flags = CIFSSEC_MUST_KRB5;
834 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
835 *flags = CIFSSEC_MUST_NTLMSSP;
836 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
837 *flags = CIFSSEC_MUST_NTLMV2;
838 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
839 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100840 else if (CIFSSEC_MUST_LANMAN &&
841 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400842 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100843 else if (CIFSSEC_MUST_PLNTXT &&
844 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400845 *flags = CIFSSEC_MUST_PLNTXT;
846
847 *flags |= signflags;
848}
849
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000850static ssize_t cifs_security_flags_proc_write(struct file *file,
851 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Jeff Layton7715dad2013-05-26 07:01:01 -0400853 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000854 unsigned int flags;
855 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300856 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000857
Steve French221601c2007-06-05 20:35:06 +0000858 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000859 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000861 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000862
Steve French221601c2007-06-05 20:35:06 +0000863 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000864 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000865
Steve French221601c2007-06-05 20:35:06 +0000866 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000867 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700868 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300869 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000870 return count;
Kees Cook14042972016-03-17 14:22:54 -0700871 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400872 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
873 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000874 return -EINVAL;
875 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Jeff Layton7715dad2013-05-26 07:01:01 -0400878 /* else we have a number */
879 rc = kstrtouint(flags_string, 0, &flags);
880 if (rc) {
881 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
882 flags_string);
883 return rc;
884 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000885
Joe Perchesf96637b2013-05-04 22:12:25 -0500886 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000887
Jeff Layton7715dad2013-05-26 07:01:01 -0400888 if (flags == 0) {
889 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000890 return -EINVAL;
891 }
892
Steve French221601c2007-06-05 20:35:06 +0000893 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400894 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500895 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000896 return -EINVAL;
897 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400898
Jeff Layton52dfb442013-05-26 07:01:02 -0400899 cifs_security_flags_handle_must_flags(&flags);
900
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000901 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400902 global_secflags = flags;
903 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000904 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400905 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500906 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400907 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500908 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000909 }
910 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 return count;
912}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000913
914static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000915 .open = cifs_security_flags_proc_open,
916 .read = seq_read,
917 .llseek = seq_lseek,
918 .release = single_release,
919 .write = cifs_security_flags_proc_write,
920};
Steve French90c81e02008-02-12 20:32:36 +0000921#else
Steve Frenche086fce2008-02-18 04:03:58 +0000922inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000923{
924}
925
Steve Frenche086fce2008-02-18 04:03:58 +0000926inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000927{
928}
929#endif /* PROC_FS */