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