1ab6cacf8SSteve French.. SPDX-License-Identifier: GPL-2.0 2ab6cacf8SSteve French 3ab6cacf8SSteve French========================== 4ab6cacf8SSteve FrenchKSMBD - SMB3 Kernel Server 5ab6cacf8SSteve French========================== 6ab6cacf8SSteve French 7ab6cacf8SSteve FrenchKSMBD is a linux kernel server which implements SMB3 protocol in kernel space 8ab6cacf8SSteve Frenchfor sharing files over network. 9ab6cacf8SSteve French 10ab6cacf8SSteve FrenchKSMBD architecture 11ab6cacf8SSteve French================== 12ab6cacf8SSteve French 13ab6cacf8SSteve FrenchThe subset of performance related operations belong in kernelspace and 14ab6cacf8SSteve Frenchthe other subset which belong to operations which are not really related with 15ab6cacf8SSteve Frenchperformance in userspace. So, DCE/RPC management that has historically resulted 16*4fdd8664SVictor Timofeiinto a number of buffer overflow issues and dangerous security bugs and user 17ab6cacf8SSteve Frenchaccount management are implemented in user space as ksmbd.mountd. 18ab6cacf8SSteve FrenchFile operations that are related with performance (open/read/write/close etc.) 19ab6cacf8SSteve Frenchin kernel space (ksmbd). This also allows for easier integration with VFS 20ab6cacf8SSteve Frenchinterface for all file operations. 21ab6cacf8SSteve French 22ab6cacf8SSteve Frenchksmbd (kernel daemon) 23ab6cacf8SSteve French--------------------- 24ab6cacf8SSteve French 25ab6cacf8SSteve FrenchWhen the server daemon is started, It starts up a forker thread 26ab6cacf8SSteve French(ksmbd/interface name) at initialization time and open a dedicated port 445 27*4fdd8664SVictor Timofeifor listening to SMB requests. Whenever new clients make a request, the Forker 28*4fdd8664SVictor Timofeithread will accept the client connection and fork a new thread for a dedicated 29ab6cacf8SSteve Frenchcommunication channel between the client and the server. It allows for parallel 30ab6cacf8SSteve Frenchprocessing of SMB requests(commands) from clients as well as allowing for new 31ab6cacf8SSteve Frenchclients to make new connections. Each instance is named ksmbd/1~n(port number) 32ab6cacf8SSteve Frenchto indicate connected clients. Depending on the SMB request types, each new 33ab6cacf8SSteve Frenchthread can decide to pass through the commands to the user space (ksmbd.mountd), 34ab6cacf8SSteve Frenchcurrently DCE/RPC commands are identified to be handled through the user space. 35ab6cacf8SSteve FrenchTo further utilize the linux kernel, it has been chosen to process the commands 36ab6cacf8SSteve Frenchas workitems and to be executed in the handlers of the ksmbd-io kworker threads. 37*4fdd8664SVictor TimofeiIt allows for multiplexing of the handlers as the kernel takes care of initiating 38ab6cacf8SSteve Frenchextra worker threads if the load is increased and vice versa, if the load is 39*4fdd8664SVictor Timofeidecreased it destroys the extra worker threads. So, after the connection is 40*4fdd8664SVictor Timofeiestablished with the client. Dedicated ksmbd/1..n(port number) takes complete 41ab6cacf8SSteve Frenchownership of receiving/parsing of SMB commands. Each received command is worked 42*4fdd8664SVictor Timofeiin parallel i.e., there can be multiple client commands which are worked in 43ab6cacf8SSteve Frenchparallel. After receiving each command a separated kernel workitem is prepared 44ab6cacf8SSteve Frenchfor each command which is further queued to be handled by ksmbd-io kworkers. 45ab6cacf8SSteve FrenchSo, each SMB workitem is queued to the kworkers. This allows the benefit of load 46ab6cacf8SSteve Frenchsharing to be managed optimally by the default kernel and optimizing client 47ab6cacf8SSteve Frenchperformance by handling client commands in parallel. 48ab6cacf8SSteve French 49ab6cacf8SSteve Frenchksmbd.mountd (user space daemon) 50ab6cacf8SSteve French-------------------------------- 51ab6cacf8SSteve French 52*4fdd8664SVictor Timofeiksmbd.mountd is a userspace process to, transfer the user account and password that 53ab6cacf8SSteve Frenchare registered using ksmbd.adduser (part of utils for user space). Further it 54*4fdd8664SVictor Timofeiallows sharing information parameters that are parsed from smb.conf to ksmbd in 55ab6cacf8SSteve Frenchkernel. For the execution part it has a daemon which is continuously running 56ab6cacf8SSteve Frenchand connected to the kernel interface using netlink socket, it waits for the 57ab6cacf8SSteve Frenchrequests (dcerpc and share/user info). It handles RPC calls (at a minimum few 58ab6cacf8SSteve Frenchdozen) that are most important for file server from NetShareEnum and 59ab6cacf8SSteve FrenchNetServerGetInfo. Complete DCE/RPC response is prepared from the user space 60ab6cacf8SSteve Frenchand passed over to the associated kernel thread for the client. 61ab6cacf8SSteve French 62ab6cacf8SSteve French 63ab6cacf8SSteve FrenchKSMBD Feature Status 64ab6cacf8SSteve French==================== 65ab6cacf8SSteve French 66ab6cacf8SSteve French============================== ================================================= 67ab6cacf8SSteve FrenchFeature name Status 68ab6cacf8SSteve French============================== ================================================= 69ab6cacf8SSteve FrenchDialects Supported. SMB2.1 SMB3.0, SMB3.1.1 dialects 70ab6cacf8SSteve French (intentionally excludes security vulnerable SMB1 71ab6cacf8SSteve French dialect). 72ab6cacf8SSteve FrenchAuto Negotiation Supported. 73ab6cacf8SSteve FrenchCompound Request Supported. 74ab6cacf8SSteve FrenchOplock Cache Mechanism Supported. 75ab6cacf8SSteve FrenchSMB2 leases(v1 lease) Supported. 76fdfd6ddeSNamjae JeonDirectory leases(v2 lease) Supported. 77ab6cacf8SSteve FrenchMulti-credits Supported. 78ab6cacf8SSteve FrenchNTLM/NTLMv2 Supported. 79ab6cacf8SSteve FrenchHMAC-SHA256 Signing Supported. 80ab6cacf8SSteve FrenchSecure negotiate Supported. 81ab6cacf8SSteve FrenchSigning Update Supported. 82ab6cacf8SSteve FrenchPre-authentication integrity Supported. 83fdfd6ddeSNamjae JeonSMB3 encryption(CCM, GCM) Supported. (CCM/GCM128 and CCM/GCM256 supported) 84ab6cacf8SSteve FrenchSMB direct(RDMA) Supported. 85ab6cacf8SSteve FrenchSMB3 Multi-channel Partially Supported. Planned to implement 86ab6cacf8SSteve French replay/retry mechanisms for future. 87ab6cacf8SSteve FrenchReceive Side Scaling mode Supported. 88ab6cacf8SSteve FrenchSMB3.1.1 POSIX extension Supported. 89ab6cacf8SSteve FrenchACLs Partially Supported. only DACLs available, SACLs 90ab6cacf8SSteve French (auditing) is planned for the future. For 91ab6cacf8SSteve French ownership (SIDs) ksmbd generates random subauth 92ab6cacf8SSteve French values(then store it to disk) and use uid/gid 93ab6cacf8SSteve French get from inode as RID for local domain SID. 94ab6cacf8SSteve French The current acl implementation is limited to 95ab6cacf8SSteve French standalone server, not a domain member. 96ab6cacf8SSteve French Integration with Samba tools is being worked on 97ab6cacf8SSteve French to allow future support for running as a domain 98ab6cacf8SSteve French member. 99ab6cacf8SSteve FrenchKerberos Supported. 100ab6cacf8SSteve FrenchDurable handle v1,v2 Planned for future. 101ab6cacf8SSteve FrenchPersistent handle Planned for future. 102ab6cacf8SSteve FrenchSMB2 notify Planned for future. 103ab6cacf8SSteve FrenchSparse file support Supported. 104ab6cacf8SSteve FrenchDCE/RPC support Partially Supported. a few calls(NetShareEnumAll, 105ab6cacf8SSteve French NetServerGetInfo, SAMR, LSARPC) that are needed 106ab6cacf8SSteve French for file server handled via netlink interface 107ab6cacf8SSteve French from ksmbd.mountd. Additional integration with 108ab6cacf8SSteve French Samba tools and libraries via upcall is being 109ab6cacf8SSteve French investigated to allow support for additional 110ab6cacf8SSteve French DCE/RPC management calls (and future support 111ab6cacf8SSteve French for Witness protocol e.g.) 112ab6cacf8SSteve Frenchksmbd/nfsd interoperability Planned for future. The features that ksmbd 113ab6cacf8SSteve French support are Leases, Notify, ACLs and Share modes. 114fdfd6ddeSNamjae JeonSMB3.1.1 Compression Planned for future. 115fdfd6ddeSNamjae JeonSMB3.1.1 over QUIC Planned for future. 116fdfd6ddeSNamjae JeonSigning/Encryption over RDMA Planned for future. 117fdfd6ddeSNamjae JeonSMB3.1.1 GMAC signing support Planned for future. 118ab6cacf8SSteve French============================== ================================================= 119ab6cacf8SSteve French 120ab6cacf8SSteve French 121ab6cacf8SSteve FrenchHow to run 122ab6cacf8SSteve French========== 123ab6cacf8SSteve French 124ab6cacf8SSteve French1. Download ksmbd-tools(https://github.com/cifsd-team/ksmbd-tools/releases) and 125ab6cacf8SSteve French compile them. 126ab6cacf8SSteve French 127*4fdd8664SVictor Timofei - Refer to README(https://github.com/cifsd-team/ksmbd-tools/blob/master/README.md) 128ab6cacf8SSteve French to know how to use ksmbd.mountd/adduser/addshare/control utils 129ab6cacf8SSteve French 130ab6cacf8SSteve French $ ./autogen.sh 131ab6cacf8SSteve French $ ./configure --with-rundir=/run 132ab6cacf8SSteve French $ make && sudo make install 133ab6cacf8SSteve French 134ab6cacf8SSteve French2. Create /usr/local/etc/ksmbd/ksmbd.conf file, add SMB share in ksmbd.conf file. 135ab6cacf8SSteve French 136*4fdd8664SVictor Timofei - Refer to ksmbd.conf.example in ksmbd-utils, See ksmbd.conf manpage 137ab6cacf8SSteve French for details to configure shares. 138ab6cacf8SSteve French 139ab6cacf8SSteve French $ man ksmbd.conf 140ab6cacf8SSteve French 141ab6cacf8SSteve French3. Create user/password for SMB share. 142ab6cacf8SSteve French 143ab6cacf8SSteve French - See ksmbd.adduser manpage. 144ab6cacf8SSteve French 145ab6cacf8SSteve French $ man ksmbd.adduser 146ab6cacf8SSteve French $ sudo ksmbd.adduser -a <Enter USERNAME for SMB share access> 147ab6cacf8SSteve French 148*4fdd8664SVictor Timofei4. Insert the ksmbd.ko module after you build your kernel. No need to load the module 149ab6cacf8SSteve French if ksmbd is built into the kernel. 150ab6cacf8SSteve French 151ab6cacf8SSteve French - Set ksmbd in menuconfig(e.g. $ make menuconfig) 152ab6cacf8SSteve French [*] Network File Systems ---> 153ab6cacf8SSteve French <M> SMB3 server support (EXPERIMENTAL) 154ab6cacf8SSteve French 155ab6cacf8SSteve French $ sudo modprobe ksmbd.ko 156ab6cacf8SSteve French 157ab6cacf8SSteve French5. Start ksmbd user space daemon 158ab6cacf8SSteve French 159ab6cacf8SSteve French $ sudo ksmbd.mountd 160ab6cacf8SSteve French 161ab6cacf8SSteve French6. Access share from Windows or Linux using SMB3 client (cifs.ko or smbclient of samba) 162ab6cacf8SSteve French 163ab6cacf8SSteve FrenchShutdown KSMBD 164ab6cacf8SSteve French============== 165ab6cacf8SSteve French 166ab6cacf8SSteve French1. kill user and kernel space daemon 167ab6cacf8SSteve French # sudo ksmbd.control -s 168ab6cacf8SSteve French 169ab6cacf8SSteve FrenchHow to turn debug print on 170ab6cacf8SSteve French========================== 171ab6cacf8SSteve French 172ab6cacf8SSteve FrenchEach layer 173ab6cacf8SSteve French/sys/class/ksmbd-control/debug 174ab6cacf8SSteve French 175ab6cacf8SSteve French1. Enable all component prints 176ab6cacf8SSteve French # sudo ksmbd.control -d "all" 177ab6cacf8SSteve French 178*4fdd8664SVictor Timofei2. Enable one of the components (smb, auth, vfs, oplock, ipc, conn, rdma) 179ab6cacf8SSteve French # sudo ksmbd.control -d "smb" 180ab6cacf8SSteve French 181ab6cacf8SSteve French3. Show what prints are enabled. 182ab6cacf8SSteve French # cat /sys/class/ksmbd-control/debug 183ab6cacf8SSteve French [smb] auth vfs oplock ipc conn [rdma] 184ab6cacf8SSteve French 185ab6cacf8SSteve French4. Disable prints: 186ab6cacf8SSteve French If you try the selected component once more, It is disabled without brackets. 187