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