smb: client: fix potential OOB in cifs_dump_detail()
[platform/kernel/linux-rpi.git] / fs / smb / client / cifs_debug.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *
4  *   Copyright (C) International Business Machines  Corp., 2000,2005
5  *
6  *   Modified by Steve French (sfrench@us.ibm.com)
7  */
8 #include <linux/fs.h>
9 #include <linux/string.h>
10 #include <linux/ctype.h>
11 #include <linux/kstrtox.h>
12 #include <linux/module.h>
13 #include <linux/proc_fs.h>
14 #include <linux/uaccess.h>
15 #include <uapi/linux/ethtool.h>
16 #include "cifspdu.h"
17 #include "cifsglob.h"
18 #include "cifsproto.h"
19 #include "cifs_debug.h"
20 #include "cifsfs.h"
21 #include "fs_context.h"
22 #ifdef CONFIG_CIFS_DFS_UPCALL
23 #include "dfs_cache.h"
24 #endif
25 #ifdef CONFIG_CIFS_SMB_DIRECT
26 #include "smbdirect.h"
27 #endif
28 #include "cifs_swn.h"
29
30 void
31 cifs_dump_mem(char *label, void *data, int length)
32 {
33         pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
34         print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
35                        data, length, true);
36 }
37
38 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
39 {
40 #ifdef CONFIG_CIFS_DEBUG2
41         struct smb_hdr *smb = buf;
42
43         cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n",
44                  smb->Command, smb->Status.CifsError, smb->Flags,
45                  smb->Flags2, smb->Mid, smb->Pid, smb->WordCount);
46         if (!server->ops->check_message(buf, server->total_read, server)) {
47                 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
48                          server->ops->calc_smb_size(smb));
49         }
50 #endif /* CONFIG_CIFS_DEBUG2 */
51 }
52
53 void cifs_dump_mids(struct TCP_Server_Info *server)
54 {
55 #ifdef CONFIG_CIFS_DEBUG2
56         struct mid_q_entry *mid_entry;
57
58         if (server == NULL)
59                 return;
60
61         cifs_dbg(VFS, "Dump pending requests:\n");
62         spin_lock(&server->mid_lock);
63         list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
64                 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
65                          mid_entry->mid_state,
66                          le16_to_cpu(mid_entry->command),
67                          mid_entry->pid,
68                          mid_entry->callback_data,
69                          mid_entry->mid);
70 #ifdef CONFIG_CIFS_STATS2
71                 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
72                          mid_entry->large_buf,
73                          mid_entry->resp_buf,
74                          mid_entry->when_received,
75                          jiffies);
76 #endif /* STATS2 */
77                 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
78                          mid_entry->multiRsp, mid_entry->multiEnd);
79                 if (mid_entry->resp_buf) {
80                         cifs_dump_detail(mid_entry->resp_buf, server);
81                         cifs_dump_mem("existing buf: ",
82                                 mid_entry->resp_buf, 62);
83                 }
84         }
85         spin_unlock(&server->mid_lock);
86 #endif /* CONFIG_CIFS_DEBUG2 */
87 }
88
89 #ifdef CONFIG_PROC_FS
90 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
91 {
92         __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
93
94         seq_printf(m, "%s Mounts: %d ", tcon->tree_name, tcon->tc_count);
95         if (tcon->nativeFileSystem)
96                 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
97         seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
98                    le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
99                    le32_to_cpu(tcon->fsAttrInfo.Attributes),
100                    le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
101                    tcon->status);
102         if (dev_type == FILE_DEVICE_DISK)
103                 seq_puts(m, " type: DISK ");
104         else if (dev_type == FILE_DEVICE_CD_ROM)
105                 seq_puts(m, " type: CDROM ");
106         else
107                 seq_printf(m, " type: %d ", dev_type);
108
109         seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
110
111         if ((tcon->seal) ||
112             (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
113             (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
114                 seq_puts(m, " encrypted");
115         if (tcon->nocase)
116                 seq_printf(m, " nocase");
117         if (tcon->unix_ext)
118                 seq_printf(m, " POSIX Extensions");
119         if (tcon->ses->server->ops->dump_share_caps)
120                 tcon->ses->server->ops->dump_share_caps(m, tcon);
121         if (tcon->use_witness)
122                 seq_puts(m, " Witness");
123         if (tcon->broken_sparse_sup)
124                 seq_puts(m, " nosparse");
125         if (tcon->need_reconnect)
126                 seq_puts(m, "\tDISCONNECTED ");
127         spin_lock(&tcon->tc_lock);
128         if (tcon->origin_fullpath) {
129                 seq_printf(m, "\n\tDFS origin fullpath: %s",
130                            tcon->origin_fullpath);
131         }
132         spin_unlock(&tcon->tc_lock);
133         seq_putc(m, '\n');
134 }
135
136 static void
137 cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
138 {
139         struct TCP_Server_Info *server = chan->server;
140
141         seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
142                    "\n\t\tNumber of credits: %d,%d,%d Dialect 0x%x"
143                    "\n\t\tTCP status: %d Instance: %d"
144                    "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
145                    "\n\t\tIn Send: %d In MaxReq Wait: %d",
146                    i+1, server->conn_id,
147                    server->credits,
148                    server->echo_credits,
149                    server->oplock_credits,
150                    server->dialect,
151                    server->tcpStatus,
152                    server->reconnect_instance,
153                    server->srv_count,
154                    server->sec_mode,
155                    in_flight(server),
156                    atomic_read(&server->in_send),
157                    atomic_read(&server->num_waiters));
158 #ifdef CONFIG_NET_NS
159         if (server->net)
160                 seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
161 #endif /* NET_NS */
162
163 }
164
165 static inline const char *smb_speed_to_str(size_t bps)
166 {
167         size_t mbps = bps / 1000 / 1000;
168
169         switch (mbps) {
170         case SPEED_10:
171                 return "10Mbps";
172         case SPEED_100:
173                 return "100Mbps";
174         case SPEED_1000:
175                 return "1Gbps";
176         case SPEED_2500:
177                 return "2.5Gbps";
178         case SPEED_5000:
179                 return "5Gbps";
180         case SPEED_10000:
181                 return "10Gbps";
182         case SPEED_14000:
183                 return "14Gbps";
184         case SPEED_20000:
185                 return "20Gbps";
186         case SPEED_25000:
187                 return "25Gbps";
188         case SPEED_40000:
189                 return "40Gbps";
190         case SPEED_50000:
191                 return "50Gbps";
192         case SPEED_56000:
193                 return "56Gbps";
194         case SPEED_100000:
195                 return "100Gbps";
196         case SPEED_200000:
197                 return "200Gbps";
198         case SPEED_400000:
199                 return "400Gbps";
200         case SPEED_800000:
201                 return "800Gbps";
202         default:
203                 return "Unknown";
204         }
205 }
206
207 static void
208 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
209 {
210         struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
211         struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
212
213         seq_printf(m, "\tSpeed: %s\n", smb_speed_to_str(iface->speed));
214         seq_puts(m, "\t\tCapabilities: ");
215         if (iface->rdma_capable)
216                 seq_puts(m, "rdma ");
217         if (iface->rss_capable)
218                 seq_puts(m, "rss ");
219         if (!iface->rdma_capable && !iface->rss_capable)
220                 seq_puts(m, "None");
221         seq_putc(m, '\n');
222         if (iface->sockaddr.ss_family == AF_INET)
223                 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
224         else if (iface->sockaddr.ss_family == AF_INET6)
225                 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
226         if (!iface->is_active)
227                 seq_puts(m, "\t\t[for-cleanup]\n");
228 }
229
230 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
231 {
232         struct TCP_Server_Info *server;
233         struct cifs_ses *ses;
234         struct cifs_tcon *tcon;
235         struct cifsFileInfo *cfile;
236
237         seq_puts(m, "# Version:1\n");
238         seq_puts(m, "# Format:\n");
239         seq_puts(m, "# <tree id> <ses id> <persistent fid> <flags> <count> <pid> <uid>");
240 #ifdef CONFIG_CIFS_DEBUG2
241         seq_printf(m, " <filename> <mid>\n");
242 #else
243         seq_printf(m, " <filename>\n");
244 #endif /* CIFS_DEBUG2 */
245         spin_lock(&cifs_tcp_ses_lock);
246         list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
247                 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
248                         list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
249                                 spin_lock(&tcon->open_file_lock);
250                                 list_for_each_entry(cfile, &tcon->openFileList, tlist) {
251                                         seq_printf(m,
252                                                 "0x%x 0x%llx 0x%llx 0x%x %d %d %d %pd",
253                                                 tcon->tid,
254                                                 ses->Suid,
255                                                 cfile->fid.persistent_fid,
256                                                 cfile->f_flags,
257                                                 cfile->count,
258                                                 cfile->pid,
259                                                 from_kuid(&init_user_ns, cfile->uid),
260                                                 cfile->dentry);
261 #ifdef CONFIG_CIFS_DEBUG2
262                                         seq_printf(m, " %llu\n", cfile->fid.mid);
263 #else
264                                         seq_printf(m, "\n");
265 #endif /* CIFS_DEBUG2 */
266                                 }
267                                 spin_unlock(&tcon->open_file_lock);
268                         }
269                 }
270         }
271         spin_unlock(&cifs_tcp_ses_lock);
272         seq_putc(m, '\n');
273         return 0;
274 }
275
276 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
277 {
278         struct mid_q_entry *mid_entry;
279         struct TCP_Server_Info *server;
280         struct TCP_Server_Info *chan_server;
281         struct cifs_ses *ses;
282         struct cifs_tcon *tcon;
283         struct cifs_server_iface *iface;
284         size_t iface_weight = 0, iface_min_speed = 0;
285         struct cifs_server_iface *last_iface = NULL;
286         int c, i, j;
287
288         seq_puts(m,
289                     "Display Internal CIFS Data Structures for Debugging\n"
290                     "---------------------------------------------------\n");
291         seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
292         seq_printf(m, "Features:");
293 #ifdef CONFIG_CIFS_DFS_UPCALL
294         seq_printf(m, " DFS");
295 #endif
296 #ifdef CONFIG_CIFS_FSCACHE
297         seq_printf(m, ",FSCACHE");
298 #endif
299 #ifdef CONFIG_CIFS_SMB_DIRECT
300         seq_printf(m, ",SMB_DIRECT");
301 #endif
302 #ifdef CONFIG_CIFS_STATS2
303         seq_printf(m, ",STATS2");
304 #else
305         seq_printf(m, ",STATS");
306 #endif
307 #ifdef CONFIG_CIFS_DEBUG2
308         seq_printf(m, ",DEBUG2");
309 #elif defined(CONFIG_CIFS_DEBUG)
310         seq_printf(m, ",DEBUG");
311 #endif
312 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
313         seq_printf(m, ",ALLOW_INSECURE_LEGACY");
314 #endif
315 #ifdef CONFIG_CIFS_POSIX
316         seq_printf(m, ",CIFS_POSIX");
317 #endif
318 #ifdef CONFIG_CIFS_UPCALL
319         seq_printf(m, ",UPCALL(SPNEGO)");
320 #endif
321 #ifdef CONFIG_CIFS_XATTR
322         seq_printf(m, ",XATTR");
323 #endif
324         seq_printf(m, ",ACL");
325 #ifdef CONFIG_CIFS_SWN_UPCALL
326         seq_puts(m, ",WITNESS");
327 #endif
328         seq_putc(m, '\n');
329         seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
330         seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
331
332         seq_printf(m, "\nServers: ");
333
334         c = 0;
335         spin_lock(&cifs_tcp_ses_lock);
336         list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
337                 /* channel info will be printed as a part of sessions below */
338                 if (SERVER_IS_CHAN(server))
339                         continue;
340
341                 c++;
342                 seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
343                         c, server->conn_id);
344
345                 spin_lock(&server->srv_lock);
346                 if (server->hostname)
347                         seq_printf(m, "Hostname: %s ", server->hostname);
348                 seq_printf(m, "\nClientGUID: %pUL", server->client_guid);
349                 spin_unlock(&server->srv_lock);
350 #ifdef CONFIG_CIFS_SMB_DIRECT
351                 if (!server->rdma)
352                         goto skip_rdma;
353
354                 if (!server->smbd_conn) {
355                         seq_printf(m, "\nSMBDirect transport not available");
356                         goto skip_rdma;
357                 }
358
359                 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
360                         "transport status: %x",
361                         server->smbd_conn->protocol,
362                         server->smbd_conn->transport_status);
363                 seq_printf(m, "\nConn receive_credit_max: %x "
364                         "send_credit_target: %x max_send_size: %x",
365                         server->smbd_conn->receive_credit_max,
366                         server->smbd_conn->send_credit_target,
367                         server->smbd_conn->max_send_size);
368                 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
369                         "max_fragmented_send_size: %x max_receive_size:%x",
370                         server->smbd_conn->max_fragmented_recv_size,
371                         server->smbd_conn->max_fragmented_send_size,
372                         server->smbd_conn->max_receive_size);
373                 seq_printf(m, "\nConn keep_alive_interval: %x "
374                         "max_readwrite_size: %x rdma_readwrite_threshold: %x",
375                         server->smbd_conn->keep_alive_interval,
376                         server->smbd_conn->max_readwrite_size,
377                         server->smbd_conn->rdma_readwrite_threshold);
378                 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
379                         "count_put_receive_buffer: %x count_send_empty: %x",
380                         server->smbd_conn->count_get_receive_buffer,
381                         server->smbd_conn->count_put_receive_buffer,
382                         server->smbd_conn->count_send_empty);
383                 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
384                         "count_enqueue_reassembly_queue: %x "
385                         "count_dequeue_reassembly_queue: %x "
386                         "fragment_reassembly_remaining: %x "
387                         "reassembly_data_length: %x "
388                         "reassembly_queue_length: %x",
389                         server->smbd_conn->count_reassembly_queue,
390                         server->smbd_conn->count_enqueue_reassembly_queue,
391                         server->smbd_conn->count_dequeue_reassembly_queue,
392                         server->smbd_conn->fragment_reassembly_remaining,
393                         server->smbd_conn->reassembly_data_length,
394                         server->smbd_conn->reassembly_queue_length);
395                 seq_printf(m, "\nCurrent Credits send_credits: %x "
396                         "receive_credits: %x receive_credit_target: %x",
397                         atomic_read(&server->smbd_conn->send_credits),
398                         atomic_read(&server->smbd_conn->receive_credits),
399                         server->smbd_conn->receive_credit_target);
400                 seq_printf(m, "\nPending send_pending: %x ",
401                         atomic_read(&server->smbd_conn->send_pending));
402                 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
403                         "count_empty_packet_queue: %x",
404                         server->smbd_conn->count_receive_queue,
405                         server->smbd_conn->count_empty_packet_queue);
406                 seq_printf(m, "\nMR responder_resources: %x "
407                         "max_frmr_depth: %x mr_type: %x",
408                         server->smbd_conn->responder_resources,
409                         server->smbd_conn->max_frmr_depth,
410                         server->smbd_conn->mr_type);
411                 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
412                         atomic_read(&server->smbd_conn->mr_ready_count),
413                         atomic_read(&server->smbd_conn->mr_used_count));
414 skip_rdma:
415 #endif
416                 seq_printf(m, "\nNumber of credits: %d,%d,%d Dialect 0x%x",
417                         server->credits,
418                         server->echo_credits,
419                         server->oplock_credits,
420                         server->dialect);
421                 if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
422                         seq_printf(m, " COMPRESS_LZNT1");
423                 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
424                         seq_printf(m, " COMPRESS_LZ77");
425                 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
426                         seq_printf(m, " COMPRESS_LZ77_HUFF");
427                 if (server->sign)
428                         seq_printf(m, " signed");
429                 if (server->posix_ext_supported)
430                         seq_printf(m, " posix");
431                 if (server->nosharesock)
432                         seq_printf(m, " nosharesock");
433
434                 if (server->rdma)
435                         seq_printf(m, "\nRDMA ");
436                 seq_printf(m, "\nTCP status: %d Instance: %d"
437                                 "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
438                                 server->tcpStatus,
439                                 server->reconnect_instance,
440                                 server->srv_count,
441                                 server->sec_mode, in_flight(server));
442 #ifdef CONFIG_NET_NS
443                 if (server->net)
444                         seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
445 #endif /* NET_NS */
446
447                 seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
448                                 atomic_read(&server->in_send),
449                                 atomic_read(&server->num_waiters));
450
451                 if (server->leaf_fullpath) {
452                         seq_printf(m, "\nDFS leaf full path: %s",
453                                    server->leaf_fullpath);
454                 }
455
456                 seq_printf(m, "\n\n\tSessions: ");
457                 i = 0;
458                 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
459                         spin_lock(&ses->ses_lock);
460                         if (ses->ses_status == SES_EXITING) {
461                                 spin_unlock(&ses->ses_lock);
462                                 continue;
463                         }
464                         i++;
465                         if ((ses->serverDomain == NULL) ||
466                                 (ses->serverOS == NULL) ||
467                                 (ses->serverNOS == NULL)) {
468                                 seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
469                                         i, ses->ip_addr, ses->ses_count,
470                                         ses->capabilities, ses->ses_status);
471                                 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
472                                         seq_printf(m, "Guest ");
473                                 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
474                                         seq_printf(m, "Anonymous ");
475                         } else {
476                                 seq_printf(m,
477                                     "\n\t%d) Name: %s  Domain: %s Uses: %d OS: %s "
478                                     "\n\tNOS: %s\tCapability: 0x%x"
479                                         "\n\tSMB session status: %d ",
480                                 i, ses->ip_addr, ses->serverDomain,
481                                 ses->ses_count, ses->serverOS, ses->serverNOS,
482                                 ses->capabilities, ses->ses_status);
483                         }
484                         spin_unlock(&ses->ses_lock);
485
486                         seq_printf(m, "\n\tSecurity type: %s ",
487                                 get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
488
489                         /* dump session id helpful for use with network trace */
490                         seq_printf(m, " SessionId: 0x%llx", ses->Suid);
491                         if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) {
492                                 seq_puts(m, " encrypted");
493                                 /* can help in debugging to show encryption type */
494                                 if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
495                                         seq_puts(m, "(gcm256)");
496                         }
497                         if (ses->sign)
498                                 seq_puts(m, " signed");
499
500                         seq_printf(m, "\n\tUser: %d Cred User: %d",
501                                    from_kuid(&init_user_ns, ses->linux_uid),
502                                    from_kuid(&init_user_ns, ses->cred_uid));
503
504                         if (ses->dfs_root_ses) {
505                                 seq_printf(m, "\n\tDFS root session id: 0x%llx",
506                                            ses->dfs_root_ses->Suid);
507                         }
508
509                         spin_lock(&ses->chan_lock);
510                         if (CIFS_CHAN_NEEDS_RECONNECT(ses, 0))
511                                 seq_puts(m, "\tPrimary channel: DISCONNECTED ");
512                         if (CIFS_CHAN_IN_RECONNECT(ses, 0))
513                                 seq_puts(m, "\t[RECONNECTING] ");
514
515                         if (ses->chan_count > 1) {
516                                 seq_printf(m, "\n\n\tExtra Channels: %zu ",
517                                            ses->chan_count-1);
518                                 for (j = 1; j < ses->chan_count; j++) {
519                                         cifs_dump_channel(m, j, &ses->chans[j]);
520                                         if (CIFS_CHAN_NEEDS_RECONNECT(ses, j))
521                                                 seq_puts(m, "\tDISCONNECTED ");
522                                         if (CIFS_CHAN_IN_RECONNECT(ses, j))
523                                                 seq_puts(m, "\t[RECONNECTING] ");
524                                 }
525                         }
526                         spin_unlock(&ses->chan_lock);
527
528                         seq_puts(m, "\n\n\tShares: ");
529                         j = 0;
530
531                         seq_printf(m, "\n\t%d) IPC: ", j);
532                         if (ses->tcon_ipc)
533                                 cifs_debug_tcon(m, ses->tcon_ipc);
534                         else
535                                 seq_puts(m, "none\n");
536
537                         list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
538                                 ++j;
539                                 seq_printf(m, "\n\t%d) ", j);
540                                 cifs_debug_tcon(m, tcon);
541                         }
542
543                         spin_lock(&ses->iface_lock);
544                         if (ses->iface_count)
545                                 seq_printf(m, "\n\n\tServer interfaces: %zu"
546                                            "\tLast updated: %lu seconds ago",
547                                            ses->iface_count,
548                                            (jiffies - ses->iface_last_update) / HZ);
549
550                         last_iface = list_last_entry(&ses->iface_list,
551                                                      struct cifs_server_iface,
552                                                      iface_head);
553                         iface_min_speed = last_iface->speed;
554
555                         j = 0;
556                         list_for_each_entry(iface, &ses->iface_list,
557                                                  iface_head) {
558                                 seq_printf(m, "\n\t%d)", ++j);
559                                 cifs_dump_iface(m, iface);
560
561                                 iface_weight = iface->speed / iface_min_speed;
562                                 seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)"
563                                            "\n\t\tAllocated channels: %u\n",
564                                            iface->weight_fulfilled,
565                                            iface_weight,
566                                            iface->num_channels);
567
568                                 if (is_ses_using_iface(ses, iface))
569                                         seq_puts(m, "\t\t[CONNECTED]\n");
570                         }
571                         spin_unlock(&ses->iface_lock);
572
573                         seq_puts(m, "\n\n\tMIDs: ");
574                         spin_lock(&ses->chan_lock);
575                         for (j = 0; j < ses->chan_count; j++) {
576                                 chan_server = ses->chans[j].server;
577                                 if (!chan_server)
578                                         continue;
579
580                                 if (list_empty(&chan_server->pending_mid_q))
581                                         continue;
582
583                                 seq_printf(m, "\n\tServer ConnectionId: 0x%llx",
584                                            chan_server->conn_id);
585                                 spin_lock(&chan_server->mid_lock);
586                                 list_for_each_entry(mid_entry, &chan_server->pending_mid_q, qhead) {
587                                         seq_printf(m, "\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu",
588                                                    mid_entry->mid_state,
589                                                    le16_to_cpu(mid_entry->command),
590                                                    mid_entry->pid,
591                                                    mid_entry->callback_data,
592                                                    mid_entry->mid);
593                                 }
594                                 spin_unlock(&chan_server->mid_lock);
595                         }
596                         spin_unlock(&ses->chan_lock);
597                         seq_puts(m, "\n--\n");
598                 }
599                 if (i == 0)
600                         seq_printf(m, "\n\t\t[NONE]");
601         }
602         if (c == 0)
603                 seq_printf(m, "\n\t[NONE]");
604
605         spin_unlock(&cifs_tcp_ses_lock);
606         seq_putc(m, '\n');
607         cifs_swn_dump(m);
608
609         /* BB add code to dump additional info such as TCP session info now */
610         return 0;
611 }
612
613 static ssize_t cifs_stats_proc_write(struct file *file,
614                 const char __user *buffer, size_t count, loff_t *ppos)
615 {
616         bool bv;
617         int rc;
618         struct TCP_Server_Info *server;
619         struct cifs_ses *ses;
620         struct cifs_tcon *tcon;
621
622         rc = kstrtobool_from_user(buffer, count, &bv);
623         if (rc == 0) {
624 #ifdef CONFIG_CIFS_STATS2
625                 int i;
626
627                 atomic_set(&total_buf_alloc_count, 0);
628                 atomic_set(&total_small_buf_alloc_count, 0);
629 #endif /* CONFIG_CIFS_STATS2 */
630                 atomic_set(&tcpSesReconnectCount, 0);
631                 atomic_set(&tconInfoReconnectCount, 0);
632
633                 spin_lock(&GlobalMid_Lock);
634                 GlobalMaxActiveXid = 0;
635                 GlobalCurrentXid = 0;
636                 spin_unlock(&GlobalMid_Lock);
637                 spin_lock(&cifs_tcp_ses_lock);
638                 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
639                         server->max_in_flight = 0;
640 #ifdef CONFIG_CIFS_STATS2
641                         for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
642                                 atomic_set(&server->num_cmds[i], 0);
643                                 atomic_set(&server->smb2slowcmd[i], 0);
644                                 server->time_per_cmd[i] = 0;
645                                 server->slowest_cmd[i] = 0;
646                                 server->fastest_cmd[0] = 0;
647                         }
648 #endif /* CONFIG_CIFS_STATS2 */
649                         list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
650                                 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
651                                         atomic_set(&tcon->num_smbs_sent, 0);
652                                         spin_lock(&tcon->stat_lock);
653                                         tcon->bytes_read = 0;
654                                         tcon->bytes_written = 0;
655                                         spin_unlock(&tcon->stat_lock);
656                                         if (server->ops->clear_stats)
657                                                 server->ops->clear_stats(tcon);
658                                 }
659                         }
660                 }
661                 spin_unlock(&cifs_tcp_ses_lock);
662         } else {
663                 return rc;
664         }
665
666         return count;
667 }
668
669 static int cifs_stats_proc_show(struct seq_file *m, void *v)
670 {
671         int i;
672 #ifdef CONFIG_CIFS_STATS2
673         int j;
674 #endif /* STATS2 */
675         struct TCP_Server_Info *server;
676         struct cifs_ses *ses;
677         struct cifs_tcon *tcon;
678
679         seq_printf(m, "Resources in use\nCIFS Session: %d\n",
680                         sesInfoAllocCount.counter);
681         seq_printf(m, "Share (unique mount targets): %d\n",
682                         tconInfoAllocCount.counter);
683         seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
684                         buf_alloc_count.counter,
685                         cifs_min_rcv + tcpSesAllocCount.counter);
686         seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
687                         small_buf_alloc_count.counter, cifs_min_small);
688 #ifdef CONFIG_CIFS_STATS2
689         seq_printf(m, "Total Large %d Small %d Allocations\n",
690                                 atomic_read(&total_buf_alloc_count),
691                                 atomic_read(&total_small_buf_alloc_count));
692 #endif /* CONFIG_CIFS_STATS2 */
693
694         seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
695         seq_printf(m,
696                 "\n%d session %d share reconnects\n",
697                 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
698
699         seq_printf(m,
700                 "Total vfs operations: %d maximum at one time: %d\n",
701                 GlobalCurrentXid, GlobalMaxActiveXid);
702
703         i = 0;
704         spin_lock(&cifs_tcp_ses_lock);
705         list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
706                 seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
707 #ifdef CONFIG_CIFS_STATS2
708                 seq_puts(m, "\nTotal time spent processing by command. Time ");
709                 seq_printf(m, "units are jiffies (%d per second)\n", HZ);
710                 seq_puts(m, "  SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
711                 seq_puts(m, "  --------\t------\t----------\t-------\t-------\n");
712                 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
713                         seq_printf(m, "  %d\t\t%d\t%llu\t\t%u\t%u\n", j,
714                                 atomic_read(&server->num_cmds[j]),
715                                 server->time_per_cmd[j],
716                                 server->fastest_cmd[j],
717                                 server->slowest_cmd[j]);
718                 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
719                         if (atomic_read(&server->smb2slowcmd[j])) {
720                                 spin_lock(&server->srv_lock);
721                                 seq_printf(m, "  %d slow responses from %s for command %d\n",
722                                         atomic_read(&server->smb2slowcmd[j]),
723                                         server->hostname, j);
724                                 spin_unlock(&server->srv_lock);
725                         }
726 #endif /* STATS2 */
727                 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
728                         list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
729                                 i++;
730                                 seq_printf(m, "\n%d) %s", i, tcon->tree_name);
731                                 if (tcon->need_reconnect)
732                                         seq_puts(m, "\tDISCONNECTED ");
733                                 seq_printf(m, "\nSMBs: %d",
734                                            atomic_read(&tcon->num_smbs_sent));
735                                 if (server->ops->print_stats)
736                                         server->ops->print_stats(m, tcon);
737                         }
738                 }
739         }
740         spin_unlock(&cifs_tcp_ses_lock);
741
742         seq_putc(m, '\n');
743         return 0;
744 }
745
746 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
747 {
748         return single_open(file, cifs_stats_proc_show, NULL);
749 }
750
751 static const struct proc_ops cifs_stats_proc_ops = {
752         .proc_open      = cifs_stats_proc_open,
753         .proc_read      = seq_read,
754         .proc_lseek     = seq_lseek,
755         .proc_release   = single_release,
756         .proc_write     = cifs_stats_proc_write,
757 };
758
759 #ifdef CONFIG_CIFS_SMB_DIRECT
760 #define PROC_FILE_DEFINE(name) \
761 static ssize_t name##_write(struct file *file, const char __user *buffer, \
762         size_t count, loff_t *ppos) \
763 { \
764         int rc; \
765         rc = kstrtoint_from_user(buffer, count, 10, & name); \
766         if (rc) \
767                 return rc; \
768         return count; \
769 } \
770 static int name##_proc_show(struct seq_file *m, void *v) \
771 { \
772         seq_printf(m, "%d\n", name ); \
773         return 0; \
774 } \
775 static int name##_open(struct inode *inode, struct file *file) \
776 { \
777         return single_open(file, name##_proc_show, NULL); \
778 } \
779 \
780 static const struct proc_ops cifs_##name##_proc_fops = { \
781         .proc_open      = name##_open, \
782         .proc_read      = seq_read, \
783         .proc_lseek     = seq_lseek, \
784         .proc_release   = single_release, \
785         .proc_write     = name##_write, \
786 }
787
788 PROC_FILE_DEFINE(rdma_readwrite_threshold);
789 PROC_FILE_DEFINE(smbd_max_frmr_depth);
790 PROC_FILE_DEFINE(smbd_keep_alive_interval);
791 PROC_FILE_DEFINE(smbd_max_receive_size);
792 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
793 PROC_FILE_DEFINE(smbd_max_send_size);
794 PROC_FILE_DEFINE(smbd_send_credit_target);
795 PROC_FILE_DEFINE(smbd_receive_credit_max);
796 #endif
797
798 static struct proc_dir_entry *proc_fs_cifs;
799 static const struct proc_ops cifsFYI_proc_ops;
800 static const struct proc_ops cifs_lookup_cache_proc_ops;
801 static const struct proc_ops traceSMB_proc_ops;
802 static const struct proc_ops cifs_security_flags_proc_ops;
803 static const struct proc_ops cifs_linux_ext_proc_ops;
804 static const struct proc_ops cifs_mount_params_proc_ops;
805
806 void
807 cifs_proc_init(void)
808 {
809         proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
810         if (proc_fs_cifs == NULL)
811                 return;
812
813         proc_create_single("DebugData", 0, proc_fs_cifs,
814                         cifs_debug_data_proc_show);
815
816         proc_create_single("open_files", 0400, proc_fs_cifs,
817                         cifs_debug_files_proc_show);
818
819         proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
820         proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
821         proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
822         proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
823                     &cifs_linux_ext_proc_ops);
824         proc_create("SecurityFlags", 0644, proc_fs_cifs,
825                     &cifs_security_flags_proc_ops);
826         proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
827                     &cifs_lookup_cache_proc_ops);
828
829         proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
830
831 #ifdef CONFIG_CIFS_DFS_UPCALL
832         proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
833 #endif
834
835 #ifdef CONFIG_CIFS_SMB_DIRECT
836         proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
837                 &cifs_rdma_readwrite_threshold_proc_fops);
838         proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
839                 &cifs_smbd_max_frmr_depth_proc_fops);
840         proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
841                 &cifs_smbd_keep_alive_interval_proc_fops);
842         proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
843                 &cifs_smbd_max_receive_size_proc_fops);
844         proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
845                 &cifs_smbd_max_fragmented_recv_size_proc_fops);
846         proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
847                 &cifs_smbd_max_send_size_proc_fops);
848         proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
849                 &cifs_smbd_send_credit_target_proc_fops);
850         proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
851                 &cifs_smbd_receive_credit_max_proc_fops);
852 #endif
853 }
854
855 void
856 cifs_proc_clean(void)
857 {
858         if (proc_fs_cifs == NULL)
859                 return;
860
861         remove_proc_entry("DebugData", proc_fs_cifs);
862         remove_proc_entry("open_files", proc_fs_cifs);
863         remove_proc_entry("cifsFYI", proc_fs_cifs);
864         remove_proc_entry("traceSMB", proc_fs_cifs);
865         remove_proc_entry("Stats", proc_fs_cifs);
866         remove_proc_entry("SecurityFlags", proc_fs_cifs);
867         remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
868         remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
869         remove_proc_entry("mount_params", proc_fs_cifs);
870
871 #ifdef CONFIG_CIFS_DFS_UPCALL
872         remove_proc_entry("dfscache", proc_fs_cifs);
873 #endif
874 #ifdef CONFIG_CIFS_SMB_DIRECT
875         remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
876         remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
877         remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
878         remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
879         remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
880         remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
881         remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
882         remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
883 #endif
884         remove_proc_entry("fs/cifs", NULL);
885 }
886
887 static int cifsFYI_proc_show(struct seq_file *m, void *v)
888 {
889         seq_printf(m, "%d\n", cifsFYI);
890         return 0;
891 }
892
893 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
894 {
895         return single_open(file, cifsFYI_proc_show, NULL);
896 }
897
898 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
899                 size_t count, loff_t *ppos)
900 {
901         char c[2] = { '\0' };
902         bool bv;
903         int rc;
904
905         rc = get_user(c[0], buffer);
906         if (rc)
907                 return rc;
908         if (kstrtobool(c, &bv) == 0)
909                 cifsFYI = bv;
910         else if ((c[0] > '1') && (c[0] <= '9'))
911                 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
912         else
913                 return -EINVAL;
914
915         return count;
916 }
917
918 static const struct proc_ops cifsFYI_proc_ops = {
919         .proc_open      = cifsFYI_proc_open,
920         .proc_read      = seq_read,
921         .proc_lseek     = seq_lseek,
922         .proc_release   = single_release,
923         .proc_write     = cifsFYI_proc_write,
924 };
925
926 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
927 {
928         seq_printf(m, "%d\n", linuxExtEnabled);
929         return 0;
930 }
931
932 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
933 {
934         return single_open(file, cifs_linux_ext_proc_show, NULL);
935 }
936
937 static ssize_t cifs_linux_ext_proc_write(struct file *file,
938                 const char __user *buffer, size_t count, loff_t *ppos)
939 {
940         int rc;
941
942         rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
943         if (rc)
944                 return rc;
945
946         return count;
947 }
948
949 static const struct proc_ops cifs_linux_ext_proc_ops = {
950         .proc_open      = cifs_linux_ext_proc_open,
951         .proc_read      = seq_read,
952         .proc_lseek     = seq_lseek,
953         .proc_release   = single_release,
954         .proc_write     = cifs_linux_ext_proc_write,
955 };
956
957 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
958 {
959         seq_printf(m, "%d\n", lookupCacheEnabled);
960         return 0;
961 }
962
963 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
964 {
965         return single_open(file, cifs_lookup_cache_proc_show, NULL);
966 }
967
968 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
969                 const char __user *buffer, size_t count, loff_t *ppos)
970 {
971         int rc;
972
973         rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
974         if (rc)
975                 return rc;
976
977         return count;
978 }
979
980 static const struct proc_ops cifs_lookup_cache_proc_ops = {
981         .proc_open      = cifs_lookup_cache_proc_open,
982         .proc_read      = seq_read,
983         .proc_lseek     = seq_lseek,
984         .proc_release   = single_release,
985         .proc_write     = cifs_lookup_cache_proc_write,
986 };
987
988 static int traceSMB_proc_show(struct seq_file *m, void *v)
989 {
990         seq_printf(m, "%d\n", traceSMB);
991         return 0;
992 }
993
994 static int traceSMB_proc_open(struct inode *inode, struct file *file)
995 {
996         return single_open(file, traceSMB_proc_show, NULL);
997 }
998
999 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
1000                 size_t count, loff_t *ppos)
1001 {
1002         int rc;
1003
1004         rc = kstrtobool_from_user(buffer, count, &traceSMB);
1005         if (rc)
1006                 return rc;
1007
1008         return count;
1009 }
1010
1011 static const struct proc_ops traceSMB_proc_ops = {
1012         .proc_open      = traceSMB_proc_open,
1013         .proc_read      = seq_read,
1014         .proc_lseek     = seq_lseek,
1015         .proc_release   = single_release,
1016         .proc_write     = traceSMB_proc_write,
1017 };
1018
1019 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
1020 {
1021         seq_printf(m, "0x%x\n", global_secflags);
1022         return 0;
1023 }
1024
1025 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
1026 {
1027         return single_open(file, cifs_security_flags_proc_show, NULL);
1028 }
1029
1030 /*
1031  * Ensure that if someone sets a MUST flag, that we disable all other MAY
1032  * flags except for the ones corresponding to the given MUST flag. If there are
1033  * multiple MUST flags, then try to prefer more secure ones.
1034  */
1035 static void
1036 cifs_security_flags_handle_must_flags(unsigned int *flags)
1037 {
1038         unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
1039
1040         if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
1041                 *flags = CIFSSEC_MUST_KRB5;
1042         else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
1043                 *flags = CIFSSEC_MUST_NTLMSSP;
1044         else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
1045                 *flags = CIFSSEC_MUST_NTLMV2;
1046
1047         *flags |= signflags;
1048 }
1049
1050 static ssize_t cifs_security_flags_proc_write(struct file *file,
1051                 const char __user *buffer, size_t count, loff_t *ppos)
1052 {
1053         int rc;
1054         unsigned int flags;
1055         char flags_string[12];
1056         bool bv;
1057
1058         if ((count < 1) || (count > 11))
1059                 return -EINVAL;
1060
1061         memset(flags_string, 0, 12);
1062
1063         if (copy_from_user(flags_string, buffer, count))
1064                 return -EFAULT;
1065
1066         if (count < 3) {
1067                 /* single char or single char followed by null */
1068                 if (kstrtobool(flags_string, &bv) == 0) {
1069                         global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
1070                         return count;
1071                 } else if (!isdigit(flags_string[0])) {
1072                         cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
1073                                         flags_string);
1074                         return -EINVAL;
1075                 }
1076         }
1077
1078         /* else we have a number */
1079         rc = kstrtouint(flags_string, 0, &flags);
1080         if (rc) {
1081                 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
1082                                 flags_string);
1083                 return rc;
1084         }
1085
1086         cifs_dbg(FYI, "sec flags 0x%x\n", flags);
1087
1088         if (flags == 0)  {
1089                 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
1090                 return -EINVAL;
1091         }
1092
1093         if (flags & ~CIFSSEC_MASK) {
1094                 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
1095                          flags & ~CIFSSEC_MASK);
1096                 return -EINVAL;
1097         }
1098
1099         cifs_security_flags_handle_must_flags(&flags);
1100
1101         /* flags look ok - update the global security flags for cifs module */
1102         global_secflags = flags;
1103         if (global_secflags & CIFSSEC_MUST_SIGN) {
1104                 /* requiring signing implies signing is allowed */
1105                 global_secflags |= CIFSSEC_MAY_SIGN;
1106                 cifs_dbg(FYI, "packet signing now required\n");
1107         } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
1108                 cifs_dbg(FYI, "packet signing disabled\n");
1109         }
1110         /* BB should we turn on MAY flags for other MUST options? */
1111         return count;
1112 }
1113
1114 static const struct proc_ops cifs_security_flags_proc_ops = {
1115         .proc_open      = cifs_security_flags_proc_open,
1116         .proc_read      = seq_read,
1117         .proc_lseek     = seq_lseek,
1118         .proc_release   = single_release,
1119         .proc_write     = cifs_security_flags_proc_write,
1120 };
1121
1122 /* To make it easier to debug, can help to show mount params */
1123 static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
1124 {
1125         const struct fs_parameter_spec *p;
1126         const char *type;
1127
1128         for (p = smb3_fs_parameters; p->name; p++) {
1129                 /* cannot use switch with pointers... */
1130                 if (!p->type) {
1131                         if (p->flags == fs_param_neg_with_no)
1132                                 type = "noflag";
1133                         else
1134                                 type = "flag";
1135                 } else if (p->type == fs_param_is_bool)
1136                         type = "bool";
1137                 else if (p->type == fs_param_is_u32)
1138                         type = "u32";
1139                 else if (p->type == fs_param_is_u64)
1140                         type = "u64";
1141                 else if (p->type == fs_param_is_string)
1142                         type = "string";
1143                 else
1144                         type = "unknown";
1145
1146                 seq_printf(m, "%s:%s\n", p->name, type);
1147         }
1148
1149         return 0;
1150 }
1151
1152 static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
1153 {
1154         return single_open(file, cifs_mount_params_proc_show, NULL);
1155 }
1156
1157 static const struct proc_ops cifs_mount_params_proc_ops = {
1158         .proc_open      = cifs_mount_params_proc_open,
1159         .proc_read      = seq_read,
1160         .proc_lseek     = seq_lseek,
1161         .proc_release   = single_release,
1162         /* No need for write for now */
1163         /* .proc_write  = cifs_mount_params_proc_write, */
1164 };
1165
1166 #else
1167 inline void cifs_proc_init(void)
1168 {
1169 }
1170
1171 inline void cifs_proc_clean(void)
1172 {
1173 }
1174 #endif /* PROC_FS */