From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367211; b=LH5WsuW8NQJCbJb2v6ocWACdP98d6S7QS4mV8o1i3giA7gXatqdswcDXy0PqjPTRIvZ0 oRiBcMpSOqhO++adHsC2iLORD4o/9Jylp1HCAuWuEhYg4X0bk2Kc3XXxUGL880AFxuNsX mxqf3Q2oAgXWoWfFXyixZuP7KXkXiNeFJDb9wXeqTqf9v5al24bTSwjZeOLX+29Oc7ig6 UAuOaejuzhGy3s8sR6JWFIq4iP6oPqTZd/0JE84OX0Yl3Hr2o0+t8+WISej1I8tEZfN6g hi/TVQSHm+cZvordHkcN9bn5SNLD091LluB6akCsrf4X8xgEhjSrMtRCGnFKdTDDqwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367211; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=IAcqFdgNRLQSgrSIysd5UAa7f5YDMEPc2ogSV9nRHEU=; b=BlRLRJ3tpZywaFK4rdSBPF53ryPUX1qJ+1h2iraeYzDQNW1TFfRmxBEBfDn8q58aZC9d iVbvAVJzWG/HSD3BbsGXfirN7suG1BDLMoeZgq0ce3nCWEJpw//JXzZt9Hhws6CQ+sQug n8OivNAplcXVru5WQnB0tE/5+Y5BmmqBqgkkooi5pP26C3V1IF8y0CD8VEjU+FmThKUY3 DrnLXD8LeEfXztl7Q+ZdsDKQO5zlEwYc8W267eu9hOAJ47Ib/vkoRaFZM7A4y38/jO58o f1iqv/f8hiDFGBQXGWe3q8IFKT6YcAFIgv3X9mU/iO+xzmm184K4xiHmjugiE1n7rVg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=rootsys.at; spf=pass smtp.mailfrom=rootsys.at; dkim=pass header.d=rootsys.at header.i=@rootsys.at header.a=rsa-sha256 header.s=google header.b=nVcIIsDi; arc=none smtp.remote-ip=209.85.221.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1368F606A33A for ; Fri, 4 Dec 2026 06:53:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1368F606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rootsys.at Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rootsys.at Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=rootsys.at header.i=@rootsys.at header.a=rsa-sha256 header.s=google header.b=nVcIIsDi Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso654501f8f.0 for ; Thu, 03 Dec 2026 22:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rootsys.at; s=google; t=1796367209; x=1796972009; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=IAcqFdgNRLQSgrSIysd5UAa7f5YDMEPc2ogSV9nRHEU=; b=nVcIIsDi3ceR9Ft7wgr7ubiKL8Bq6/4usMmGVzeOziJXt4fga6ARVAYUrmzGCqKmX2 GeCXEh8JMPGytd/+OQcMAazfvww7kghlzevljw3F0DPpZkPvSZNRIkaY68vMS1ye8Hij We8QrYs6r/ghXn0rP48U5ptwTS8k9GN7oUN2yzgDXASnZvz6i6CqVcnw/StGo5wy6/ms xjEENTlIoXqW0Ic1isy+pwrkGmWKkStZ9X+PEHnqxwhJJ2+Cqj6vRYIKKp7x6wxMP62Q KRohdwW80xhaWeWgLg3XeGVtYpLGMKRh+12dMFVJkQjSmiHlxJOLVHCx42eNlmIETkjX k/oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796367209; x=1796972009; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IAcqFdgNRLQSgrSIysd5UAa7f5YDMEPc2ogSV9nRHEU=; b=NpPD4DSQqqNxuiep04gXhj8FO5duGxGsT9b4/uJaU6aLj569FnIuzHDFnLpSJtMSoJ KrHMNGD76y21eYOcWNKvGer/FK1yWV5MRHF82VT3BfvZEGVv2fOd4qJW6TNQ2H0lBkwX KjFki/hbG0usXU1CaaUfYUwRv5WRVhkFsTtre6bgmkn7c8T7pBngpWcNycqpynGHqoeT reUGZ3ItfCEYavKMHOC+44mqP9CGphrCrg1Cf4wkJt70s+OApw8COqebyz/1De+nw5X5 xkZqaxFMNZ7B1e/pOfXaaJpLNQRzP/3XhtREr7T9sGpU4S76R1/7isdTZ88QwwmuaVVR 6ZvA== X-Forwarded-Encrypted: i=1; AL+hErGur3dRjUwAtPElHN275DTnqBwaqb60N81xZ1xXL5EYDQEpsuSypwq3lykNm7rZPZCc2W6IPA5cpDl0@vger.kernel.org X-Gm-Message-State: APuU4Z+QON07Nu+UCHHMFL5IqpyMB4gHbQd6+4KS3kCEt6G1fJQrYkIk tUhZMm1N1ftcx7HP4qYSuLwMbaHJ0gLZ03W4d4H7blK8jGUfQu6SNY0E9AXwNvE2dfHY X-Gm-Gg: AZFdTZeuOctETVHE3EuVriNHNmVw5cx5mh/2ETA1bYJE+F1MhFXHNi/rss3NhY46t3x pvYTzvvlNT8n447k2/7ddkP1xncxAQ+XJ5FaOZTji9tVxZVnYe/WPOXpcBwCOUOeYKMQ4KSf1lp MRsNOcd9XHYNNA8lVL1LfRgadDBaZ0cbaM4SiCgoL8DQ5sdGsmGd1ueys0qRd8XgT0Ugo17qtfK VLFjk+sTp0sHwhkcVTUosMfQ97GfYTofvBlWTWttMnPToa+jzSaFvVXjUhg0KxtsDC2dA3FiOSS y9cIStmKcV1KyiSnx45CA659kG/ds1emZePNu4SxPPFT/oV8VsrifqYRfPx/2vZBzkeVI5ckr4j +Kq6Wy4NTc5pempo9xv6+YIQMU0ThB14eEBOIBT7Eq05fG6Q97EfuEqHEz2M0GWpv9yQYlqfO3n oZm3HpYmGRtmzRKUGGVtR2XAIgDOvmrwCKrNc5Fi7SolA0FB+Lyg4KcT5jOVQxjfHD/C2HeE6lA m+ZTjgrpDVxu1UnjzMWHvqOj5QNdHAoFHfcG/NrIq/PdtW7cATy/kM3DK218LzxCdz3vwTfBcrn nkRi9gUhpDhC2/JURmSKGElgYMSCaJXw85MRoniDeWXRd3oy275PwzNANcvJHGM= X-Received: by 2002:a05:6000:2c13:b0:4a6:dfe3:fd93 with SMTP id ffacd0b85a97d-4d1ebd96098mr2064084f8f.40.1796367209429; Thu, 03 Dec 2026 22:53:29 -0800 (PST) Received: from rootsys.at (clnet-p094-053.ikbnet.co.at. [83.175.94.53]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17435dbccsm3637349f8f.47.2026.12.03.22.53.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Dec 2026 22:53:29 -0800 (PST) From: RootSys GmbH Research To: Namjae Jeon Cc: Michail Andreas Michalopoulos , Ian Bridges , Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-cifs@vger.kernel.org, RootSys GmbH Research Subject: [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests Date: Fri, 4 Dec 2026 07:53:22 +0100 Message-ID: X-Mailer: git-send-email 2.54.0 X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: RootSys GmbH Research ksmbd does not enforce "server signing = mandatory" or "smb3 encryption = mandatory" on requests once a client has offered a cipher in NEGOTIATE, which the Linux and current Windows clients always do. sess->sign is cleared for such sessions, and the gate added by 2bebf2470af1 ("ksmbd: enforce signing required by the session") only looks at sess->sign, so an unsigned plaintext request is executed on a session that requires signing, and a plaintext request on a session that was told SMB2_SESSION_FLAG_ENCRYPT_DATA. A client that cannot encrypt gets a plaintext session even with mandatory encryption, and so does a SESSION_SETUP that sets SMB2_SESSION_REQ_FLAG_BINDING without a SessionId. On SMB 3.0 and 3.0.2, one client's SMB2_GLOBAL_CAP_ENCRYPTION is ORed into the static per-dialect table and changes how every later session of that dialect is set up, until the module is reloaded. The consequence is that a man-in-the-middle between a client and ksmbd can inject requests into an authenticated session and have them run with the victim's credentials, and that an NTLM relay to ksmbd is not stopped by either setting, which is what the two settings exist for. Patch 1 gives each connection its own copy of its dialect's capability table. Patch 2 makes the request gate honour sess->sign_required. Patch 3 refuses a binding SESSION_SETUP without a SessionId. Patch 4 refuses plaintext requests on sessions that were told to encrypt. Patch 5 fails SESSION_SETUP with STATUS_ACCESS_DENIED, as MS-SMB2 3.3.5.5 requires, when encryption is mandatory and the client cannot encrypt, and fails a guest login then. The series is based on ksmbd-for-next 43dc36660aff. Patch 2 uses sess->sign_required, and patch 4 ksmbd_set_failed_rsp_credits() and the MessageId check on the failed-session path, from commits queued there. On mainline 007722b8211f it applies on top of the eight ksmbd-for-next commits from e1b357794105 ("ksmbd: verify the signature of session binding requests") to 332ac50e7533 ("ksmbd: account for the credits of a request on a failed session"). Patch 1 has no dependencies. Changes in v3, following Namjae's review of v2: - Patch 5 (v2 4/4) checks what the client offered, as 3.3.5.5 says: SMB2_GLOBAL_CAP_ENCRYPTION in the client's NEGOTIATE capabilities on SMB 3.0 and 3.0.2, a common cipher on SMB 3.1.1. v2 used smb3_encryption_negotiated(), which holds on 3.0 and 3.0.2 whenever encryption is mandatory, because init_smb3_0_server() and init_smb3_02_server() then set the capability on the server side. An SMB 3.0 client that offered no encryption got a session and was only stopped at its first plaintext request; it now fails the first SESSION_SETUP. - Patch 4 (v2 3/4) handles a refused plaintext request like a request on a failed session: the request is verified first, which consumes its MessageId and refuses a replay, and its credits are charged and new ones granted before the response is sent. In v2 a refused request did neither: 600 plaintext ECHOs on a session that must encrypt were answered with no credits and left their MessageIds unconsumed, and ksmbd dropped the connection at the client's next, encrypted, request. With v3 the same 600 requests get their credits and the next encrypted request succeeds. A plaintext CANCEL is still dropped without a response and consumes no credit. - Guest sessions: with mandatory encryption a guest login reached the encryption setup, the response carried SMB2_SESSION_FLAG_ENCRYPT_DATA instead of SMB2_SESSION_FLAG_IS_GUEST, the keys were derived from an all-zero session key, and v2 also set sess->enc_required on it. A guest login got such a session with and without v2, and requests encrypted with keys derived from a zero key were accepted on it. 3.3.5.5.3 derives encryption keys only for a session that is neither guest nor anonymous, so a guest session cannot meet the setting; patch 5 now fails a guest login with STATUS_ACCESS_DENIED when encryption is mandatory, as Samba does. - New patch 3: smb2_sess_setup() treats SessionId 0 as a new session and clears conn->binding, but ntlm_authenticate() and krb5_authenticate() looked at the request's SMB2_SESSION_REQ_FLAG_BINDING bit to skip the encryption setup. With NTLM, the challenge stays on the connection, so after the pending session of the first leg has failed, an AUTHENTICATE sent with SessionId 0 and the binding bit set up a new session without encryption keys and without SMB2_SESSION_FLAG_ENCRYPT_DATA, and an unsigned plaintext TREE_CONNECT on it succeeded, with and without v2. Patch 3 fails such a request with STATUS_INVALID_PARAMETER, as Samba does, and both authentication paths use conn->binding. On every other path that reaches them, conn->binding and the bit agree. - Stable: patch 2's prerequisite tags name the current ksmbd-for-next ids of the three commits; patch 4 now also names ac68edfa99c7 and 332ac50e7533 as prerequisites. - Tested-by kept on patches 1 and 2, whose code is unchanged since v1. Patch 3 is new and patches 4 and 5 have changed; they carry none. The v2 changes (order, stable tags, v1 3/4 replaced by the SESSION_SETUP check, CANCEL, Sashiko's four points) are described in the v2 cover letter. v2: https://lore.kernel.org/linux-cifs/cover.1795701726.git.research@rootsys.at/ v1: https://lore.kernel.org/linux-cifs/20261119103805.29514-1-research@rootsys.at/ Testing: W=1 builds of fs/smb/server after each patch, with CONFIG_SMB_SERVER=y and CONFIG_SMB_SERVER_KERBEROS5=y, give no warnings. checkpatch --strict reports no errors or warnings, only CamelCase checks for the MS-SMB2 field names SessionId and SessionFlags. On KASAN kernels built from ksmbd-for-next 43dc36660aff and from mainline 007722b8211f with the eight commits above, each with this series: - every unsigned or plaintext request that gets through on the unpatched tree is refused with STATUS_ACCESS_DENIED: TREE_CONNECT after an NTLM login over SMB 3.1.1 with a cipher offered (mandatory signing, and mandatory encryption), and over SMB 3.0 after another client offered SMB2_GLOBAL_CAP_ENCRYPTION; - under mandatory encryption, SMB 2.1 clients, SMB 3.0 clients without SMB2_GLOBAL_CAP_ENCRYPTION, SMB 3.1.1 clients that offer no cipher and guest logins fail SESSION_SETUP with STATUS_ACCESS_DENIED, and an AUTHENTICATE with SessionId 0 and the binding bit fails with STATUS_INVALID_PARAMETER; - 600 refused plaintext requests are granted credits, and an encrypted request after them succeeds; - the next NEGOTIATE no longer advertises a capability another client offered; - an unsigned plaintext CANCEL for a request that is not pending gets no response on a session that must encrypt; on a session that requires signing it gets STATUS_ACCESS_DENIED; - on a session that must encrypt, a plaintext request is refused with STATUS_ACCESS_DENIED whether its TreeId is valid or not, an unsigned plaintext reauthentication is refused and the session stays usable, and the response to an encrypted reauthentication carries SMB2_SESSION_FLAG_ENCRYPT_DATA; - in a plaintext compound, after the SESSION_SETUP that completes a session, an ECHO with SessionId 0 and a SESSION_SETUP for a new session are processed as without the series, and a related ECHO is refused; - the in-kernel cifs client mounts, writes and reads under mandatory signing with vers=2.1, 3.0, 3.0.2 and 3.1.1 using sign, and with vers=3.0, 3.0.2 and 3.1.1 using seal; under mandatory encryption with vers=3.0, 3.0.2 and 3.1.1, sign or seal. vers=2.1 under mandatory encryption fails at SESSION_SETUP with STATUS_ACCESS_DENIED, as intended. A vers=3.1.1 mount without "seal" under mandatory encryption keeps working across a server restart. No KASAN, UBSAN or WARN reports. Not tested: Kerberos sessions (krb5_authenticate() gets the same changes as ntlm_authenticate() in patches 3 and 4), SMB Direct, multichannel binding, and a signed plaintext CANCEL on a session that must encrypt. We found this with AI-assisted code review and testing; the reproducer and the fix were tested by us on current mainline. RootSys GmbH Research (5): ksmbd: keep negotiated capabilities per connection ksmbd: require signing on sessions that negotiated encryption ksmbd: refuse a binding request without a SessionId ksmbd: reject plaintext requests on sessions that must be encrypted ksmbd: refuse session setup without encryption when it is mandatory fs/smb/server/connection.h | 2 ++ fs/smb/server/mgmt/user_session.h | 2 ++ fs/smb/server/server.c | 51 ++++++++++++++++++++++++-- fs/smb/server/smb2ops.c | 19 +++++++--- fs/smb/server/smb2pdu.c | 60 +++++++++++++++++++++++++++---- 5 files changed, 121 insertions(+), 13 deletions(-) base-commit: 43dc36660aff09d415b2949d3498c94763798b21 -- 2.43.0