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