blob: 9d69ea433330ae8d1395a9ebfefd6db300874271 [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
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040045void cifs_dump_detail(void *buf)
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);
53 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040054#endif /* CONFIG_CIFS_DEBUG2 */
Steve French39798772006-05-31 22:40:51 +000055}
56
Steve Frenchffdd6e42007-06-24 21:15:44 +000057void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000058{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040059#ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +000060 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000061 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000062
Steve French221601c2007-06-05 20:35:06 +000063 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000064 return;
65
Joe Perchesf96637b2013-05-04 22:12:25 -050066 cifs_dbg(VFS, "Dump pending requests:\n");
Steve French39798772006-05-31 22:40:51 +000067 spin_lock(&GlobalMid_Lock);
68 list_for_each(tmp, &server->pending_mid_q) {
69 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesf96637b2013-05-04 22:12:25 -050070 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
71 mid_entry->mid_state,
72 le16_to_cpu(mid_entry->command),
73 mid_entry->pid,
74 mid_entry->callback_data,
75 mid_entry->mid);
Steve French39798772006-05-31 22:40:51 +000076#ifdef CONFIG_CIFS_STATS2
Joe Perchesf96637b2013-05-04 22:12:25 -050077 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
78 mid_entry->large_buf,
79 mid_entry->resp_buf,
80 mid_entry->when_received,
81 jiffies);
Steve French39798772006-05-31 22:40:51 +000082#endif /* STATS2 */
Joe Perchesf96637b2013-05-04 22:12:25 -050083 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
84 mid_entry->multiRsp, mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +000085 if (mid_entry->resp_buf) {
86 cifs_dump_detail(mid_entry->resp_buf);
87 cifs_dump_mem("existing buf: ",
88 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +000089 }
90 }
91 spin_unlock(&GlobalMid_Lock);
Steve French39798772006-05-31 22:40:51 +000092#endif /* CONFIG_CIFS_DEBUG2 */
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040093}
Steve French39798772006-05-31 22:40:51 +000094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#ifdef CONFIG_PROC_FS
Aurelien Aptel02cf5902018-01-24 13:46:12 +010096static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
97{
98 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
99
100 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
101 if (tcon->nativeFileSystem)
102 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
103 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
104 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
105 le32_to_cpu(tcon->fsAttrInfo.Attributes),
106 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
107 tcon->tidStatus);
108 if (dev_type == FILE_DEVICE_DISK)
109 seq_puts(m, " type: DISK ");
110 else if (dev_type == FILE_DEVICE_CD_ROM)
111 seq_puts(m, " type: CDROM ");
112 else
113 seq_printf(m, " type: %d ", dev_type);
Steve Frenchede2e522018-01-31 14:34:37 -0600114 if (tcon->seal)
115 seq_printf(m, " Encrypted");
116 if (tcon->unix_ext)
117 seq_printf(m, " POSIX Extensions");
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100118 if (tcon->ses->server->ops->dump_share_caps)
119 tcon->ses->server->ops->dump_share_caps(m, tcon);
120
121 if (tcon->need_reconnect)
122 seq_puts(m, "\tDISCONNECTED ");
123 seq_putc(m, '\n');
124}
125
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000126static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500128 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000129 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500130 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000131 struct cifs_ses *ses;
132 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500133 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000135 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 "Display Internal CIFS Data Structures for Debugging\n"
137 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000138 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500139 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530140#ifdef CONFIG_CIFS_DFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500141 seq_printf(m, " dfs");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530142#endif
143#ifdef CONFIG_CIFS_FSCACHE
Jeff Laytonca40b712011-01-07 11:30:29 -0500144 seq_printf(m, " fscache");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530145#endif
146#ifdef CONFIG_CIFS_WEAK_PW_HASH
Jeff Laytonca40b712011-01-07 11:30:29 -0500147 seq_printf(m, " lanman");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530148#endif
149#ifdef CONFIG_CIFS_POSIX
Jeff Laytonca40b712011-01-07 11:30:29 -0500150 seq_printf(m, " posix");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530151#endif
152#ifdef CONFIG_CIFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500153 seq_printf(m, " spnego");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530154#endif
155#ifdef CONFIG_CIFS_XATTR
Jeff Laytonca40b712011-01-07 11:30:29 -0500156 seq_printf(m, " xattr");
157#endif
158#ifdef CONFIG_CIFS_ACL
159 seq_printf(m, " acl");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530160#endif
161 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000162 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
163 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530166 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500167 list_for_each(tmp1, &cifs_tcp_ses_list) {
168 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500169 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700170
171#ifdef CONFIG_CIFS_SMB_DIRECT
172 if (!server->rdma)
173 goto skip_rdma;
174
175 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
176 "transport status: %x",
177 server->smbd_conn->protocol,
178 server->smbd_conn->transport_status);
179 seq_printf(m, "\nConn receive_credit_max: %x "
180 "send_credit_target: %x max_send_size: %x",
181 server->smbd_conn->receive_credit_max,
182 server->smbd_conn->send_credit_target,
183 server->smbd_conn->max_send_size);
184 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
185 "max_fragmented_send_size: %x max_receive_size:%x",
186 server->smbd_conn->max_fragmented_recv_size,
187 server->smbd_conn->max_fragmented_send_size,
188 server->smbd_conn->max_receive_size);
189 seq_printf(m, "\nConn keep_alive_interval: %x "
190 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
191 server->smbd_conn->keep_alive_interval,
192 server->smbd_conn->max_readwrite_size,
193 server->smbd_conn->rdma_readwrite_threshold);
194 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
195 "count_put_receive_buffer: %x count_send_empty: %x",
196 server->smbd_conn->count_get_receive_buffer,
197 server->smbd_conn->count_put_receive_buffer,
198 server->smbd_conn->count_send_empty);
199 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
200 "count_enqueue_reassembly_queue: %x "
201 "count_dequeue_reassembly_queue: %x "
202 "fragment_reassembly_remaining: %x "
203 "reassembly_data_length: %x "
204 "reassembly_queue_length: %x",
205 server->smbd_conn->count_reassembly_queue,
206 server->smbd_conn->count_enqueue_reassembly_queue,
207 server->smbd_conn->count_dequeue_reassembly_queue,
208 server->smbd_conn->fragment_reassembly_remaining,
209 server->smbd_conn->reassembly_data_length,
210 server->smbd_conn->reassembly_queue_length);
211 seq_printf(m, "\nCurrent Credits send_credits: %x "
212 "receive_credits: %x receive_credit_target: %x",
213 atomic_read(&server->smbd_conn->send_credits),
214 atomic_read(&server->smbd_conn->receive_credits),
215 server->smbd_conn->receive_credit_target);
216 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
217 " %x smbd_send_pending: %x smbd_recv_pending: %x",
218 atomic_read(&server->smbd_conn->send_pending),
219 atomic_read(&server->smbd_conn->send_payload_pending),
220 server->smbd_conn->smbd_send_pending,
221 server->smbd_conn->smbd_recv_pending);
222 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
223 "count_empty_packet_queue: %x",
224 server->smbd_conn->count_receive_queue,
225 server->smbd_conn->count_empty_packet_queue);
226 seq_printf(m, "\nMR responder_resources: %x "
227 "max_frmr_depth: %x mr_type: %x",
228 server->smbd_conn->responder_resources,
229 server->smbd_conn->max_frmr_depth,
230 server->smbd_conn->mr_type);
231 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
232 atomic_read(&server->smbd_conn->mr_ready_count),
233 atomic_read(&server->smbd_conn->mr_used_count));
234skip_rdma:
235#endif
Steve Frenchede2e522018-01-31 14:34:37 -0600236 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
237 server->credits, server->dialect);
238 if (server->sign)
239 seq_printf(m, " signed");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500241 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000242 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500243 smb_ses_list);
244 if ((ses->serverDomain == NULL) ||
245 (ses->serverOS == NULL) ||
246 (ses->serverNOS == NULL)) {
Steve French1fa089e2017-09-20 16:46:49 -0500247 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
248 i, ses->serverName, ses->ses_count,
249 ses->capabilities, ses->status);
250 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
251 seq_printf(m, "Guest\t");
252 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
253 seq_printf(m, "Anonymous\t");
Jeff Layton14fbf502008-11-14 13:53:46 -0500254 } else {
255 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500256 "\n%d) Name: %s Domain: %s Uses: %d OS:"
257 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000258 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700259 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500260 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000261 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500262 }
Long Li8339dd32017-11-07 01:54:55 -0700263 if (server->rdma)
264 seq_printf(m, "RDMA\n\t");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000265 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500266 "Server: %d SecMode: 0x%x Req On Wire: %d",
267 server->tcpStatus, server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300268 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700269
270#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000271 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000272 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500273 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700274#endif
275
Jeff Laytonf1987b42008-11-15 11:12:47 -0500276 seq_puts(m, "\n\tShares:");
277 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100278
279 seq_printf(m, "\n\t%d) IPC: ", j);
280 if (ses->tcon_ipc)
281 cifs_debug_tcon(m, ses->tcon_ipc);
282 else
283 seq_puts(m, "none\n");
284
Jeff Laytonf1987b42008-11-15 11:12:47 -0500285 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000286 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500287 tcon_list);
288 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100289 seq_printf(m, "\n\t%d) ", j);
290 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500291 }
292
293 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500296 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500297 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500299 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400300 " %d cbdata: %p mid %llu\n",
301 mid_entry->mid_state,
302 le16_to_cpu(mid_entry->command),
303 mid_entry->pid,
304 mid_entry->callback_data,
305 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
Steve French221601c2007-06-05 20:35:06 +0000307 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530310 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000311 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000314 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000317static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
318{
319 return single_open(file, cifs_debug_data_proc_show, NULL);
320}
Steve French1047abc2005-10-11 19:58:06 -0700321
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000322static const struct file_operations cifs_debug_data_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000323 .open = cifs_debug_data_proc_open,
324 .read = seq_read,
325 .llseek = seq_lseek,
326 .release = single_release,
327};
328
329#ifdef CONFIG_CIFS_STATS
330static ssize_t cifs_stats_proc_write(struct file *file,
331 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700332{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300333 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000334 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500335 struct list_head *tmp1, *tmp2, *tmp3;
336 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000337 struct cifs_ses *ses;
338 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700339
Kees Cook14042972016-03-17 14:22:54 -0700340 rc = kstrtobool_from_user(buffer, count, &bv);
341 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800342#ifdef CONFIG_CIFS_STATS2
343 atomic_set(&totBufAllocCount, 0);
344 atomic_set(&totSmBufAllocCount, 0);
345#endif /* CONFIG_CIFS_STATS2 */
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530346 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500347 list_for_each(tmp1, &cifs_tcp_ses_list) {
348 server = list_entry(tmp1, struct TCP_Server_Info,
349 tcp_ses_list);
Steve Frenchc2b33822008-11-17 03:57:13 +0000350 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000351 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000352 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500353 list_for_each(tmp3, &ses->tcon_list) {
354 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000355 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500356 tcon_list);
357 atomic_set(&tcon->num_smbs_sent, 0);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400358 if (server->ops->clear_stats)
359 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500360 }
361 }
Steve French1047abc2005-10-11 19:58:06 -0700362 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530363 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700364 } else {
365 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700366 }
367
Steve French221601c2007-06-05 20:35:06 +0000368 return count;
Steve French1047abc2005-10-11 19:58:06 -0700369}
370
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000371static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000373 int i;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500374 struct list_head *tmp1, *tmp2, *tmp3;
375 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000376 struct cifs_ses *ses;
377 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000379 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 "Resources in use\nCIFS Session: %d\n",
381 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000382 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000384 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700385 bufAllocCount.counter,
386 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000387 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000388 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800389#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000390 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800391 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000392 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800393#endif /* CONFIG_CIFS_STATS2 */
394
Jeff Layton80975312011-01-11 07:24:02 -0500395 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000396 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000398 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000400 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000402 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530405 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500406 list_for_each(tmp1, &cifs_tcp_ses_list) {
407 server = list_entry(tmp1, struct TCP_Server_Info,
408 tcp_ses_list);
409 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000410 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500411 smb_ses_list);
412 list_for_each(tmp3, &ses->tcon_list) {
413 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000414 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500415 tcon_list);
416 i++;
417 seq_printf(m, "\n%d) %s", i, tcon->treeName);
418 if (tcon->need_reconnect)
419 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400420 seq_printf(m, "\nSMBs: %d",
421 atomic_read(&tcon->num_smbs_sent));
422 if (server->ops->print_stats)
423 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500424 }
425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530427 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000429 seq_putc(m, '\n');
430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000432
433static int cifs_stats_proc_open(struct inode *inode, struct file *file)
434{
435 return single_open(file, cifs_stats_proc_show, NULL);
436}
437
438static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000439 .open = cifs_stats_proc_open,
440 .read = seq_read,
441 .llseek = seq_lseek,
442 .release = single_release,
443 .write = cifs_stats_proc_write,
444};
Steve French90c81e02008-02-12 20:32:36 +0000445#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Long Lid8ec9132017-11-07 01:54:58 -0700447#ifdef CONFIG_CIFS_SMB_DIRECT
448#define PROC_FILE_DEFINE(name) \
449static ssize_t name##_write(struct file *file, const char __user *buffer, \
450 size_t count, loff_t *ppos) \
451{ \
452 int rc; \
453 rc = kstrtoint_from_user(buffer, count, 10, & name); \
454 if (rc) \
455 return rc; \
456 return count; \
457} \
458static int name##_proc_show(struct seq_file *m, void *v) \
459{ \
460 seq_printf(m, "%d\n", name ); \
461 return 0; \
462} \
463static int name##_open(struct inode *inode, struct file *file) \
464{ \
465 return single_open(file, name##_proc_show, NULL); \
466} \
467\
468static const struct file_operations cifs_##name##_proc_fops = { \
469 .open = name##_open, \
470 .read = seq_read, \
471 .llseek = seq_lseek, \
472 .release = single_release, \
473 .write = name##_write, \
474}
475
Long Lid8ec9132017-11-07 01:54:58 -0700476PROC_FILE_DEFINE(rdma_readwrite_threshold);
477PROC_FILE_DEFINE(smbd_max_frmr_depth);
478PROC_FILE_DEFINE(smbd_keep_alive_interval);
479PROC_FILE_DEFINE(smbd_max_receive_size);
480PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
481PROC_FILE_DEFINE(smbd_max_send_size);
482PROC_FILE_DEFINE(smbd_send_credit_target);
483PROC_FILE_DEFINE(smbd_receive_credit_max);
484#endif
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000487static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000488static const struct file_operations cifs_lookup_cache_proc_fops;
489static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000490static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000491static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493void
494cifs_proc_init(void)
495{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700496 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (proc_fs_cifs == NULL)
498 return;
499
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000500 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502#ifdef CONFIG_CIFS_STATS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000503 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000504#endif /* STATS */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000505 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
506 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000507 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
508 &cifs_linux_ext_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000509 proc_create("SecurityFlags", 0, proc_fs_cifs,
510 &cifs_security_flags_proc_fops);
511 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
512 &cifs_lookup_cache_proc_fops);
Long Lid8ec9132017-11-07 01:54:58 -0700513#ifdef CONFIG_CIFS_SMB_DIRECT
514 proc_create("rdma_readwrite_threshold", 0, proc_fs_cifs,
515 &cifs_rdma_readwrite_threshold_proc_fops);
516 proc_create("smbd_max_frmr_depth", 0, proc_fs_cifs,
517 &cifs_smbd_max_frmr_depth_proc_fops);
518 proc_create("smbd_keep_alive_interval", 0, proc_fs_cifs,
519 &cifs_smbd_keep_alive_interval_proc_fops);
520 proc_create("smbd_max_receive_size", 0, proc_fs_cifs,
521 &cifs_smbd_max_receive_size_proc_fops);
522 proc_create("smbd_max_fragmented_recv_size", 0, proc_fs_cifs,
523 &cifs_smbd_max_fragmented_recv_size_proc_fops);
524 proc_create("smbd_max_send_size", 0, proc_fs_cifs,
525 &cifs_smbd_max_send_size_proc_fops);
526 proc_create("smbd_send_credit_target", 0, proc_fs_cifs,
527 &cifs_smbd_send_credit_target_proc_fops);
528 proc_create("smbd_receive_credit_max", 0, proc_fs_cifs,
529 &cifs_smbd_receive_credit_max_proc_fops);
530#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
533void
534cifs_proc_clean(void)
535{
536 if (proc_fs_cifs == NULL)
537 return;
538
539 remove_proc_entry("DebugData", proc_fs_cifs);
540 remove_proc_entry("cifsFYI", proc_fs_cifs);
541 remove_proc_entry("traceSMB", proc_fs_cifs);
542#ifdef CONFIG_CIFS_STATS
543 remove_proc_entry("Stats", proc_fs_cifs);
544#endif
Steve French221601c2007-06-05 20:35:06 +0000545 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000546 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000547 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Long Lid8ec9132017-11-07 01:54:58 -0700548#ifdef CONFIG_CIFS_SMB_DIRECT
549 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
550 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
551 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
552 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
553 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
554 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
555 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
556 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
557#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700558 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000561static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000563 seq_printf(m, "%d\n", cifsFYI);
564 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000566
567static int cifsFYI_proc_open(struct inode *inode, struct file *file)
568{
569 return single_open(file, cifsFYI_proc_show, NULL);
570}
571
572static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
573 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Kees Cook14042972016-03-17 14:22:54 -0700575 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300576 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 int rc;
578
Kees Cook14042972016-03-17 14:22:54 -0700579 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (rc)
581 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700582 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300583 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700584 else if ((c[0] > '1') && (c[0] <= '9'))
585 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 return count;
588}
589
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000590static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000591 .open = cifsFYI_proc_open,
592 .read = seq_read,
593 .llseek = seq_lseek,
594 .release = single_release,
595 .write = cifsFYI_proc_write,
596};
597
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000598static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000600 seq_printf(m, "%d\n", linuxExtEnabled);
601 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000603
604static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
605{
606 return single_open(file, cifs_linux_ext_proc_show, NULL);
607}
608
609static ssize_t cifs_linux_ext_proc_write(struct file *file,
610 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Steve French221601c2007-06-05 20:35:06 +0000612 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Kees Cook14042972016-03-17 14:22:54 -0700614 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000615 if (rc)
616 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300617
Steve French221601c2007-06-05 20:35:06 +0000618 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000621static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000622 .open = cifs_linux_ext_proc_open,
623 .read = seq_read,
624 .llseek = seq_lseek,
625 .release = single_release,
626 .write = cifs_linux_ext_proc_write,
627};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000629static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000631 seq_printf(m, "%d\n", lookupCacheEnabled);
632 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000634
635static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
636{
637 return single_open(file, cifs_lookup_cache_proc_show, NULL);
638}
639
640static ssize_t cifs_lookup_cache_proc_write(struct file *file,
641 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 int rc;
644
Kees Cook14042972016-03-17 14:22:54 -0700645 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (rc)
647 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return count;
650}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000651
652static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000653 .open = cifs_lookup_cache_proc_open,
654 .read = seq_read,
655 .llseek = seq_lseek,
656 .release = single_release,
657 .write = cifs_lookup_cache_proc_write,
658};
659
660static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000662 seq_printf(m, "%d\n", traceSMB);
663 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000665
666static int traceSMB_proc_open(struct inode *inode, struct file *file)
667{
668 return single_open(file, traceSMB_proc_show, NULL);
669}
670
671static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
672 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 int rc;
675
Kees Cook14042972016-03-17 14:22:54 -0700676 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if (rc)
678 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 return count;
681}
682
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000683static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000684 .open = traceSMB_proc_open,
685 .read = seq_read,
686 .llseek = seq_lseek,
687 .release = single_release,
688 .write = traceSMB_proc_write,
689};
690
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000691static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692{
Jeff Layton04912d62010-04-24 07:57:45 -0400693 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000694 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000696
697static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
698{
699 return single_open(file, cifs_security_flags_proc_show, NULL);
700}
701
Jeff Layton52dfb442013-05-26 07:01:02 -0400702/*
703 * Ensure that if someone sets a MUST flag, that we disable all other MAY
704 * flags except for the ones corresponding to the given MUST flag. If there are
705 * multiple MUST flags, then try to prefer more secure ones.
706 */
707static void
708cifs_security_flags_handle_must_flags(unsigned int *flags)
709{
710 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
711
712 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
713 *flags = CIFSSEC_MUST_KRB5;
714 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
715 *flags = CIFSSEC_MUST_NTLMSSP;
716 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
717 *flags = CIFSSEC_MUST_NTLMV2;
718 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
719 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100720 else if (CIFSSEC_MUST_LANMAN &&
721 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400722 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100723 else if (CIFSSEC_MUST_PLNTXT &&
724 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400725 *flags = CIFSSEC_MUST_PLNTXT;
726
727 *flags |= signflags;
728}
729
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000730static ssize_t cifs_security_flags_proc_write(struct file *file,
731 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Jeff Layton7715dad2013-05-26 07:01:01 -0400733 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000734 unsigned int flags;
735 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300736 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000737
Steve French221601c2007-06-05 20:35:06 +0000738 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000739 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000741 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000742
Steve French221601c2007-06-05 20:35:06 +0000743 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000744 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000745
Steve French221601c2007-06-05 20:35:06 +0000746 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000747 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700748 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300749 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000750 return count;
Kees Cook14042972016-03-17 14:22:54 -0700751 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400752 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
753 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000754 return -EINVAL;
755 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Jeff Layton7715dad2013-05-26 07:01:01 -0400758 /* else we have a number */
759 rc = kstrtouint(flags_string, 0, &flags);
760 if (rc) {
761 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
762 flags_string);
763 return rc;
764 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000765
Joe Perchesf96637b2013-05-04 22:12:25 -0500766 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000767
Jeff Layton7715dad2013-05-26 07:01:01 -0400768 if (flags == 0) {
769 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000770 return -EINVAL;
771 }
772
Steve French221601c2007-06-05 20:35:06 +0000773 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400774 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500775 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000776 return -EINVAL;
777 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400778
Jeff Layton52dfb442013-05-26 07:01:02 -0400779 cifs_security_flags_handle_must_flags(&flags);
780
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000781 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400782 global_secflags = flags;
783 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000784 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400785 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500786 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400787 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500788 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000789 }
790 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 return count;
792}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000793
794static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000795 .open = cifs_security_flags_proc_open,
796 .read = seq_read,
797 .llseek = seq_lseek,
798 .release = single_release,
799 .write = cifs_security_flags_proc_write,
800};
Steve French90c81e02008-02-12 20:32:36 +0000801#else
Steve Frenche086fce2008-02-18 04:03:58 +0000802inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000803{
804}
805
Steve Frenche086fce2008-02-18 04:03:58 +0000806inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000807{
808}
809#endif /* PROC_FS */