blob: e35e711db68ecaad868efc4bf0815c139fa99129 [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
Joe Perchesf96637b2013-05-04 22:12:25 -050045#ifdef CONFIG_CIFS_DEBUG
46void cifs_vfs_err(const char *fmt, ...)
47{
48 struct va_format vaf;
49 va_list args;
50
51 va_start(args, fmt);
52
53 vaf.fmt = fmt;
54 vaf.va = &args;
55
Jamie Bainbridgeec7147a2015-11-07 22:13:49 +100056 pr_err_ratelimited("CIFS VFS: %pV", &vaf);
Joe Perchesf96637b2013-05-04 22:12:25 -050057
58 va_end(args);
59}
60#endif
61
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040062void cifs_dump_detail(void *buf)
Steve French39798772006-05-31 22:40:51 +000063{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040064#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040065 struct smb_hdr *smb = (struct smb_hdr *)buf;
66
Joe Perchesf96637b2013-05-04 22:12:25 -050067 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
68 smb->Command, smb->Status.CifsError,
69 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
70 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040071#endif /* CONFIG_CIFS_DEBUG2 */
Steve French39798772006-05-31 22:40:51 +000072}
73
Steve Frenchffdd6e42007-06-24 21:15:44 +000074void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000075{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040076#ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +000077 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000078 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000079
Steve French221601c2007-06-05 20:35:06 +000080 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000081 return;
82
Joe Perchesf96637b2013-05-04 22:12:25 -050083 cifs_dbg(VFS, "Dump pending requests:\n");
Steve French39798772006-05-31 22:40:51 +000084 spin_lock(&GlobalMid_Lock);
85 list_for_each(tmp, &server->pending_mid_q) {
86 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesf96637b2013-05-04 22:12:25 -050087 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
88 mid_entry->mid_state,
89 le16_to_cpu(mid_entry->command),
90 mid_entry->pid,
91 mid_entry->callback_data,
92 mid_entry->mid);
Steve French39798772006-05-31 22:40:51 +000093#ifdef CONFIG_CIFS_STATS2
Joe Perchesf96637b2013-05-04 22:12:25 -050094 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
95 mid_entry->large_buf,
96 mid_entry->resp_buf,
97 mid_entry->when_received,
98 jiffies);
Steve French39798772006-05-31 22:40:51 +000099#endif /* STATS2 */
Joe Perchesf96637b2013-05-04 22:12:25 -0500100 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
101 mid_entry->multiRsp, mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +0000102 if (mid_entry->resp_buf) {
103 cifs_dump_detail(mid_entry->resp_buf);
104 cifs_dump_mem("existing buf: ",
105 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +0000106 }
107 }
108 spin_unlock(&GlobalMid_Lock);
Steve French39798772006-05-31 22:40:51 +0000109#endif /* CONFIG_CIFS_DEBUG2 */
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +0400110}
Steve French39798772006-05-31 22:40:51 +0000111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#ifdef CONFIG_PROC_FS
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100113static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
114{
115 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
116
117 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
118 if (tcon->nativeFileSystem)
119 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
120 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
121 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
122 le32_to_cpu(tcon->fsAttrInfo.Attributes),
123 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
124 tcon->tidStatus);
125 if (dev_type == FILE_DEVICE_DISK)
126 seq_puts(m, " type: DISK ");
127 else if (dev_type == FILE_DEVICE_CD_ROM)
128 seq_puts(m, " type: CDROM ");
129 else
130 seq_printf(m, " type: %d ", dev_type);
Steve Frenchede2e522018-01-31 14:34:37 -0600131 if (tcon->seal)
132 seq_printf(m, " Encrypted");
133 if (tcon->unix_ext)
134 seq_printf(m, " POSIX Extensions");
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100135 if (tcon->ses->server->ops->dump_share_caps)
136 tcon->ses->server->ops->dump_share_caps(m, tcon);
137
138 if (tcon->need_reconnect)
139 seq_puts(m, "\tDISCONNECTED ");
140 seq_putc(m, '\n');
141}
142
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000143static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500145 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000146 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500147 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000148 struct cifs_ses *ses;
149 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500150 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000152 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 "Display Internal CIFS Data Structures for Debugging\n"
154 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000155 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500156 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530157#ifdef CONFIG_CIFS_DFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500158 seq_printf(m, " dfs");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530159#endif
160#ifdef CONFIG_CIFS_FSCACHE
Jeff Laytonca40b712011-01-07 11:30:29 -0500161 seq_printf(m, " fscache");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530162#endif
163#ifdef CONFIG_CIFS_WEAK_PW_HASH
Jeff Laytonca40b712011-01-07 11:30:29 -0500164 seq_printf(m, " lanman");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530165#endif
166#ifdef CONFIG_CIFS_POSIX
Jeff Laytonca40b712011-01-07 11:30:29 -0500167 seq_printf(m, " posix");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530168#endif
169#ifdef CONFIG_CIFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500170 seq_printf(m, " spnego");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530171#endif
172#ifdef CONFIG_CIFS_XATTR
Jeff Laytonca40b712011-01-07 11:30:29 -0500173 seq_printf(m, " xattr");
174#endif
175#ifdef CONFIG_CIFS_ACL
176 seq_printf(m, " acl");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530177#endif
178 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000179 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
180 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530183 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500184 list_for_each(tmp1, &cifs_tcp_ses_list) {
185 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500186 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700187
188#ifdef CONFIG_CIFS_SMB_DIRECT
189 if (!server->rdma)
190 goto skip_rdma;
191
192 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
193 "transport status: %x",
194 server->smbd_conn->protocol,
195 server->smbd_conn->transport_status);
196 seq_printf(m, "\nConn receive_credit_max: %x "
197 "send_credit_target: %x max_send_size: %x",
198 server->smbd_conn->receive_credit_max,
199 server->smbd_conn->send_credit_target,
200 server->smbd_conn->max_send_size);
201 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
202 "max_fragmented_send_size: %x max_receive_size:%x",
203 server->smbd_conn->max_fragmented_recv_size,
204 server->smbd_conn->max_fragmented_send_size,
205 server->smbd_conn->max_receive_size);
206 seq_printf(m, "\nConn keep_alive_interval: %x "
207 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
208 server->smbd_conn->keep_alive_interval,
209 server->smbd_conn->max_readwrite_size,
210 server->smbd_conn->rdma_readwrite_threshold);
211 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
212 "count_put_receive_buffer: %x count_send_empty: %x",
213 server->smbd_conn->count_get_receive_buffer,
214 server->smbd_conn->count_put_receive_buffer,
215 server->smbd_conn->count_send_empty);
216 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
217 "count_enqueue_reassembly_queue: %x "
218 "count_dequeue_reassembly_queue: %x "
219 "fragment_reassembly_remaining: %x "
220 "reassembly_data_length: %x "
221 "reassembly_queue_length: %x",
222 server->smbd_conn->count_reassembly_queue,
223 server->smbd_conn->count_enqueue_reassembly_queue,
224 server->smbd_conn->count_dequeue_reassembly_queue,
225 server->smbd_conn->fragment_reassembly_remaining,
226 server->smbd_conn->reassembly_data_length,
227 server->smbd_conn->reassembly_queue_length);
228 seq_printf(m, "\nCurrent Credits send_credits: %x "
229 "receive_credits: %x receive_credit_target: %x",
230 atomic_read(&server->smbd_conn->send_credits),
231 atomic_read(&server->smbd_conn->receive_credits),
232 server->smbd_conn->receive_credit_target);
233 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
234 " %x smbd_send_pending: %x smbd_recv_pending: %x",
235 atomic_read(&server->smbd_conn->send_pending),
236 atomic_read(&server->smbd_conn->send_payload_pending),
237 server->smbd_conn->smbd_send_pending,
238 server->smbd_conn->smbd_recv_pending);
239 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
240 "count_empty_packet_queue: %x",
241 server->smbd_conn->count_receive_queue,
242 server->smbd_conn->count_empty_packet_queue);
243 seq_printf(m, "\nMR responder_resources: %x "
244 "max_frmr_depth: %x mr_type: %x",
245 server->smbd_conn->responder_resources,
246 server->smbd_conn->max_frmr_depth,
247 server->smbd_conn->mr_type);
248 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
249 atomic_read(&server->smbd_conn->mr_ready_count),
250 atomic_read(&server->smbd_conn->mr_used_count));
251skip_rdma:
252#endif
Steve Frenchede2e522018-01-31 14:34:37 -0600253 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
254 server->credits, server->dialect);
255 if (server->sign)
256 seq_printf(m, " signed");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500258 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000259 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500260 smb_ses_list);
261 if ((ses->serverDomain == NULL) ||
262 (ses->serverOS == NULL) ||
263 (ses->serverNOS == NULL)) {
Steve French1fa089e2017-09-20 16:46:49 -0500264 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
265 i, ses->serverName, ses->ses_count,
266 ses->capabilities, ses->status);
267 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
268 seq_printf(m, "Guest\t");
269 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
270 seq_printf(m, "Anonymous\t");
Jeff Layton14fbf502008-11-14 13:53:46 -0500271 } else {
272 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500273 "\n%d) Name: %s Domain: %s Uses: %d OS:"
274 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000275 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700276 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500277 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000278 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500279 }
Long Li8339dd32017-11-07 01:54:55 -0700280 if (server->rdma)
281 seq_printf(m, "RDMA\n\t");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000282 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500283 "Server: %d SecMode: 0x%x Req On Wire: %d",
284 server->tcpStatus, server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300285 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700286
287#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000288 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000289 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500290 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700291#endif
292
Jeff Laytonf1987b42008-11-15 11:12:47 -0500293 seq_puts(m, "\n\tShares:");
294 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100295
296 seq_printf(m, "\n\t%d) IPC: ", j);
297 if (ses->tcon_ipc)
298 cifs_debug_tcon(m, ses->tcon_ipc);
299 else
300 seq_puts(m, "none\n");
301
Jeff Laytonf1987b42008-11-15 11:12:47 -0500302 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000303 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500304 tcon_list);
305 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100306 seq_printf(m, "\n\t%d) ", j);
307 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500308 }
309
310 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500313 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500314 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500316 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400317 " %d cbdata: %p mid %llu\n",
318 mid_entry->mid_state,
319 le16_to_cpu(mid_entry->command),
320 mid_entry->pid,
321 mid_entry->callback_data,
322 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
Steve French221601c2007-06-05 20:35:06 +0000324 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530327 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000328 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000331 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000334static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
335{
336 return single_open(file, cifs_debug_data_proc_show, NULL);
337}
Steve French1047abc2005-10-11 19:58:06 -0700338
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000339static const struct file_operations cifs_debug_data_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000340 .open = cifs_debug_data_proc_open,
341 .read = seq_read,
342 .llseek = seq_lseek,
343 .release = single_release,
344};
345
346#ifdef CONFIG_CIFS_STATS
347static ssize_t cifs_stats_proc_write(struct file *file,
348 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700349{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300350 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000351 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500352 struct list_head *tmp1, *tmp2, *tmp3;
353 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000354 struct cifs_ses *ses;
355 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700356
Kees Cook14042972016-03-17 14:22:54 -0700357 rc = kstrtobool_from_user(buffer, count, &bv);
358 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800359#ifdef CONFIG_CIFS_STATS2
360 atomic_set(&totBufAllocCount, 0);
361 atomic_set(&totSmBufAllocCount, 0);
362#endif /* CONFIG_CIFS_STATS2 */
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530363 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500364 list_for_each(tmp1, &cifs_tcp_ses_list) {
365 server = list_entry(tmp1, struct TCP_Server_Info,
366 tcp_ses_list);
Steve Frenchc2b33822008-11-17 03:57:13 +0000367 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000368 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000369 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500370 list_for_each(tmp3, &ses->tcon_list) {
371 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000372 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500373 tcon_list);
374 atomic_set(&tcon->num_smbs_sent, 0);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400375 if (server->ops->clear_stats)
376 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500377 }
378 }
Steve French1047abc2005-10-11 19:58:06 -0700379 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530380 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700381 } else {
382 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700383 }
384
Steve French221601c2007-06-05 20:35:06 +0000385 return count;
Steve French1047abc2005-10-11 19:58:06 -0700386}
387
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000388static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000390 int i;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500391 struct list_head *tmp1, *tmp2, *tmp3;
392 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000393 struct cifs_ses *ses;
394 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000396 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 "Resources in use\nCIFS Session: %d\n",
398 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000399 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000401 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700402 bufAllocCount.counter,
403 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000404 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000405 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800406#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000407 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800408 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000409 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800410#endif /* CONFIG_CIFS_STATS2 */
411
Jeff Layton80975312011-01-11 07:24:02 -0500412 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000413 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000415 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000417 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000419 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530422 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500423 list_for_each(tmp1, &cifs_tcp_ses_list) {
424 server = list_entry(tmp1, struct TCP_Server_Info,
425 tcp_ses_list);
426 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000427 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500428 smb_ses_list);
429 list_for_each(tmp3, &ses->tcon_list) {
430 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000431 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500432 tcon_list);
433 i++;
434 seq_printf(m, "\n%d) %s", i, tcon->treeName);
435 if (tcon->need_reconnect)
436 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400437 seq_printf(m, "\nSMBs: %d",
438 atomic_read(&tcon->num_smbs_sent));
439 if (server->ops->print_stats)
440 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500441 }
442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530444 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000446 seq_putc(m, '\n');
447 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000449
450static int cifs_stats_proc_open(struct inode *inode, struct file *file)
451{
452 return single_open(file, cifs_stats_proc_show, NULL);
453}
454
455static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000456 .open = cifs_stats_proc_open,
457 .read = seq_read,
458 .llseek = seq_lseek,
459 .release = single_release,
460 .write = cifs_stats_proc_write,
461};
Steve French90c81e02008-02-12 20:32:36 +0000462#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Long Lid8ec9132017-11-07 01:54:58 -0700464#ifdef CONFIG_CIFS_SMB_DIRECT
465#define PROC_FILE_DEFINE(name) \
466static ssize_t name##_write(struct file *file, const char __user *buffer, \
467 size_t count, loff_t *ppos) \
468{ \
469 int rc; \
470 rc = kstrtoint_from_user(buffer, count, 10, & name); \
471 if (rc) \
472 return rc; \
473 return count; \
474} \
475static int name##_proc_show(struct seq_file *m, void *v) \
476{ \
477 seq_printf(m, "%d\n", name ); \
478 return 0; \
479} \
480static int name##_open(struct inode *inode, struct file *file) \
481{ \
482 return single_open(file, name##_proc_show, NULL); \
483} \
484\
485static const struct file_operations cifs_##name##_proc_fops = { \
486 .open = name##_open, \
487 .read = seq_read, \
488 .llseek = seq_lseek, \
489 .release = single_release, \
490 .write = name##_write, \
491}
492
Long Lid8ec9132017-11-07 01:54:58 -0700493PROC_FILE_DEFINE(rdma_readwrite_threshold);
494PROC_FILE_DEFINE(smbd_max_frmr_depth);
495PROC_FILE_DEFINE(smbd_keep_alive_interval);
496PROC_FILE_DEFINE(smbd_max_receive_size);
497PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
498PROC_FILE_DEFINE(smbd_max_send_size);
499PROC_FILE_DEFINE(smbd_send_credit_target);
500PROC_FILE_DEFINE(smbd_receive_credit_max);
501#endif
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000504static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000505static const struct file_operations cifs_lookup_cache_proc_fops;
506static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000507static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000508static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510void
511cifs_proc_init(void)
512{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700513 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if (proc_fs_cifs == NULL)
515 return;
516
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000517 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519#ifdef CONFIG_CIFS_STATS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000520 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000521#endif /* STATS */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000522 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
523 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000524 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
525 &cifs_linux_ext_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000526 proc_create("SecurityFlags", 0, proc_fs_cifs,
527 &cifs_security_flags_proc_fops);
528 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
529 &cifs_lookup_cache_proc_fops);
Long Lid8ec9132017-11-07 01:54:58 -0700530#ifdef CONFIG_CIFS_SMB_DIRECT
531 proc_create("rdma_readwrite_threshold", 0, proc_fs_cifs,
532 &cifs_rdma_readwrite_threshold_proc_fops);
533 proc_create("smbd_max_frmr_depth", 0, proc_fs_cifs,
534 &cifs_smbd_max_frmr_depth_proc_fops);
535 proc_create("smbd_keep_alive_interval", 0, proc_fs_cifs,
536 &cifs_smbd_keep_alive_interval_proc_fops);
537 proc_create("smbd_max_receive_size", 0, proc_fs_cifs,
538 &cifs_smbd_max_receive_size_proc_fops);
539 proc_create("smbd_max_fragmented_recv_size", 0, proc_fs_cifs,
540 &cifs_smbd_max_fragmented_recv_size_proc_fops);
541 proc_create("smbd_max_send_size", 0, proc_fs_cifs,
542 &cifs_smbd_max_send_size_proc_fops);
543 proc_create("smbd_send_credit_target", 0, proc_fs_cifs,
544 &cifs_smbd_send_credit_target_proc_fops);
545 proc_create("smbd_receive_credit_max", 0, proc_fs_cifs,
546 &cifs_smbd_receive_credit_max_proc_fops);
547#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
550void
551cifs_proc_clean(void)
552{
553 if (proc_fs_cifs == NULL)
554 return;
555
556 remove_proc_entry("DebugData", proc_fs_cifs);
557 remove_proc_entry("cifsFYI", proc_fs_cifs);
558 remove_proc_entry("traceSMB", proc_fs_cifs);
559#ifdef CONFIG_CIFS_STATS
560 remove_proc_entry("Stats", proc_fs_cifs);
561#endif
Steve French221601c2007-06-05 20:35:06 +0000562 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000563 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000564 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Long Lid8ec9132017-11-07 01:54:58 -0700565#ifdef CONFIG_CIFS_SMB_DIRECT
566 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
567 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
568 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
569 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
570 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
571 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
572 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
573 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
574#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700575 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000578static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000580 seq_printf(m, "%d\n", cifsFYI);
581 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000583
584static int cifsFYI_proc_open(struct inode *inode, struct file *file)
585{
586 return single_open(file, cifsFYI_proc_show, NULL);
587}
588
589static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
590 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Kees Cook14042972016-03-17 14:22:54 -0700592 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300593 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 int rc;
595
Kees Cook14042972016-03-17 14:22:54 -0700596 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 if (rc)
598 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700599 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300600 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700601 else if ((c[0] > '1') && (c[0] <= '9'))
602 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 return count;
605}
606
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000607static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000608 .open = cifsFYI_proc_open,
609 .read = seq_read,
610 .llseek = seq_lseek,
611 .release = single_release,
612 .write = cifsFYI_proc_write,
613};
614
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000615static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000617 seq_printf(m, "%d\n", linuxExtEnabled);
618 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000620
621static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
622{
623 return single_open(file, cifs_linux_ext_proc_show, NULL);
624}
625
626static ssize_t cifs_linux_ext_proc_write(struct file *file,
627 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
Steve French221601c2007-06-05 20:35:06 +0000629 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Kees Cook14042972016-03-17 14:22:54 -0700631 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000632 if (rc)
633 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300634
Steve French221601c2007-06-05 20:35:06 +0000635 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636}
637
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000638static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000639 .open = cifs_linux_ext_proc_open,
640 .read = seq_read,
641 .llseek = seq_lseek,
642 .release = single_release,
643 .write = cifs_linux_ext_proc_write,
644};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000646static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000648 seq_printf(m, "%d\n", lookupCacheEnabled);
649 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000651
652static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
653{
654 return single_open(file, cifs_lookup_cache_proc_show, NULL);
655}
656
657static ssize_t cifs_lookup_cache_proc_write(struct file *file,
658 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 int rc;
661
Kees Cook14042972016-03-17 14:22:54 -0700662 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 if (rc)
664 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return count;
667}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000668
669static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000670 .open = cifs_lookup_cache_proc_open,
671 .read = seq_read,
672 .llseek = seq_lseek,
673 .release = single_release,
674 .write = cifs_lookup_cache_proc_write,
675};
676
677static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000679 seq_printf(m, "%d\n", traceSMB);
680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000682
683static int traceSMB_proc_open(struct inode *inode, struct file *file)
684{
685 return single_open(file, traceSMB_proc_show, NULL);
686}
687
688static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
689 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 int rc;
692
Kees Cook14042972016-03-17 14:22:54 -0700693 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 if (rc)
695 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 return count;
698}
699
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000700static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000701 .open = traceSMB_proc_open,
702 .read = seq_read,
703 .llseek = seq_lseek,
704 .release = single_release,
705 .write = traceSMB_proc_write,
706};
707
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000708static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
Jeff Layton04912d62010-04-24 07:57:45 -0400710 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000711 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000713
714static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
715{
716 return single_open(file, cifs_security_flags_proc_show, NULL);
717}
718
Jeff Layton52dfb442013-05-26 07:01:02 -0400719/*
720 * Ensure that if someone sets a MUST flag, that we disable all other MAY
721 * flags except for the ones corresponding to the given MUST flag. If there are
722 * multiple MUST flags, then try to prefer more secure ones.
723 */
724static void
725cifs_security_flags_handle_must_flags(unsigned int *flags)
726{
727 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
728
729 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
730 *flags = CIFSSEC_MUST_KRB5;
731 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
732 *flags = CIFSSEC_MUST_NTLMSSP;
733 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
734 *flags = CIFSSEC_MUST_NTLMV2;
735 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
736 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100737 else if (CIFSSEC_MUST_LANMAN &&
738 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400739 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100740 else if (CIFSSEC_MUST_PLNTXT &&
741 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400742 *flags = CIFSSEC_MUST_PLNTXT;
743
744 *flags |= signflags;
745}
746
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000747static ssize_t cifs_security_flags_proc_write(struct file *file,
748 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
Jeff Layton7715dad2013-05-26 07:01:01 -0400750 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000751 unsigned int flags;
752 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300753 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000754
Steve French221601c2007-06-05 20:35:06 +0000755 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000756 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000758 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000759
Steve French221601c2007-06-05 20:35:06 +0000760 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000761 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000762
Steve French221601c2007-06-05 20:35:06 +0000763 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000764 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700765 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300766 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000767 return count;
Kees Cook14042972016-03-17 14:22:54 -0700768 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400769 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
770 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000771 return -EINVAL;
772 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Jeff Layton7715dad2013-05-26 07:01:01 -0400775 /* else we have a number */
776 rc = kstrtouint(flags_string, 0, &flags);
777 if (rc) {
778 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
779 flags_string);
780 return rc;
781 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000782
Joe Perchesf96637b2013-05-04 22:12:25 -0500783 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000784
Jeff Layton7715dad2013-05-26 07:01:01 -0400785 if (flags == 0) {
786 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000787 return -EINVAL;
788 }
789
Steve French221601c2007-06-05 20:35:06 +0000790 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400791 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500792 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000793 return -EINVAL;
794 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400795
Jeff Layton52dfb442013-05-26 07:01:02 -0400796 cifs_security_flags_handle_must_flags(&flags);
797
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000798 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400799 global_secflags = flags;
800 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000801 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400802 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500803 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400804 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500805 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000806 }
807 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return count;
809}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000810
811static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000812 .open = cifs_security_flags_proc_open,
813 .read = seq_read,
814 .llseek = seq_lseek,
815 .release = single_release,
816 .write = cifs_security_flags_proc_write,
817};
Steve French90c81e02008-02-12 20:32:36 +0000818#else
Steve Frenche086fce2008-02-18 04:03:58 +0000819inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000820{
821}
822
Steve Frenche086fce2008-02-18 04:03:58 +0000823inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000824{
825}
826#endif /* PROC_FS */