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