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