From: RootSys GmbH Research <team@rootsys.at>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Michail Andreas Michalopoulos <mike.michalo@gmail.com>,
Ian Bridges <icb@fastmail.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Tom Talpey <tom@talpey.com>,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
linux-cifs@vger.kernel.org,
RootSys GmbH Research <research@rootsys.at>
Subject: [PATCH v2 0/4] ksmbd: enforce mandatory signing and encryption on requests
Date: Thu, 26 Nov 2026 16:08:32 +0100 [thread overview]
Message-ID: <cover.1795701726.git.research@rootsys.at> (raw)
In-Reply-To: <20261119103805.29514-1-research@rootsys.at>
From: RootSys GmbH Research <research@rootsys.at>
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 offers no cipher at all
gets a plaintext session even with mandatory encryption. 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 plaintext requests on sessions that were told to encrypt.
Patch 4 fails SESSION_SETUP with STATUS_ACCESS_DENIED, as MS-SMB2
3.3.5.5 requires, when encryption is mandatory and the connection
cannot encrypt (SMB 2.x, or SMB 3.1.1 without a common cipher).
The series is based on ksmbd-for-next 3c31349456c5, because patch 2
uses sess->sign_required from the session setup signing series queued
there. On mainline it applies on top of that series' first three
commits, 16ab0adace8f ("ksmbd: verify the signature of session binding
requests"), 42a1d80e64a3 ("ksmbd: sign with the negotiated SMB 3.1.1
signing algorithm") and ea472ddf7a9a ("ksmbd: use the channel signing
key for session setup on a bound channel"). Patch 1 has no
dependencies.
Changes in v2, following the review of v1:
- Order: the per-connection capability patch (v1 4/4) is now patch 1,
since it depends on nothing. Its changelog now says that in the
default "auto" mode the leaked capability gives a later SMB 3.0
client that offered no encryption sess->enc and clears sess->sign,
which is the gap patch 2 closes.
- Stable: patch 2 needs sess->sign_required, so its stable tags now
name the three commits above as prerequisites, in the format of
stable-kernel-rules.rst. The other patches keep a plain stable tag.
- v1 3/4 ("refuse tree connect without a cipher when encryption is
mandatory") is replaced by patch 4, which follows MS-SMB2 3.3.5.5
and fails the SESSION_SETUP itself, so a relayed login is stopped
before authentication completes. On SMB 3.0 and 3.0.2,
init_smb3_0_server() and init_smb3_02_server() set
SMB2_GLOBAL_CAP_ENCRYPTION unconditionally under mandatory
encryption, so the check does not trigger there; such sessions are
told to encrypt, and patch 3 refuses their plaintext requests.
- A signed plaintext SESSION_SETUP reauthentication on a session that
was told to encrypt is still accepted. In MS-SMB2, 3.3.5.2.9 applies
where a command section calls for it: 3.3.5.6 (LOGOFF) to 3.3.5.21
(SET_INFO) locate or verify the session "as specified in section
3.3.5.2.9". 3.3.5.5 looks the session up itself and does not refer to
3.3.5.2.9; its only encryption requirement is the dialect and
capability check at its start, and neither 3.3.5.5.2
(reauthentication) nor 3.3.5.5.3 asks whether the request was
encrypted. Signature verification (3.3.5.2.4) does apply, and ksmbd
does it.
- CANCEL (thanks, Ian): patch 3 drops a plaintext SMB2 CANCEL on a
session that must encrypt without a response, where v1 answered it
with STATUS_ACCESS_DENIED:
MS-SMB2 3.3.5.16 never answers a CANCEL and verifies the session as
in 3.3.5.2.9 only for a signed one. The signing check in patch 2 still
answers an unsigned CANCEL on a session that requires signing with
STATUS_ACCESS_DENIED, as ksmbd already does when sess->sign is set:
3.3.5.16 exempts a CANCEL only from 3.3.5.2.3, and 3.3.5.2.4 fails an
unsigned request on a session that requires signing.
- Sashiko's review of v1 2/4 (now patch 3) raised four points. We
checked each one on a KASAN kernel:
- Reauthentication: SESSION_SETUP is outside the new check on
purpose; smb2_sess_setup() checks the session it reauthenticates.
It refuses an unsigned plaintext reauthentication of a user session
that must encrypt with STATUS_ACCESS_DENIED at the first leg, and
the session stays usable. smb2_sess_needs_protection() is true for
every such session, since sess->enc_required implies sess->enc and
the global flag. A guest session is not checked there, so an
injected reauthentication can expire it, with or without this
series; its keys are derived from an all-zero session key, so an
attacker on the path could send the same request encrypted. No
change.
- Compounds: reproduced. After a plaintext SESSION_SETUP that
completes a session, a chained ECHO with SessionId 0 and a chained
SESSION_SETUP for a new session got STATUS_ACCESS_DENIED. The check
now leaves SESSION_SETUP to smb2_sess_setup() and skips an ECHO
with SessionId 0 (3.3.5.17); a related ECHO, which uses the new
session, is still refused.
- Order: reproduced for the tree connect. A plaintext request got
STATUS_NETWORK_NAME_DELETED for an invalid TreeId and
STATUS_ACCESS_DENIED for a valid one. The check now runs where the
session is verified, before the tree connect is looked up, so both
get STATUS_ACCESS_DENIED. A session whose Kerberos ticket has
expired still answers STATUS_NETWORK_SESSION_EXPIRED first, since
3.3.5.2.9 checks Session.State before EncryptData.
- Reauthentication response: reproduced, the response to an
encrypted NTLM reauthentication had SessionFlags 0. Patch 3 now
sets SMB2_SESSION_FLAG_ENCRYPT_DATA there, as 3.3.5.5.3 requires.
The Linux client is not affected either way: it sends a non-binding
SESSION_SETUP only with SessionId 0, so after a reconnect it sets up
a new session, and a vers=3.1.1 mount without "seal" under mandatory
encryption kept working across a server restart, with and without
the series.
- Tested-by added to patches 1 and 2, whose code is unchanged from v1.
Patch 3 has changed (CANCEL and the points above) and patch 4 is new
code; they carry none.
- The patches carry an in-body From: research@rootsys.at, so the author
matches Signed-off-by:. The mail itself goes out through the
team@rootsys.at mailbox, which research@rootsys.at is an alias of.
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) and =m, 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 3c31349456c5 and from mainline 8dac6df92a2e (with the
three commits above), each with this series:
- every unsigned or plaintext request that gets through on the
unpatched trees 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 and SMB 3.1.1 clients that offer
no cipher fail the first SESSION_SETUP with STATUS_ACCESS_DENIED, and
an SMB 3.0 client without SMB2_GLOBAL_CAP_ENCRYPTION is told to
encrypt and its plaintext TREE_CONNECT is refused;
- 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, as without the series; on
a session that requires signing it gets STATUS_ACCESS_DENIED, as it
did without the series when the client offered no cipher;
- 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 change as ntlm_authenticate() in
patch 3), 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 (4):
ksmbd: keep negotiated capabilities per connection
ksmbd: require signing on sessions that negotiated encryption
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 | 41 ++++++++++++++++++++++++++++---
fs/smb/server/smb2ops.c | 19 +++++++++++---
fs/smb/server/smb2pdu.c | 25 +++++++++++++++++--
5 files changed, 80 insertions(+), 9 deletions(-)
base-commit: 3c31349456c5b71edc837270cf9075b28dc59ee3
--
2.43.0
next prev parent reply other threads:[~2026-11-26 15:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 10:38 [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 1/4] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 2/4] ksmbd: reject plaintext requests on sessions that must be encrypted RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 3/4] ksmbd: refuse tree connect without a cipher when encryption is mandatory RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 4/4] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
2026-11-19 12:51 ` [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests mixalhs
2026-11-19 13:44 ` RootSys GmbH Research
2026-11-19 17:29 ` Ian Bridges
2026-11-26 15:08 ` RootSys GmbH Research [this message]
2026-11-26 15:08 ` [PATCH v2 1/4] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
2026-11-26 15:08 ` [PATCH v2 2/4] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
2026-11-26 15:08 ` [PATCH v2 3/4] ksmbd: reject plaintext requests on sessions that must be encrypted RootSys GmbH Research
2026-11-26 15:08 ` [PATCH v2 4/4] ksmbd: refuse session setup without encryption when it is mandatory RootSys GmbH Research
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1795701726.git.research@rootsys.at \
--to=team@rootsys.at \
--cc=chenxiaosong@chenxiaosong.com \
--cc=icb@fastmail.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=mike.michalo@gmail.com \
--cc=research@rootsys.at \
--cc=senozhatsky@chromium.org \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox