blob: 43ae00cd160f9551f1e085a51ffbe87a0cc5a2ff [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,
54 server->ops->calc_smb_size(smb));
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) {
87 cifs_dump_detail(mid_entry->resp_buf);
88 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");
117 if (tcon->unix_ext)
118 seq_printf(m, " POSIX Extensions");
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100119 if (tcon->ses->server->ops->dump_share_caps)
120 tcon->ses->server->ops->dump_share_caps(m, tcon);
121
122 if (tcon->need_reconnect)
123 seq_puts(m, "\tDISCONNECTED ");
124 seq_putc(m, '\n');
125}
126
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000127static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500129 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000130 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500131 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000132 struct cifs_ses *ses;
133 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500134 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000136 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 "Display Internal CIFS Data Structures for Debugging\n"
138 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000139 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500140 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530141#ifdef CONFIG_CIFS_DFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500142 seq_printf(m, " dfs");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530143#endif
144#ifdef CONFIG_CIFS_FSCACHE
Jeff Laytonca40b712011-01-07 11:30:29 -0500145 seq_printf(m, " fscache");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530146#endif
147#ifdef CONFIG_CIFS_WEAK_PW_HASH
Jeff Laytonca40b712011-01-07 11:30:29 -0500148 seq_printf(m, " lanman");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530149#endif
150#ifdef CONFIG_CIFS_POSIX
Jeff Laytonca40b712011-01-07 11:30:29 -0500151 seq_printf(m, " posix");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530152#endif
153#ifdef CONFIG_CIFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500154 seq_printf(m, " spnego");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530155#endif
156#ifdef CONFIG_CIFS_XATTR
Jeff Laytonca40b712011-01-07 11:30:29 -0500157 seq_printf(m, " xattr");
158#endif
159#ifdef CONFIG_CIFS_ACL
160 seq_printf(m, " acl");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530161#endif
162 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000163 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
164 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530167 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500168 list_for_each(tmp1, &cifs_tcp_ses_list) {
169 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500170 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700171
172#ifdef CONFIG_CIFS_SMB_DIRECT
173 if (!server->rdma)
174 goto skip_rdma;
175
176 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
177 "transport status: %x",
178 server->smbd_conn->protocol,
179 server->smbd_conn->transport_status);
180 seq_printf(m, "\nConn receive_credit_max: %x "
181 "send_credit_target: %x max_send_size: %x",
182 server->smbd_conn->receive_credit_max,
183 server->smbd_conn->send_credit_target,
184 server->smbd_conn->max_send_size);
185 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
186 "max_fragmented_send_size: %x max_receive_size:%x",
187 server->smbd_conn->max_fragmented_recv_size,
188 server->smbd_conn->max_fragmented_send_size,
189 server->smbd_conn->max_receive_size);
190 seq_printf(m, "\nConn keep_alive_interval: %x "
191 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
192 server->smbd_conn->keep_alive_interval,
193 server->smbd_conn->max_readwrite_size,
194 server->smbd_conn->rdma_readwrite_threshold);
195 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
196 "count_put_receive_buffer: %x count_send_empty: %x",
197 server->smbd_conn->count_get_receive_buffer,
198 server->smbd_conn->count_put_receive_buffer,
199 server->smbd_conn->count_send_empty);
200 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
201 "count_enqueue_reassembly_queue: %x "
202 "count_dequeue_reassembly_queue: %x "
203 "fragment_reassembly_remaining: %x "
204 "reassembly_data_length: %x "
205 "reassembly_queue_length: %x",
206 server->smbd_conn->count_reassembly_queue,
207 server->smbd_conn->count_enqueue_reassembly_queue,
208 server->smbd_conn->count_dequeue_reassembly_queue,
209 server->smbd_conn->fragment_reassembly_remaining,
210 server->smbd_conn->reassembly_data_length,
211 server->smbd_conn->reassembly_queue_length);
212 seq_printf(m, "\nCurrent Credits send_credits: %x "
213 "receive_credits: %x receive_credit_target: %x",
214 atomic_read(&server->smbd_conn->send_credits),
215 atomic_read(&server->smbd_conn->receive_credits),
216 server->smbd_conn->receive_credit_target);
217 seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
218 " %x smbd_send_pending: %x smbd_recv_pending: %x",
219 atomic_read(&server->smbd_conn->send_pending),
220 atomic_read(&server->smbd_conn->send_payload_pending),
221 server->smbd_conn->smbd_send_pending,
222 server->smbd_conn->smbd_recv_pending);
223 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
224 "count_empty_packet_queue: %x",
225 server->smbd_conn->count_receive_queue,
226 server->smbd_conn->count_empty_packet_queue);
227 seq_printf(m, "\nMR responder_resources: %x "
228 "max_frmr_depth: %x mr_type: %x",
229 server->smbd_conn->responder_resources,
230 server->smbd_conn->max_frmr_depth,
231 server->smbd_conn->mr_type);
232 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
233 atomic_read(&server->smbd_conn->mr_ready_count),
234 atomic_read(&server->smbd_conn->mr_used_count));
235skip_rdma:
236#endif
Steve Frenchede2e522018-01-31 14:34:37 -0600237 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
238 server->credits, server->dialect);
239 if (server->sign)
240 seq_printf(m, " signed");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500242 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000243 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500244 smb_ses_list);
245 if ((ses->serverDomain == NULL) ||
246 (ses->serverOS == NULL) ||
247 (ses->serverNOS == NULL)) {
Steve French1fa089e2017-09-20 16:46:49 -0500248 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
249 i, ses->serverName, ses->ses_count,
250 ses->capabilities, ses->status);
251 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
252 seq_printf(m, "Guest\t");
253 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
254 seq_printf(m, "Anonymous\t");
Jeff Layton14fbf502008-11-14 13:53:46 -0500255 } else {
256 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500257 "\n%d) Name: %s Domain: %s Uses: %d OS:"
258 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000259 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700260 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500261 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000262 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500263 }
Long Li8339dd32017-11-07 01:54:55 -0700264 if (server->rdma)
265 seq_printf(m, "RDMA\n\t");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000266 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500267 "Server: %d SecMode: 0x%x Req On Wire: %d",
268 server->tcpStatus, server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300269 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700270
271#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000272 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000273 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500274 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700275#endif
276
Jeff Laytonf1987b42008-11-15 11:12:47 -0500277 seq_puts(m, "\n\tShares:");
278 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100279
280 seq_printf(m, "\n\t%d) IPC: ", j);
281 if (ses->tcon_ipc)
282 cifs_debug_tcon(m, ses->tcon_ipc);
283 else
284 seq_puts(m, "none\n");
285
Jeff Laytonf1987b42008-11-15 11:12:47 -0500286 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000287 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500288 tcon_list);
289 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100290 seq_printf(m, "\n\t%d) ", j);
291 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500292 }
293
294 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500297 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500298 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500300 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400301 " %d cbdata: %p mid %llu\n",
302 mid_entry->mid_state,
303 le16_to_cpu(mid_entry->command),
304 mid_entry->pid,
305 mid_entry->callback_data,
306 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Steve French221601c2007-06-05 20:35:06 +0000308 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530311 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000312 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000315 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000318static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
319{
320 return single_open(file, cifs_debug_data_proc_show, NULL);
321}
Steve French1047abc2005-10-11 19:58:06 -0700322
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000323static const struct file_operations cifs_debug_data_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000324 .open = cifs_debug_data_proc_open,
325 .read = seq_read,
326 .llseek = seq_lseek,
327 .release = single_release,
328};
329
330#ifdef CONFIG_CIFS_STATS
331static ssize_t cifs_stats_proc_write(struct file *file,
332 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700333{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300334 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000335 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500336 struct list_head *tmp1, *tmp2, *tmp3;
337 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000338 struct cifs_ses *ses;
339 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700340
Kees Cook14042972016-03-17 14:22:54 -0700341 rc = kstrtobool_from_user(buffer, count, &bv);
342 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800343#ifdef CONFIG_CIFS_STATS2
344 atomic_set(&totBufAllocCount, 0);
345 atomic_set(&totSmBufAllocCount, 0);
346#endif /* CONFIG_CIFS_STATS2 */
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530347 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500348 list_for_each(tmp1, &cifs_tcp_ses_list) {
349 server = list_entry(tmp1, struct TCP_Server_Info,
350 tcp_ses_list);
Steve Frenchc2b33822008-11-17 03:57:13 +0000351 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000352 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000353 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500354 list_for_each(tmp3, &ses->tcon_list) {
355 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000356 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500357 tcon_list);
358 atomic_set(&tcon->num_smbs_sent, 0);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400359 if (server->ops->clear_stats)
360 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500361 }
362 }
Steve French1047abc2005-10-11 19:58:06 -0700363 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530364 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700365 } else {
366 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700367 }
368
Steve French221601c2007-06-05 20:35:06 +0000369 return count;
Steve French1047abc2005-10-11 19:58:06 -0700370}
371
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000372static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000374 int i;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500375 struct list_head *tmp1, *tmp2, *tmp3;
376 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000377 struct cifs_ses *ses;
378 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000380 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 "Resources in use\nCIFS Session: %d\n",
382 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000383 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000385 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700386 bufAllocCount.counter,
387 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000388 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000389 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800390#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000391 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800392 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000393 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800394#endif /* CONFIG_CIFS_STATS2 */
395
Jeff Layton80975312011-01-11 07:24:02 -0500396 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000397 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000399 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000401 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000403 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530406 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500407 list_for_each(tmp1, &cifs_tcp_ses_list) {
408 server = list_entry(tmp1, struct TCP_Server_Info,
409 tcp_ses_list);
410 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000411 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500412 smb_ses_list);
413 list_for_each(tmp3, &ses->tcon_list) {
414 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000415 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500416 tcon_list);
417 i++;
418 seq_printf(m, "\n%d) %s", i, tcon->treeName);
419 if (tcon->need_reconnect)
420 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400421 seq_printf(m, "\nSMBs: %d",
422 atomic_read(&tcon->num_smbs_sent));
423 if (server->ops->print_stats)
424 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500425 }
426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530428 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000430 seq_putc(m, '\n');
431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000433
434static int cifs_stats_proc_open(struct inode *inode, struct file *file)
435{
436 return single_open(file, cifs_stats_proc_show, NULL);
437}
438
439static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000440 .open = cifs_stats_proc_open,
441 .read = seq_read,
442 .llseek = seq_lseek,
443 .release = single_release,
444 .write = cifs_stats_proc_write,
445};
Steve French90c81e02008-02-12 20:32:36 +0000446#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Long Lid8ec9132017-11-07 01:54:58 -0700448#ifdef CONFIG_CIFS_SMB_DIRECT
449#define PROC_FILE_DEFINE(name) \
450static ssize_t name##_write(struct file *file, const char __user *buffer, \
451 size_t count, loff_t *ppos) \
452{ \
453 int rc; \
454 rc = kstrtoint_from_user(buffer, count, 10, & name); \
455 if (rc) \
456 return rc; \
457 return count; \
458} \
459static int name##_proc_show(struct seq_file *m, void *v) \
460{ \
461 seq_printf(m, "%d\n", name ); \
462 return 0; \
463} \
464static int name##_open(struct inode *inode, struct file *file) \
465{ \
466 return single_open(file, name##_proc_show, NULL); \
467} \
468\
469static const struct file_operations cifs_##name##_proc_fops = { \
470 .open = name##_open, \
471 .read = seq_read, \
472 .llseek = seq_lseek, \
473 .release = single_release, \
474 .write = name##_write, \
475}
476
Long Lid8ec9132017-11-07 01:54:58 -0700477PROC_FILE_DEFINE(rdma_readwrite_threshold);
478PROC_FILE_DEFINE(smbd_max_frmr_depth);
479PROC_FILE_DEFINE(smbd_keep_alive_interval);
480PROC_FILE_DEFINE(smbd_max_receive_size);
481PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
482PROC_FILE_DEFINE(smbd_max_send_size);
483PROC_FILE_DEFINE(smbd_send_credit_target);
484PROC_FILE_DEFINE(smbd_receive_credit_max);
485#endif
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000488static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000489static const struct file_operations cifs_lookup_cache_proc_fops;
490static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000491static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000492static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494void
495cifs_proc_init(void)
496{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700497 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (proc_fs_cifs == NULL)
499 return;
500
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000501 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503#ifdef CONFIG_CIFS_STATS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000504 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000505#endif /* STATS */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000506 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
507 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000508 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
509 &cifs_linux_ext_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000510 proc_create("SecurityFlags", 0, proc_fs_cifs,
511 &cifs_security_flags_proc_fops);
512 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
513 &cifs_lookup_cache_proc_fops);
Long Lid8ec9132017-11-07 01:54:58 -0700514#ifdef CONFIG_CIFS_SMB_DIRECT
515 proc_create("rdma_readwrite_threshold", 0, proc_fs_cifs,
516 &cifs_rdma_readwrite_threshold_proc_fops);
517 proc_create("smbd_max_frmr_depth", 0, proc_fs_cifs,
518 &cifs_smbd_max_frmr_depth_proc_fops);
519 proc_create("smbd_keep_alive_interval", 0, proc_fs_cifs,
520 &cifs_smbd_keep_alive_interval_proc_fops);
521 proc_create("smbd_max_receive_size", 0, proc_fs_cifs,
522 &cifs_smbd_max_receive_size_proc_fops);
523 proc_create("smbd_max_fragmented_recv_size", 0, proc_fs_cifs,
524 &cifs_smbd_max_fragmented_recv_size_proc_fops);
525 proc_create("smbd_max_send_size", 0, proc_fs_cifs,
526 &cifs_smbd_max_send_size_proc_fops);
527 proc_create("smbd_send_credit_target", 0, proc_fs_cifs,
528 &cifs_smbd_send_credit_target_proc_fops);
529 proc_create("smbd_receive_credit_max", 0, proc_fs_cifs,
530 &cifs_smbd_receive_credit_max_proc_fops);
531#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
534void
535cifs_proc_clean(void)
536{
537 if (proc_fs_cifs == NULL)
538 return;
539
540 remove_proc_entry("DebugData", proc_fs_cifs);
541 remove_proc_entry("cifsFYI", proc_fs_cifs);
542 remove_proc_entry("traceSMB", proc_fs_cifs);
543#ifdef CONFIG_CIFS_STATS
544 remove_proc_entry("Stats", proc_fs_cifs);
545#endif
Steve French221601c2007-06-05 20:35:06 +0000546 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000547 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000548 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Long Lid8ec9132017-11-07 01:54:58 -0700549#ifdef CONFIG_CIFS_SMB_DIRECT
550 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
551 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
552 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
553 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
554 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
555 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
556 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
557 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
558#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700559 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000562static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000564 seq_printf(m, "%d\n", cifsFYI);
565 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000567
568static int cifsFYI_proc_open(struct inode *inode, struct file *file)
569{
570 return single_open(file, cifsFYI_proc_show, NULL);
571}
572
573static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
574 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Kees Cook14042972016-03-17 14:22:54 -0700576 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300577 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 int rc;
579
Kees Cook14042972016-03-17 14:22:54 -0700580 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 if (rc)
582 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700583 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300584 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700585 else if ((c[0] > '1') && (c[0] <= '9'))
586 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 return count;
589}
590
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000591static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000592 .open = cifsFYI_proc_open,
593 .read = seq_read,
594 .llseek = seq_lseek,
595 .release = single_release,
596 .write = cifsFYI_proc_write,
597};
598
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000599static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000601 seq_printf(m, "%d\n", linuxExtEnabled);
602 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000604
605static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
606{
607 return single_open(file, cifs_linux_ext_proc_show, NULL);
608}
609
610static ssize_t cifs_linux_ext_proc_write(struct file *file,
611 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
Steve French221601c2007-06-05 20:35:06 +0000613 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Kees Cook14042972016-03-17 14:22:54 -0700615 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000616 if (rc)
617 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300618
Steve French221601c2007-06-05 20:35:06 +0000619 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000622static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000623 .open = cifs_linux_ext_proc_open,
624 .read = seq_read,
625 .llseek = seq_lseek,
626 .release = single_release,
627 .write = cifs_linux_ext_proc_write,
628};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000630static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000632 seq_printf(m, "%d\n", lookupCacheEnabled);
633 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000635
636static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
637{
638 return single_open(file, cifs_lookup_cache_proc_show, NULL);
639}
640
641static ssize_t cifs_lookup_cache_proc_write(struct file *file,
642 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 int rc;
645
Kees Cook14042972016-03-17 14:22:54 -0700646 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (rc)
648 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 return count;
651}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000652
653static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000654 .open = cifs_lookup_cache_proc_open,
655 .read = seq_read,
656 .llseek = seq_lseek,
657 .release = single_release,
658 .write = cifs_lookup_cache_proc_write,
659};
660
661static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000663 seq_printf(m, "%d\n", traceSMB);
664 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000666
667static int traceSMB_proc_open(struct inode *inode, struct file *file)
668{
669 return single_open(file, traceSMB_proc_show, NULL);
670}
671
672static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
673 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 int rc;
676
Kees Cook14042972016-03-17 14:22:54 -0700677 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (rc)
679 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 return count;
682}
683
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000684static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000685 .open = traceSMB_proc_open,
686 .read = seq_read,
687 .llseek = seq_lseek,
688 .release = single_release,
689 .write = traceSMB_proc_write,
690};
691
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000692static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Jeff Layton04912d62010-04-24 07:57:45 -0400694 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000695 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000697
698static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
699{
700 return single_open(file, cifs_security_flags_proc_show, NULL);
701}
702
Jeff Layton52dfb442013-05-26 07:01:02 -0400703/*
704 * Ensure that if someone sets a MUST flag, that we disable all other MAY
705 * flags except for the ones corresponding to the given MUST flag. If there are
706 * multiple MUST flags, then try to prefer more secure ones.
707 */
708static void
709cifs_security_flags_handle_must_flags(unsigned int *flags)
710{
711 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
712
713 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
714 *flags = CIFSSEC_MUST_KRB5;
715 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
716 *flags = CIFSSEC_MUST_NTLMSSP;
717 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
718 *flags = CIFSSEC_MUST_NTLMV2;
719 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
720 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100721 else if (CIFSSEC_MUST_LANMAN &&
722 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400723 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100724 else if (CIFSSEC_MUST_PLNTXT &&
725 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400726 *flags = CIFSSEC_MUST_PLNTXT;
727
728 *flags |= signflags;
729}
730
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000731static ssize_t cifs_security_flags_proc_write(struct file *file,
732 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Jeff Layton7715dad2013-05-26 07:01:01 -0400734 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000735 unsigned int flags;
736 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300737 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000738
Steve French221601c2007-06-05 20:35:06 +0000739 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000742 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000743
Steve French221601c2007-06-05 20:35:06 +0000744 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000745 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000746
Steve French221601c2007-06-05 20:35:06 +0000747 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000748 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700749 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300750 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000751 return count;
Kees Cook14042972016-03-17 14:22:54 -0700752 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400753 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
754 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000755 return -EINVAL;
756 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Jeff Layton7715dad2013-05-26 07:01:01 -0400759 /* else we have a number */
760 rc = kstrtouint(flags_string, 0, &flags);
761 if (rc) {
762 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
763 flags_string);
764 return rc;
765 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000766
Joe Perchesf96637b2013-05-04 22:12:25 -0500767 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000768
Jeff Layton7715dad2013-05-26 07:01:01 -0400769 if (flags == 0) {
770 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000771 return -EINVAL;
772 }
773
Steve French221601c2007-06-05 20:35:06 +0000774 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400775 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500776 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000777 return -EINVAL;
778 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400779
Jeff Layton52dfb442013-05-26 07:01:02 -0400780 cifs_security_flags_handle_must_flags(&flags);
781
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000782 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400783 global_secflags = flags;
784 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000785 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400786 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500787 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400788 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500789 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000790 }
791 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 return count;
793}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000794
795static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000796 .open = cifs_security_flags_proc_open,
797 .read = seq_read,
798 .llseek = seq_lseek,
799 .release = single_release,
800 .write = cifs_security_flags_proc_write,
801};
Steve French90c81e02008-02-12 20:32:36 +0000802#else
Steve Frenche086fce2008-02-18 04:03:58 +0000803inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000804{
805}
806
Steve Frenche086fce2008-02-18 04:03:58 +0000807inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000808{
809}
810#endif /* PROC_FS */