blob: bfe99950581527bcc494acb6419436e6373aa923 [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 French5c5a41be2018-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
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
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000148static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500150 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000151 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500152 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000153 struct cifs_ses *ses;
154 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500155 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000157 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 "Display Internal CIFS Data Structures for Debugging\n"
159 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000160 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500161 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530162#ifdef CONFIG_CIFS_DFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500163 seq_printf(m, " dfs");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530164#endif
165#ifdef CONFIG_CIFS_FSCACHE
Jeff Laytonca40b712011-01-07 11:30:29 -0500166 seq_printf(m, " fscache");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530167#endif
168#ifdef CONFIG_CIFS_WEAK_PW_HASH
Jeff Laytonca40b712011-01-07 11:30:29 -0500169 seq_printf(m, " lanman");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530170#endif
171#ifdef CONFIG_CIFS_POSIX
Jeff Laytonca40b712011-01-07 11:30:29 -0500172 seq_printf(m, " posix");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530173#endif
174#ifdef CONFIG_CIFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500175 seq_printf(m, " spnego");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530176#endif
177#ifdef CONFIG_CIFS_XATTR
Jeff Laytonca40b712011-01-07 11:30:29 -0500178 seq_printf(m, " xattr");
179#endif
180#ifdef CONFIG_CIFS_ACL
181 seq_printf(m, " acl");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530182#endif
183 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000184 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
185 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530188 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500189 list_for_each(tmp1, &cifs_tcp_ses_list) {
190 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500191 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700192
193#ifdef CONFIG_CIFS_SMB_DIRECT
194 if (!server->rdma)
195 goto skip_rdma;
196
197 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
198 "transport status: %x",
199 server->smbd_conn->protocol,
200 server->smbd_conn->transport_status);
201 seq_printf(m, "\nConn receive_credit_max: %x "
202 "send_credit_target: %x max_send_size: %x",
203 server->smbd_conn->receive_credit_max,
204 server->smbd_conn->send_credit_target,
205 server->smbd_conn->max_send_size);
206 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
207 "max_fragmented_send_size: %x max_receive_size:%x",
208 server->smbd_conn->max_fragmented_recv_size,
209 server->smbd_conn->max_fragmented_send_size,
210 server->smbd_conn->max_receive_size);
211 seq_printf(m, "\nConn keep_alive_interval: %x "
212 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
213 server->smbd_conn->keep_alive_interval,
214 server->smbd_conn->max_readwrite_size,
215 server->smbd_conn->rdma_readwrite_threshold);
216 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
217 "count_put_receive_buffer: %x count_send_empty: %x",
218 server->smbd_conn->count_get_receive_buffer,
219 server->smbd_conn->count_put_receive_buffer,
220 server->smbd_conn->count_send_empty);
221 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
222 "count_enqueue_reassembly_queue: %x "
223 "count_dequeue_reassembly_queue: %x "
224 "fragment_reassembly_remaining: %x "
225 "reassembly_data_length: %x "
226 "reassembly_queue_length: %x",
227 server->smbd_conn->count_reassembly_queue,
228 server->smbd_conn->count_enqueue_reassembly_queue,
229 server->smbd_conn->count_dequeue_reassembly_queue,
230 server->smbd_conn->fragment_reassembly_remaining,
231 server->smbd_conn->reassembly_data_length,
232 server->smbd_conn->reassembly_queue_length);
233 seq_printf(m, "\nCurrent Credits send_credits: %x "
234 "receive_credits: %x receive_credit_target: %x",
235 atomic_read(&server->smbd_conn->send_credits),
236 atomic_read(&server->smbd_conn->receive_credits),
237 server->smbd_conn->receive_credit_target);
238 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
239 " %x smbd_send_pending: %x smbd_recv_pending: %x",
240 atomic_read(&server->smbd_conn->send_pending),
241 atomic_read(&server->smbd_conn->send_payload_pending),
242 server->smbd_conn->smbd_send_pending,
243 server->smbd_conn->smbd_recv_pending);
244 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
245 "count_empty_packet_queue: %x",
246 server->smbd_conn->count_receive_queue,
247 server->smbd_conn->count_empty_packet_queue);
248 seq_printf(m, "\nMR responder_resources: %x "
249 "max_frmr_depth: %x mr_type: %x",
250 server->smbd_conn->responder_resources,
251 server->smbd_conn->max_frmr_depth,
252 server->smbd_conn->mr_type);
253 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
254 atomic_read(&server->smbd_conn->mr_ready_count),
255 atomic_read(&server->smbd_conn->mr_used_count));
256skip_rdma:
257#endif
Steve Frenchede2e522018-01-31 14:34:37 -0600258 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
259 server->credits, server->dialect);
260 if (server->sign)
261 seq_printf(m, " signed");
Steve Frenchfcef0db2018-05-19 20:45:27 -0500262#ifdef CONFIG_CIFS_SMB311
263 if (server->posix_ext_supported)
264 seq_printf(m, " posix");
265#endif /* 3.1.1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500267 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000268 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500269 smb_ses_list);
270 if ((ses->serverDomain == NULL) ||
271 (ses->serverOS == NULL) ||
272 (ses->serverNOS == NULL)) {
Steve French1fa089e2017-09-20 16:46:49 -0500273 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
274 i, ses->serverName, ses->ses_count,
275 ses->capabilities, ses->status);
276 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
277 seq_printf(m, "Guest\t");
278 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
279 seq_printf(m, "Anonymous\t");
Jeff Layton14fbf502008-11-14 13:53:46 -0500280 } else {
281 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500282 "\n%d) Name: %s Domain: %s Uses: %d OS:"
283 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000284 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700285 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500286 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000287 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500288 }
Long Li8339dd32017-11-07 01:54:55 -0700289 if (server->rdma)
290 seq_printf(m, "RDMA\n\t");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000291 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500292 "Server: %d SecMode: 0x%x Req On Wire: %d",
293 server->tcpStatus, server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300294 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700295
296#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000297 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000298 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500299 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700300#endif
301
Jeff Laytonf1987b42008-11-15 11:12:47 -0500302 seq_puts(m, "\n\tShares:");
303 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100304
305 seq_printf(m, "\n\t%d) IPC: ", j);
306 if (ses->tcon_ipc)
307 cifs_debug_tcon(m, ses->tcon_ipc);
308 else
309 seq_puts(m, "none\n");
310
Jeff Laytonf1987b42008-11-15 11:12:47 -0500311 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000312 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500313 tcon_list);
314 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100315 seq_printf(m, "\n\t%d) ", j);
316 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500317 }
318
319 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500322 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500323 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500325 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400326 " %d cbdata: %p mid %llu\n",
327 mid_entry->mid_state,
328 le16_to_cpu(mid_entry->command),
329 mid_entry->pid,
330 mid_entry->callback_data,
331 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
Steve French221601c2007-06-05 20:35:06 +0000333 spin_unlock(&GlobalMid_Lock);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200334
335 spin_lock(&ses->iface_lock);
Steve French115d5d22018-06-14 21:59:31 -0500336 if (ses->iface_count)
337 seq_printf(m, "\n\tServer interfaces: %zu\n",
338 ses->iface_count);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200339 for (j = 0; j < ses->iface_count; j++) {
340 seq_printf(m, "\t%d)\n", j);
341 cifs_dump_iface(m, &ses->iface_list[j]);
342 }
343 spin_unlock(&ses->iface_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530346 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000347 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000350 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000353#ifdef CONFIG_CIFS_STATS
354static ssize_t cifs_stats_proc_write(struct file *file,
355 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700356{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300357 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000358 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500359 struct list_head *tmp1, *tmp2, *tmp3;
360 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000361 struct cifs_ses *ses;
362 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700363
Kees Cook14042972016-03-17 14:22:54 -0700364 rc = kstrtobool_from_user(buffer, count, &bv);
365 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800366#ifdef CONFIG_CIFS_STATS2
367 atomic_set(&totBufAllocCount, 0);
368 atomic_set(&totSmBufAllocCount, 0);
369#endif /* CONFIG_CIFS_STATS2 */
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530370 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500371 list_for_each(tmp1, &cifs_tcp_ses_list) {
372 server = list_entry(tmp1, struct TCP_Server_Info,
373 tcp_ses_list);
Steve Frenchc2b33822008-11-17 03:57:13 +0000374 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000375 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000376 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500377 list_for_each(tmp3, &ses->tcon_list) {
378 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000379 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500380 tcon_list);
381 atomic_set(&tcon->num_smbs_sent, 0);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400382 if (server->ops->clear_stats)
383 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500384 }
385 }
Steve French1047abc2005-10-11 19:58:06 -0700386 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530387 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700388 } else {
389 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700390 }
391
Steve French221601c2007-06-05 20:35:06 +0000392 return count;
Steve French1047abc2005-10-11 19:58:06 -0700393}
394
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000395static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000397 int i;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500398 struct list_head *tmp1, *tmp2, *tmp3;
399 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000400 struct cifs_ses *ses;
401 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000403 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 "Resources in use\nCIFS Session: %d\n",
405 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000406 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000408 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700409 bufAllocCount.counter,
410 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000411 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000412 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800413#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000414 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800415 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000416 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800417#endif /* CONFIG_CIFS_STATS2 */
418
Jeff Layton80975312011-01-11 07:24:02 -0500419 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000420 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000422 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000424 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000426 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530429 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500430 list_for_each(tmp1, &cifs_tcp_ses_list) {
431 server = list_entry(tmp1, struct TCP_Server_Info,
432 tcp_ses_list);
433 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000434 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500435 smb_ses_list);
436 list_for_each(tmp3, &ses->tcon_list) {
437 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000438 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500439 tcon_list);
440 i++;
441 seq_printf(m, "\n%d) %s", i, tcon->treeName);
442 if (tcon->need_reconnect)
443 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400444 seq_printf(m, "\nSMBs: %d",
445 atomic_read(&tcon->num_smbs_sent));
446 if (server->ops->print_stats)
447 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500448 }
449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530451 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000453 seq_putc(m, '\n');
454 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000456
457static int cifs_stats_proc_open(struct inode *inode, struct file *file)
458{
459 return single_open(file, cifs_stats_proc_show, NULL);
460}
461
462static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000463 .open = cifs_stats_proc_open,
464 .read = seq_read,
465 .llseek = seq_lseek,
466 .release = single_release,
467 .write = cifs_stats_proc_write,
468};
Steve French90c81e02008-02-12 20:32:36 +0000469#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Long Lid8ec9132017-11-07 01:54:58 -0700471#ifdef CONFIG_CIFS_SMB_DIRECT
472#define PROC_FILE_DEFINE(name) \
473static ssize_t name##_write(struct file *file, const char __user *buffer, \
474 size_t count, loff_t *ppos) \
475{ \
476 int rc; \
477 rc = kstrtoint_from_user(buffer, count, 10, & name); \
478 if (rc) \
479 return rc; \
480 return count; \
481} \
482static int name##_proc_show(struct seq_file *m, void *v) \
483{ \
484 seq_printf(m, "%d\n", name ); \
485 return 0; \
486} \
487static int name##_open(struct inode *inode, struct file *file) \
488{ \
489 return single_open(file, name##_proc_show, NULL); \
490} \
491\
492static const struct file_operations cifs_##name##_proc_fops = { \
493 .open = name##_open, \
494 .read = seq_read, \
495 .llseek = seq_lseek, \
496 .release = single_release, \
497 .write = name##_write, \
498}
499
Long Lid8ec9132017-11-07 01:54:58 -0700500PROC_FILE_DEFINE(rdma_readwrite_threshold);
501PROC_FILE_DEFINE(smbd_max_frmr_depth);
502PROC_FILE_DEFINE(smbd_keep_alive_interval);
503PROC_FILE_DEFINE(smbd_max_receive_size);
504PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
505PROC_FILE_DEFINE(smbd_max_send_size);
506PROC_FILE_DEFINE(smbd_send_credit_target);
507PROC_FILE_DEFINE(smbd_receive_credit_max);
508#endif
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000511static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000512static const struct file_operations cifs_lookup_cache_proc_fops;
513static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000514static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000515static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517void
518cifs_proc_init(void)
519{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700520 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (proc_fs_cifs == NULL)
522 return;
523
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200524 proc_create_single("DebugData", 0, proc_fs_cifs,
525 cifs_debug_data_proc_show);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527#ifdef CONFIG_CIFS_STATS
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000528 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000529#endif /* STATS */
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000530 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
531 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
532 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000533 &cifs_linux_ext_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000534 proc_create("SecurityFlags", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000535 &cifs_security_flags_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000536 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000537 &cifs_lookup_cache_proc_fops);
Long Lid8ec9132017-11-07 01:54:58 -0700538#ifdef CONFIG_CIFS_SMB_DIRECT
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000539 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700540 &cifs_rdma_readwrite_threshold_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000541 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700542 &cifs_smbd_max_frmr_depth_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000543 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700544 &cifs_smbd_keep_alive_interval_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000545 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700546 &cifs_smbd_max_receive_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000547 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700548 &cifs_smbd_max_fragmented_recv_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000549 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700550 &cifs_smbd_max_send_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000551 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700552 &cifs_smbd_send_credit_target_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000553 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700554 &cifs_smbd_receive_credit_max_proc_fops);
555#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558void
559cifs_proc_clean(void)
560{
561 if (proc_fs_cifs == NULL)
562 return;
563
564 remove_proc_entry("DebugData", proc_fs_cifs);
565 remove_proc_entry("cifsFYI", proc_fs_cifs);
566 remove_proc_entry("traceSMB", proc_fs_cifs);
567#ifdef CONFIG_CIFS_STATS
568 remove_proc_entry("Stats", proc_fs_cifs);
569#endif
Steve French221601c2007-06-05 20:35:06 +0000570 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000571 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000572 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Long Lid8ec9132017-11-07 01:54:58 -0700573#ifdef CONFIG_CIFS_SMB_DIRECT
574 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
575 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
576 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
577 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
578 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
579 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
580 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
581 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
582#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700583 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000586static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000588 seq_printf(m, "%d\n", cifsFYI);
589 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000591
592static int cifsFYI_proc_open(struct inode *inode, struct file *file)
593{
594 return single_open(file, cifsFYI_proc_show, NULL);
595}
596
597static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
598 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Kees Cook14042972016-03-17 14:22:54 -0700600 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300601 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 int rc;
603
Kees Cook14042972016-03-17 14:22:54 -0700604 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (rc)
606 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700607 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300608 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700609 else if ((c[0] > '1') && (c[0] <= '9'))
610 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Ronnie Sahlberg25ad1cb2018-05-24 09:53:39 +1000611 else
612 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 return count;
615}
616
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000617static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000618 .open = cifsFYI_proc_open,
619 .read = seq_read,
620 .llseek = seq_lseek,
621 .release = single_release,
622 .write = cifsFYI_proc_write,
623};
624
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000625static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000627 seq_printf(m, "%d\n", linuxExtEnabled);
628 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000630
631static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
632{
633 return single_open(file, cifs_linux_ext_proc_show, NULL);
634}
635
636static ssize_t cifs_linux_ext_proc_write(struct file *file,
637 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
Steve French221601c2007-06-05 20:35:06 +0000639 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Kees Cook14042972016-03-17 14:22:54 -0700641 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000642 if (rc)
643 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300644
Steve French221601c2007-06-05 20:35:06 +0000645 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000648static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000649 .open = cifs_linux_ext_proc_open,
650 .read = seq_read,
651 .llseek = seq_lseek,
652 .release = single_release,
653 .write = cifs_linux_ext_proc_write,
654};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000656static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000658 seq_printf(m, "%d\n", lookupCacheEnabled);
659 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000661
662static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
663{
664 return single_open(file, cifs_lookup_cache_proc_show, NULL);
665}
666
667static ssize_t cifs_lookup_cache_proc_write(struct file *file,
668 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 int rc;
671
Kees Cook14042972016-03-17 14:22:54 -0700672 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 if (rc)
674 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 return count;
677}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000678
679static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000680 .open = cifs_lookup_cache_proc_open,
681 .read = seq_read,
682 .llseek = seq_lseek,
683 .release = single_release,
684 .write = cifs_lookup_cache_proc_write,
685};
686
687static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000689 seq_printf(m, "%d\n", traceSMB);
690 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000692
693static int traceSMB_proc_open(struct inode *inode, struct file *file)
694{
695 return single_open(file, traceSMB_proc_show, NULL);
696}
697
698static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
699 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 int rc;
702
Kees Cook14042972016-03-17 14:22:54 -0700703 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (rc)
705 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 return count;
708}
709
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000710static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000711 .open = traceSMB_proc_open,
712 .read = seq_read,
713 .llseek = seq_lseek,
714 .release = single_release,
715 .write = traceSMB_proc_write,
716};
717
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000718static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Jeff Layton04912d62010-04-24 07:57:45 -0400720 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000721 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000723
724static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
725{
726 return single_open(file, cifs_security_flags_proc_show, NULL);
727}
728
Jeff Layton52dfb442013-05-26 07:01:02 -0400729/*
730 * Ensure that if someone sets a MUST flag, that we disable all other MAY
731 * flags except for the ones corresponding to the given MUST flag. If there are
732 * multiple MUST flags, then try to prefer more secure ones.
733 */
734static void
735cifs_security_flags_handle_must_flags(unsigned int *flags)
736{
737 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
738
739 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
740 *flags = CIFSSEC_MUST_KRB5;
741 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
742 *flags = CIFSSEC_MUST_NTLMSSP;
743 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
744 *flags = CIFSSEC_MUST_NTLMV2;
745 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
746 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100747 else if (CIFSSEC_MUST_LANMAN &&
748 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400749 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100750 else if (CIFSSEC_MUST_PLNTXT &&
751 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400752 *flags = CIFSSEC_MUST_PLNTXT;
753
754 *flags |= signflags;
755}
756
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000757static ssize_t cifs_security_flags_proc_write(struct file *file,
758 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Jeff Layton7715dad2013-05-26 07:01:01 -0400760 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000761 unsigned int flags;
762 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300763 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000764
Steve French221601c2007-06-05 20:35:06 +0000765 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000766 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000768 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000769
Steve French221601c2007-06-05 20:35:06 +0000770 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000771 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000772
Steve French221601c2007-06-05 20:35:06 +0000773 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000774 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700775 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300776 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000777 return count;
Kees Cook14042972016-03-17 14:22:54 -0700778 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400779 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
780 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000781 return -EINVAL;
782 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Jeff Layton7715dad2013-05-26 07:01:01 -0400785 /* else we have a number */
786 rc = kstrtouint(flags_string, 0, &flags);
787 if (rc) {
788 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
789 flags_string);
790 return rc;
791 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000792
Joe Perchesf96637b2013-05-04 22:12:25 -0500793 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000794
Jeff Layton7715dad2013-05-26 07:01:01 -0400795 if (flags == 0) {
796 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000797 return -EINVAL;
798 }
799
Steve French221601c2007-06-05 20:35:06 +0000800 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400801 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500802 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000803 return -EINVAL;
804 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400805
Jeff Layton52dfb442013-05-26 07:01:02 -0400806 cifs_security_flags_handle_must_flags(&flags);
807
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000808 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400809 global_secflags = flags;
810 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000811 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400812 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500813 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400814 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500815 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000816 }
817 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 return count;
819}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000820
821static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000822 .open = cifs_security_flags_proc_open,
823 .read = seq_read,
824 .llseek = seq_lseek,
825 .release = single_release,
826 .write = cifs_security_flags_proc_write,
827};
Steve French90c81e02008-02-12 20:32:36 +0000828#else
Steve Frenche086fce2008-02-18 04:03:58 +0000829inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000830{
831}
832
Steve Frenche086fce2008-02-18 04:03:58 +0000833inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000834{
835}
836#endif /* PROC_FS */