162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci========================== 462306a36Sopenharmony_ciKSMBD - SMB3 Kernel Server 562306a36Sopenharmony_ci========================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciKSMBD is a linux kernel server which implements SMB3 protocol in kernel space 862306a36Sopenharmony_cifor sharing files over network. 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciKSMBD architecture 1162306a36Sopenharmony_ci================== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciThe subset of performance related operations belong in kernelspace and 1462306a36Sopenharmony_cithe other subset which belong to operations which are not really related with 1562306a36Sopenharmony_ciperformance in userspace. So, DCE/RPC management that has historically resulted 1662306a36Sopenharmony_ciinto number of buffer overflow issues and dangerous security bugs and user 1762306a36Sopenharmony_ciaccount management are implemented in user space as ksmbd.mountd. 1862306a36Sopenharmony_ciFile operations that are related with performance (open/read/write/close etc.) 1962306a36Sopenharmony_ciin kernel space (ksmbd). This also allows for easier integration with VFS 2062306a36Sopenharmony_ciinterface for all file operations. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciksmbd (kernel daemon) 2362306a36Sopenharmony_ci--------------------- 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciWhen the server daemon is started, It starts up a forker thread 2662306a36Sopenharmony_ci(ksmbd/interface name) at initialization time and open a dedicated port 445 2762306a36Sopenharmony_cifor listening to SMB requests. Whenever new clients make request, Forker 2862306a36Sopenharmony_cithread will accept the client connection and fork a new thread for dedicated 2962306a36Sopenharmony_cicommunication channel between the client and the server. It allows for parallel 3062306a36Sopenharmony_ciprocessing of SMB requests(commands) from clients as well as allowing for new 3162306a36Sopenharmony_ciclients to make new connections. Each instance is named ksmbd/1~n(port number) 3262306a36Sopenharmony_cito indicate connected clients. Depending on the SMB request types, each new 3362306a36Sopenharmony_cithread can decide to pass through the commands to the user space (ksmbd.mountd), 3462306a36Sopenharmony_cicurrently DCE/RPC commands are identified to be handled through the user space. 3562306a36Sopenharmony_ciTo further utilize the linux kernel, it has been chosen to process the commands 3662306a36Sopenharmony_cias workitems and to be executed in the handlers of the ksmbd-io kworker threads. 3762306a36Sopenharmony_ciIt allows for multiplexing of the handlers as the kernel take care of initiating 3862306a36Sopenharmony_ciextra worker threads if the load is increased and vice versa, if the load is 3962306a36Sopenharmony_cidecreased it destroys the extra worker threads. So, after connection is 4062306a36Sopenharmony_ciestablished with client. Dedicated ksmbd/1..n(port number) takes complete 4162306a36Sopenharmony_ciownership of receiving/parsing of SMB commands. Each received command is worked 4262306a36Sopenharmony_ciin parallel i.e., There can be multiple clients commands which are worked in 4362306a36Sopenharmony_ciparallel. After receiving each command a separated kernel workitem is prepared 4462306a36Sopenharmony_cifor each command which is further queued to be handled by ksmbd-io kworkers. 4562306a36Sopenharmony_ciSo, each SMB workitem is queued to the kworkers. This allows the benefit of load 4662306a36Sopenharmony_cisharing to be managed optimally by the default kernel and optimizing client 4762306a36Sopenharmony_ciperformance by handling client commands in parallel. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciksmbd.mountd (user space daemon) 5062306a36Sopenharmony_ci-------------------------------- 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciksmbd.mountd is userspace process to, transfer user account and password that 5362306a36Sopenharmony_ciare registered using ksmbd.adduser (part of utils for user space). Further it 5462306a36Sopenharmony_ciallows sharing information parameters that parsed from smb.conf to ksmbd in 5562306a36Sopenharmony_cikernel. For the execution part it has a daemon which is continuously running 5662306a36Sopenharmony_ciand connected to the kernel interface using netlink socket, it waits for the 5762306a36Sopenharmony_cirequests (dcerpc and share/user info). It handles RPC calls (at a minimum few 5862306a36Sopenharmony_cidozen) that are most important for file server from NetShareEnum and 5962306a36Sopenharmony_ciNetServerGetInfo. Complete DCE/RPC response is prepared from the user space 6062306a36Sopenharmony_ciand passed over to the associated kernel thread for the client. 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciKSMBD Feature Status 6462306a36Sopenharmony_ci==================== 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci============================== ================================================= 6762306a36Sopenharmony_ciFeature name Status 6862306a36Sopenharmony_ci============================== ================================================= 6962306a36Sopenharmony_ciDialects Supported. SMB2.1 SMB3.0, SMB3.1.1 dialects 7062306a36Sopenharmony_ci (intentionally excludes security vulnerable SMB1 7162306a36Sopenharmony_ci dialect). 7262306a36Sopenharmony_ciAuto Negotiation Supported. 7362306a36Sopenharmony_ciCompound Request Supported. 7462306a36Sopenharmony_ciOplock Cache Mechanism Supported. 7562306a36Sopenharmony_ciSMB2 leases(v1 lease) Supported. 7662306a36Sopenharmony_ciDirectory leases(v2 lease) Planned for future. 7762306a36Sopenharmony_ciMulti-credits Supported. 7862306a36Sopenharmony_ciNTLM/NTLMv2 Supported. 7962306a36Sopenharmony_ciHMAC-SHA256 Signing Supported. 8062306a36Sopenharmony_ciSecure negotiate Supported. 8162306a36Sopenharmony_ciSigning Update Supported. 8262306a36Sopenharmony_ciPre-authentication integrity Supported. 8362306a36Sopenharmony_ciSMB3 encryption(CCM, GCM) Supported. (CCM and GCM128 supported, GCM256 in 8462306a36Sopenharmony_ci progress) 8562306a36Sopenharmony_ciSMB direct(RDMA) Supported. 8662306a36Sopenharmony_ciSMB3 Multi-channel Partially Supported. Planned to implement 8762306a36Sopenharmony_ci replay/retry mechanisms for future. 8862306a36Sopenharmony_ciReceive Side Scaling mode Supported. 8962306a36Sopenharmony_ciSMB3.1.1 POSIX extension Supported. 9062306a36Sopenharmony_ciACLs Partially Supported. only DACLs available, SACLs 9162306a36Sopenharmony_ci (auditing) is planned for the future. For 9262306a36Sopenharmony_ci ownership (SIDs) ksmbd generates random subauth 9362306a36Sopenharmony_ci values(then store it to disk) and use uid/gid 9462306a36Sopenharmony_ci get from inode as RID for local domain SID. 9562306a36Sopenharmony_ci The current acl implementation is limited to 9662306a36Sopenharmony_ci standalone server, not a domain member. 9762306a36Sopenharmony_ci Integration with Samba tools is being worked on 9862306a36Sopenharmony_ci to allow future support for running as a domain 9962306a36Sopenharmony_ci member. 10062306a36Sopenharmony_ciKerberos Supported. 10162306a36Sopenharmony_ciDurable handle v1,v2 Planned for future. 10262306a36Sopenharmony_ciPersistent handle Planned for future. 10362306a36Sopenharmony_ciSMB2 notify Planned for future. 10462306a36Sopenharmony_ciSparse file support Supported. 10562306a36Sopenharmony_ciDCE/RPC support Partially Supported. a few calls(NetShareEnumAll, 10662306a36Sopenharmony_ci NetServerGetInfo, SAMR, LSARPC) that are needed 10762306a36Sopenharmony_ci for file server handled via netlink interface 10862306a36Sopenharmony_ci from ksmbd.mountd. Additional integration with 10962306a36Sopenharmony_ci Samba tools and libraries via upcall is being 11062306a36Sopenharmony_ci investigated to allow support for additional 11162306a36Sopenharmony_ci DCE/RPC management calls (and future support 11262306a36Sopenharmony_ci for Witness protocol e.g.) 11362306a36Sopenharmony_ciksmbd/nfsd interoperability Planned for future. The features that ksmbd 11462306a36Sopenharmony_ci support are Leases, Notify, ACLs and Share modes. 11562306a36Sopenharmony_ci============================== ================================================= 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ciHow to run 11962306a36Sopenharmony_ci========== 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci1. Download ksmbd-tools(https://github.com/cifsd-team/ksmbd-tools/releases) and 12262306a36Sopenharmony_ci compile them. 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci - Refer README(https://github.com/cifsd-team/ksmbd-tools/blob/master/README.md) 12562306a36Sopenharmony_ci to know how to use ksmbd.mountd/adduser/addshare/control utils 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci $ ./autogen.sh 12862306a36Sopenharmony_ci $ ./configure --with-rundir=/run 12962306a36Sopenharmony_ci $ make && sudo make install 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci2. Create /usr/local/etc/ksmbd/ksmbd.conf file, add SMB share in ksmbd.conf file. 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci - Refer ksmbd.conf.example in ksmbd-utils, See ksmbd.conf manpage 13462306a36Sopenharmony_ci for details to configure shares. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci $ man ksmbd.conf 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci3. Create user/password for SMB share. 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci - See ksmbd.adduser manpage. 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci $ man ksmbd.adduser 14362306a36Sopenharmony_ci $ sudo ksmbd.adduser -a <Enter USERNAME for SMB share access> 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci4. Insert ksmbd.ko module after build your kernel. No need to load module 14662306a36Sopenharmony_ci if ksmbd is built into the kernel. 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci - Set ksmbd in menuconfig(e.g. $ make menuconfig) 14962306a36Sopenharmony_ci [*] Network File Systems ---> 15062306a36Sopenharmony_ci <M> SMB3 server support (EXPERIMENTAL) 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci $ sudo modprobe ksmbd.ko 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci5. Start ksmbd user space daemon 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci $ sudo ksmbd.mountd 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci6. Access share from Windows or Linux using SMB3 client (cifs.ko or smbclient of samba) 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ciShutdown KSMBD 16162306a36Sopenharmony_ci============== 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci1. kill user and kernel space daemon 16462306a36Sopenharmony_ci # sudo ksmbd.control -s 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ciHow to turn debug print on 16762306a36Sopenharmony_ci========================== 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ciEach layer 17062306a36Sopenharmony_ci/sys/class/ksmbd-control/debug 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci1. Enable all component prints 17362306a36Sopenharmony_ci # sudo ksmbd.control -d "all" 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci2. Enable one of components (smb, auth, vfs, oplock, ipc, conn, rdma) 17662306a36Sopenharmony_ci # sudo ksmbd.control -d "smb" 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci3. Show what prints are enabled. 17962306a36Sopenharmony_ci # cat /sys/class/ksmbd-control/debug 18062306a36Sopenharmony_ci [smb] auth vfs oplock ipc conn [rdma] 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci4. Disable prints: 18362306a36Sopenharmony_ci If you try the selected component once more, It is disabled without brackets. 184