* [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests
@ 2026-11-19 10:38 RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 1/4] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-19 10:38 UTC (permalink / raw)
To: Namjae Jeon
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong,
mike.michalo, linux-cifs
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.
The session handling goes back to e2f34481b24d ("cifsd: add server-side
procedures for SMB3"); the signing part is what is left after
2bebf2470af1 (v7.2-rc5). We reproduced it on mainline 4405c18c95d2
(v7.4-rc3-230), on v7.3 and on ksmbd-for-next 267029b35ad1. A
reproducer is available to the maintainers on request.
The series is based on ksmbd-for-next 267029b35ad1, because patch 1
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 makes the request gate honour sess->sign_required. Patch 2
refuses plaintext requests on sessions that were told to encrypt. Patch
3 applies the existing per-share "needs a negotiated cipher" check to
tree connects when encryption is mandatory for the whole server, so an
SMB 2.1 client can no longer connect in that configuration, as
ksmbd.conf(5) documents. Patch 4 gives each connection its own copy of
its dialect's capability table.
Testing: built with W=1 for CONFIG_SMB_SERVER=y and =m without
warnings, each patch on its own, and checkpatch --strict clean. On
KASAN kernels built from ksmbd-for-next 267029b35ad1 and from mainline
4405c18c95d2 (with the three commits above), each with this series,
every unsigned or plaintext TREE_CONNECT that gets through on the
unpatched trees is refused with STATUS_ACCESS_DENIED, and the next
NEGOTIATE no longer advertises a capability another client offered. The
in-kernel cifs client still mounts, writes and reads with sign and with
seal under mandatory signing (vers=2.1, 3.0, 3.0.2 and 3.1.1; seal with
3.0 and 3.1.1), and with seal under mandatory encryption. Not tested:
Kerberos sessions (krb5_authenticate() gets the same change), SMB
Direct and multichannel binding.
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: require signing on sessions that negotiated encryption
ksmbd: reject plaintext requests on sessions that must be encrypted
ksmbd: refuse tree connect without a cipher when encryption is
mandatory
ksmbd: keep negotiated capabilities per connection
fs/smb/server/connection.h | 2 ++
fs/smb/server/mgmt/user_session.h | 2 ++
fs/smb/server/server.c | 14 ++++++++++++--
fs/smb/server/smb2ops.c | 19 +++++++++++++++----
fs/smb/server/smb2pdu.c | 16 ++++++++++++----
5 files changed, 43 insertions(+), 10 deletions(-)
base-commit: 267029b35ad1245a36d069cafe93b4ea654e0f81
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/4] ksmbd: require signing on sessions that negotiated encryption
2026-11-19 10:38 [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
@ 2026-11-19 10:38 ` RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 2/4] ksmbd: reject plaintext requests on sessions that must be encrypted RootSys GmbH Research
` (5 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-19 10:38 UTC (permalink / raw)
To: Namjae Jeon
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong,
mike.michalo, linux-cifs
ntlm_authenticate() and krb5_authenticate() clear sess->sign whenever
smb3_encryption_negotiated() is true, that is whenever the client
offered a cipher in NEGOTIATE. Offering a cipher does not mean the
client will encrypt: unless the server sets
SMB2_SESSION_FLAG_ENCRYPT_DATA, the client keeps sending plaintext
requests and signs them because signing is required.
__process_request() only refuses an unsigned plaintext request when
sess->sign is set, so on a server with "server signing = mandatory",
or for a client that sent SMB2_NEGOTIATE_SIGNING_REQUIRED, unsigned
plaintext requests are executed as soon as the client offered a
cipher. The Linux client always offers one, and so do current Windows
clients. An attacker on the path between client and server can then
inject requests that run with the victim's session and tree
connections, which mandatory signing is meant to prevent; commit
2bebf2470af1 ("ksmbd: enforce signing required by the session") closed
this only for sessions that did not negotiate encryption.
sess->sign_required already records that signing was required when
the session was set up. Use it in the request gate too.
Found with AI-assisted code review and testing.
Fixes: 2bebf2470af1 ("ksmbd: enforce signing required by the session")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/server.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 962f12e969ba..5d94a3683f7f 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -203,8 +203,12 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
}
signed_req = conn->ops->is_sign_req && conn->ops->is_sign_req(work, command);
- if (work->sess && work->sess->sign && !work->encrypted &&
- !signed_req) {
+ /*
+ * sess->sign is cleared once encryption is negotiated, even when the
+ * client does not encrypt, so check sess->sign_required as well.
+ */
+ if (work->sess && (work->sess->sign || work->sess->sign_required) &&
+ !work->encrypted && !signed_req) {
conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED);
return SERVER_HANDLER_ABORT;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/4] ksmbd: reject plaintext requests on sessions that must be encrypted
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 ` 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
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-19 10:38 UTC (permalink / raw)
To: Namjae Jeon
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong,
mike.michalo, linux-cifs
With "smb3 encryption = mandatory" ksmbd sets
SMB2_SESSION_FLAG_ENCRYPT_DATA in the SESSION_SETUP response of every
session that negotiated a cipher, so the client encrypts all further
requests. Nothing on the request path checks this, though: a plaintext
request on such a session is executed like an encrypted one. Since
sess->sign is cleared for these sessions, it does not even have to be
signed. The only encryption check on the request path is the one for
shares carrying KSMBD_SHARE_FLAG_ENCRYPT_DATA.
An attacker on the path can therefore inject plaintext, unsigned
requests into a session that both sides believe to be encrypted.
MS-SMB2 3.3.5.2.9 requires the server to fail such a request with
STATUS_ACCESS_DENIED.
Record in the session that it was told to encrypt and refuse
unencrypted requests on it.
Found with AI-assisted code review and testing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/mgmt/user_session.h | 2 ++
fs/smb/server/server.c | 6 ++++++
fs/smb/server/smb2pdu.c | 8 ++++++--
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/smb/server/mgmt/user_session.h b/fs/smb/server/mgmt/user_session.h
index 423f0a10315a..81960f3334b6 100644
--- a/fs/smb/server/mgmt/user_session.h
+++ b/fs/smb/server/mgmt/user_session.h
@@ -62,6 +62,8 @@ struct ksmbd_session {
/* signing was required at setup; sign is cleared with encryption */
bool sign_required;
bool enc;
+ /* the session was told to encrypt (SMB2_SESSION_FLAG_ENCRYPT_DATA) */
+ bool enc_required;
bool tearing_down;
int state;
diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 5d94a3683f7f..b7fa39200352 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -202,6 +202,12 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
return SERVER_HANDLER_ABORT;
}
+ /* MS-SMB2 3.3.5.2.9: a session that must encrypt takes no plaintext */
+ if (work->sess && work->sess->enc_required && !work->encrypted) {
+ conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED);
+ return SERVER_HANDLER_ABORT;
+ }
+
signed_req = conn->ops->is_sign_req && conn->ops->is_sign_req(work, command);
/*
* sess->sign is cleared once encryption is negotiated, even when the
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 29750970f8da..05af8f196b17 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2407,8 +2407,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
conn->ops->generate_encryptionkey(conn, sess);
sess->enc = true;
- if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION) {
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
+ sess->enc_required = true;
+ }
/*
* signing is disable if encryption is enable
* on this session
@@ -2513,8 +2515,10 @@ static int krb5_authenticate(struct ksmbd_work *work,
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
conn->ops->generate_encryptionkey(conn, sess);
sess->enc = true;
- if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION) {
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
+ sess->enc_required = true;
+ }
sess->sign = false;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/4] ksmbd: refuse tree connect without a cipher when encryption is mandatory
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 ` RootSys GmbH Research
2026-11-19 10:38 ` [PATCH 4/4] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-19 10:38 UTC (permalink / raw)
To: Namjae Jeon
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong,
mike.michalo, linux-cifs
ksmbd.conf(5) documents "smb3 encryption = mandatory" as "clients that
do not support encryption will be denied access to all shares". The
kernel does not do that: KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION only makes
the server advertise the capability and set
SMB2_SESSION_FLAG_ENCRYPT_DATA on sessions that negotiated a cipher. A
client that offers no cipher (SMB 2.1, or SMB 3.1.1 without an
encryption context) gets an ordinary plaintext session and can use
every share. That includes an attacker relaying a victim's NTLM
authentication, who chooses the NEGOTIATE contexts itself.
smb2_tree_connect() already refuses a connection without a negotiated
cipher for shares that carry KSMBD_SHARE_FLAG_ENCRYPT_DATA. Apply the
same check when encryption is mandatory for the whole server.
Found with AI-assisted code review and testing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/smb2pdu.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 05af8f196b17..9dc46553138d 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3120,8 +3120,12 @@ int smb2_tree_connect(struct ksmbd_work *work)
rsp->hdr.Id.SyncId.TreeId = cpu_to_le32(status.tree_conn->id);
share = status.tree_conn->share_conf;
- /* A share that requires encryption needs a negotiated SMB3 cipher. */
- if (test_share_config_flag(share, KSMBD_SHARE_FLAG_ENCRYPT_DATA) &&
+ /*
+ * A share that requires encryption, or a server configured with
+ * mandatory encryption, needs a negotiated SMB3 cipher.
+ */
+ if ((test_share_config_flag(share, KSMBD_SHARE_FLAG_ENCRYPT_DATA) ||
+ server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION) &&
!smb3_encryption_negotiated(conn)) {
ksmbd_tree_conn_disconnect(sess, status.tree_conn);
status.tree_conn = NULL;
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/4] ksmbd: keep negotiated capabilities per connection
2026-11-19 10:38 [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (2 preceding siblings ...)
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 ` RootSys GmbH Research
2026-11-19 12:51 ` [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests mixalhs
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-19 10:38 UTC (permalink / raw)
To: Namjae Jeon
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong,
mike.michalo, linux-cifs
init_smb2_1_server(), init_smb3_0_server(), init_smb3_02_server() and
init_smb3_11_server() point conn->vals at the static
smb21/smb30/smb302/smb311_server_values tables and then OR capability
bits into conn->vals->req_capabilities. Those bits therefore land in
the table shared by every connection of that dialect and are never
cleared, not even by restarting the server or changing its
configuration; later NEGOTIATE responses advertise them.
For SMB 3.0 and 3.0.2 this changes security decisions:
smb3_encryption_negotiated() tests req_capabilities, so once a single
client has offered SMB2_GLOBAL_CAP_ENCRYPTION, every later session of
that dialect is treated as having negotiated encryption, including
sessions of clients that never offered it. An attacker can trigger this
with one NEGOTIATE.
Give each connection its own copy of its dialect's table and set the
capability bits there.
Found with AI-assisted code review and testing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/connection.h | 2 ++
fs/smb/server/smb2ops.c | 19 +++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/fs/smb/server/connection.h b/fs/smb/server/connection.h
index 6855c1ab691e..127b5c2d0d9e 100644
--- a/fs/smb/server/connection.h
+++ b/fs/smb/server/connection.h
@@ -55,6 +55,8 @@ struct ksmbd_transport;
struct ksmbd_conn {
struct smb_version_values *vals;
+ /* this connection's copy of its dialect's values, see smb2ops.c */
+ struct smb_version_values vals_copy;
struct smb_version_ops *ops;
struct smb_version_cmds *cmds;
unsigned int max_cmds;
diff --git a/fs/smb/server/smb2ops.c b/fs/smb/server/smb2ops.c
index c5b3cf34494e..4a69c8832820 100644
--- a/fs/smb/server/smb2ops.c
+++ b/fs/smb/server/smb2ops.c
@@ -231,6 +231,17 @@ static struct smb_version_cmds smb2_0_server_cmds[NUMBER_OF_SMB2_COMMANDS] = {
[SMB2_CHANGE_NOTIFY_HE] = { .proc = smb2_notify},
};
+/*
+ * The capability bits depend on the client and the configuration, so set
+ * them on a copy owned by the connection instead of on the shared table.
+ */
+static void ksmbd_conn_init_vals(struct ksmbd_conn *conn,
+ const struct smb_version_values *vals)
+{
+ conn->vals_copy = *vals;
+ conn->vals = &conn->vals_copy;
+}
+
/**
* init_smb2_1_server() - initialize a smb server connection with smb2.1
* command dispatcher
@@ -238,7 +249,7 @@ static struct smb_version_cmds smb2_0_server_cmds[NUMBER_OF_SMB2_COMMANDS] = {
*/
void init_smb2_1_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb21_server_values;
+ ksmbd_conn_init_vals(conn, &smb21_server_values);
conn->ops = &smb2_0_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
@@ -255,7 +266,7 @@ void init_smb2_1_server(struct ksmbd_conn *conn)
*/
void init_smb3_0_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb30_server_values;
+ ksmbd_conn_init_vals(conn, &smb30_server_values);
conn->ops = &smb3_0_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
@@ -285,7 +296,7 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
*/
void init_smb3_02_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb302_server_values;
+ ksmbd_conn_init_vals(conn, &smb302_server_values);
conn->ops = &smb3_0_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
@@ -316,7 +327,7 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
*/
int init_smb3_11_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb311_server_values;
+ ksmbd_conn_init_vals(conn, &smb311_server_values);
conn->ops = &smb3_11_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests
2026-11-19 10:38 [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (3 preceding siblings ...)
2026-11-19 10:38 ` [PATCH 4/4] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
@ 2026-11-19 12:51 ` mixalhs
2026-11-19 13:44 ` RootSys GmbH Research
2026-11-19 17:29 ` Ian Bridges
2026-11-26 15:08 ` [PATCH v2 " RootSys GmbH Research
6 siblings, 1 reply; 13+ messages in thread
From: mixalhs @ 2026-11-19 12:51 UTC (permalink / raw)
To: RootSys GmbH Research
Cc: Namjae Jeon, Steve French, Sergey Senozhatsky, Tom Talpey,
ChenXiaoSong, linux-cifs
Hi,
I tested the series on top of ksmbd-for-next with the session setup
signing series: with "server signing = mandatory" an unsigned plaintext
request on a session that offered a cipher is now refused, with "smb3
encryption = mandatory" a plaintext request on a session told to
encrypt is refused, and a client that offers no cipher can no longer
tree connect. My binding, expired-session, compound, encryption, guest
and anonymous tests give the same results as without the series, the
Linux cifs client works, and there were no KASAN reports.
A few comments:
- Signed-off-by: submitting-patches.rst asks for "a known identity
(sorry, no anonymous contributions)", and I'm not sure a team name
counts, so it may be worth checking. Separately, From: is
team@rootsys.at but Signed-off-by is research@rootsys.at, which
checkpatch warns about.
- Patch 1 depends on sess->sign_required, which no stable tree has yet,
so the Cc: stable tags need a dependency note; patch 4 does not depend
on anything and could go first.
- Patch 3: MS-SMB2 3.3.5.5 fails the SESSION_SETUP itself with
STATUS_ACCESS_DENIED when encryption is required and the dialect is
2.x, or 3.x without SMB2_GLOBAL_CAP_ENCRYPTION, so a relayed login
would be stopped before authentication completes. On SMB 3.0 and
3.0.2 the tree connect check never triggers under mandatory
encryption, since init_smb3_0_server() and init_smb3_02_server() set
the capability unconditionally; patch 2 covers those instead.
- Patch 4: in the default "auto" mode the leaked capability gives a
later 3.0 client that offered no encryption sess->enc and clears
sess->sign, which is the hole patch 1 closes; that may be worth
saying in the commit message.
- A signed but plaintext SESSION_SETUP reauthentication is still
accepted on a session that was told to encrypt. Should it be refused?
MS-SMB2 3.3.5.2.9 fails an unencrypted request on such a session, but
I could not find text saying whether that applies to SESSION_SETUP.
Only the session's owner can sign it, so it is minor either way.
Tested-by: Michail Andreas Michalopoulos <mike.michalo@gmail.com>
Thanks,
Michail
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests
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
0 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-19 13:44 UTC (permalink / raw)
To: Michail Andreas Michalopoulos
Cc: Namjae Jeon, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong,
linux-cifs
Hi Michail,
thanks a lot for testing this and for the detailed review.
> - Signed-off-by: submitting-patches.rst asks for "a known identity
> (sorry, no anonymous contributions)", and I'm not sure a team name
> counts, so it may be worth checking. Separately, From: is
> team@rootsys.at but Signed-off-by is research@rootsys.at, which
> checkpatch warns about.
RootSys GmbH Research is the security research team of RootSys GmbH
in Innsbruck, Austria, and research@rootsys.at is the team's address.
If that does not work for the tree, please let us know.
The From: mismatch is our mail setup: research@rootsys.at is our alias
for research, pointing to the team@rootsys.at mailbox on Google
Workspace, and Gmail rewrote the header when the series went out
through that mailbox. Both addresses reach the same people. v2 will
carry an in-body From: so the author matches the Signed-off-by.
> - Patch 1 depends on sess->sign_required, which no stable tree has yet,
> so the Cc: stable tags need a dependency note; patch 4 does not depend
> on anything and could go first.
Agreed, v2 moves the capability patch to the front and adds the
dependency note to the stable tag of the signing patch.
> - Patch 3: MS-SMB2 3.3.5.5 fails the SESSION_SETUP itself with
> STATUS_ACCESS_DENIED when encryption is required and the dialect is
> 2.x, or 3.x without SMB2_GLOBAL_CAP_ENCRYPTION, so a relayed login
> would be stopped before authentication completes. On SMB 3.0 and
> 3.0.2 the tree connect check never triggers under mandatory
> encryption, since init_smb3_0_server() and init_smb3_02_server() set
> the capability unconditionally; patch 2 covers those instead.
Good point, failing the SESSION_SETUP is better than catching it at tree
connect. v2 does the check there as 3.3.5.5 describes and says in the
changelog that 3.0/3.0.2 are covered by the plaintext request check.
> - Patch 4: in the default "auto" mode the leaked capability gives a
> later 3.0 client that offered no encryption sess->enc and clears
> sess->sign, which is the hole patch 1 closes; that may be worth
> saying in the commit message.
Will add that.
> - A signed but plaintext SESSION_SETUP reauthentication is still
> accepted on a session that was told to encrypt. Should it be refused?
> MS-SMB2 3.3.5.2.9 fails an unencrypted request on such a session, but
> I could not find text saying whether that applies to SESSION_SETUP.
> Only the session's owner can sign it, so it is minor either way.
We didn't find anything explicit either. Since it has to be signed by
the session owner, we'd leave it as it is in this series, unless Namjae
prefers to have it refused as well.
v2 follows in a day or two, once it has been through the same tests
again.
Thanks,
RootSys GmbH Research
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests
2026-11-19 10:38 [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (4 preceding siblings ...)
2026-11-19 12:51 ` [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests mixalhs
@ 2026-11-19 17:29 ` Ian Bridges
2026-11-26 15:08 ` [PATCH v2 " RootSys GmbH Research
6 siblings, 0 replies; 13+ messages in thread
From: Ian Bridges @ 2026-11-19 17:29 UTC (permalink / raw)
To: team
Cc: linkinjeon, senozhatsky, tom, chenxiaosong, mike.michalo,
linux-cifs, Ian Bridges
Hi,
I tested the series on ksmbd-for-next 4616bbc5389a with KASAN. I used my
own probes, smbclient, smbtorture, the Linux cifs client and a Windows
11 client. I compared the series with the unpatched head under four
server configurations. The first kept the default settings. The second
made signing mandatory. The third made encryption mandatory. The fourth
made both mandatory.
My probes negotiated SMB 2.1, 3.0, 3.0.2 and 3.1.1, with and without
encryption support. They sent TREE_CONNECT in plaintext, signed and
encrypted. NTLM sessions ran in all four configurations. Kerberos
sessions on 3.0 and 3.1.1 ran in the two configurations with mandatory
encryption. With the series, ksmbd refuses unsigned plaintext requests
on sessions that require signing and negotiated a cipher. It refuses
plaintext requests on sessions told to encrypt, and tree connects
without a cipher when encryption is mandatory. A 3.0 or 3.0.2 client no
longer sees an encryption capability that only an earlier client
offered. Encrypted requests get the same results as without the series,
and so do signed requests on sessions that are not told to encrypt.
Linux client file operations matched those without the series in all
four configurations. The mounts used SMB 2.1, 3.0, 3.0.2 and 3.1.1, each
without sign or seal, with the sign option and with the seal option. The
only difference was the expected SMB 2.1 refusal when encryption is
mandatory. With encryption mandatory, I also tested SMB 3.1.1
multichannel and Kerberos mounts on SMB 3.0 and 3.1.1. One Kerberos
mount was still in use after its ticket expired. Windows 11 mapped a
share and copied, listed and deleted files in all four configurations.
The smbtorture subset I ran gave the same results with and without the
series in each configuration, including one test that times out in both
cases. smbclient also gave the same results, apart from the same SMB 2.1
refusal. No KASAN reports were recorded.
This review leaves out the issues that Sashiko and Michail have already
raised. Apart from those, I found one response-handling issue in the
new rejection path in patch 2. Only a client that sends plaintext on a
session that must encrypt reaches it.
> + /* MS-SMB2 3.3.5.2.9: a session that must encrypt takes no plaintext */
> + if (work->sess && work->sess->enc_required && !work->encrypted) {
> + conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED);
> + return SERVER_HANDLER_ABORT;
> + }
An unsigned plaintext SMB2 CANCEL for a request that is not pending now
gets a STATUS_ACCESS_DENIED response. Without the series it gets no
response, as MS-SMB2 3.3.5.16 requires. That section verifies the
session only for a signed CANCEL.
Thanks,
Ian
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 0/4] ksmbd: enforce mandatory signing and encryption on requests
2026-11-19 10:38 [PATCH 0/4] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (5 preceding siblings ...)
2026-11-19 17:29 ` Ian Bridges
@ 2026-11-26 15:08 ` RootSys GmbH Research
2026-11-26 15:08 ` [PATCH v2 1/4] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
` (3 more replies)
6 siblings, 4 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-26 15:08 UTC (permalink / raw)
To: Namjae Jeon
Cc: Michail Andreas Michalopoulos, Ian Bridges, Sergey Senozhatsky,
Tom Talpey, ChenXiaoSong, linux-cifs, RootSys GmbH Research
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
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/4] ksmbd: keep negotiated capabilities per connection
2026-11-26 15:08 ` [PATCH v2 " RootSys GmbH Research
@ 2026-11-26 15:08 ` RootSys GmbH Research
2026-11-26 15:08 ` [PATCH v2 2/4] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-26 15:08 UTC (permalink / raw)
To: Namjae Jeon
Cc: Michail Andreas Michalopoulos, Ian Bridges, Sergey Senozhatsky,
Tom Talpey, ChenXiaoSong, linux-cifs, RootSys GmbH Research
From: RootSys GmbH Research <research@rootsys.at>
init_smb2_1_server(), init_smb3_0_server(), init_smb3_02_server() and
init_smb3_11_server() point conn->vals at the static
smb21/smb30/smb302/smb311_server_values tables and then OR capability
bits into conn->vals->req_capabilities. Those bits therefore land in
the table shared by every connection of that dialect and are never
cleared, not even by restarting the server or changing its
configuration; later NEGOTIATE responses advertise them.
For SMB 3.0 and 3.0.2 this changes security decisions:
smb3_encryption_negotiated() tests req_capabilities, so once a single
client has offered SMB2_GLOBAL_CAP_ENCRYPTION, every later session of
that dialect is treated as having negotiated encryption, including
sessions of clients that never offered it. An attacker can trigger this
with one NEGOTIATE.
In the default "smb3 encryption = auto" mode, such a later SMB 3.0
client that offered no encryption gets sess->enc set and sess->sign
cleared in SESSION_SETUP, but is not told to encrypt. With mandatory
signing, its unsigned plaintext requests then pass __process_request(),
which only checks sess->sign. That is the gap "ksmbd: require signing
on sessions that negotiated encryption" closes for clients that do
offer a cipher; here it opens for a client that never did.
Give each connection its own copy of its dialect's table and set the
capability bits there.
Found with AI-assisted code review and testing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Tested-by: Michail Andreas Michalopoulos <mike.michalo@gmail.com>
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/connection.h | 2 ++
fs/smb/server/smb2ops.c | 19 +++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/fs/smb/server/connection.h b/fs/smb/server/connection.h
index 891612382d0f..adddcda735c6 100644
--- a/fs/smb/server/connection.h
+++ b/fs/smb/server/connection.h
@@ -55,6 +55,8 @@ struct ksmbd_transport;
struct ksmbd_conn {
struct smb_version_values *vals;
+ /* this connection's copy of its dialect's values, see smb2ops.c */
+ struct smb_version_values vals_copy;
struct smb_version_ops *ops;
struct smb_version_cmds *cmds;
unsigned int max_cmds;
diff --git a/fs/smb/server/smb2ops.c b/fs/smb/server/smb2ops.c
index c5b3cf34494e..4a69c8832820 100644
--- a/fs/smb/server/smb2ops.c
+++ b/fs/smb/server/smb2ops.c
@@ -231,6 +231,17 @@ static struct smb_version_cmds smb2_0_server_cmds[NUMBER_OF_SMB2_COMMANDS] = {
[SMB2_CHANGE_NOTIFY_HE] = { .proc = smb2_notify},
};
+/*
+ * The capability bits depend on the client and the configuration, so set
+ * them on a copy owned by the connection instead of on the shared table.
+ */
+static void ksmbd_conn_init_vals(struct ksmbd_conn *conn,
+ const struct smb_version_values *vals)
+{
+ conn->vals_copy = *vals;
+ conn->vals = &conn->vals_copy;
+}
+
/**
* init_smb2_1_server() - initialize a smb server connection with smb2.1
* command dispatcher
@@ -238,7 +249,7 @@ static struct smb_version_cmds smb2_0_server_cmds[NUMBER_OF_SMB2_COMMANDS] = {
*/
void init_smb2_1_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb21_server_values;
+ ksmbd_conn_init_vals(conn, &smb21_server_values);
conn->ops = &smb2_0_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
@@ -255,7 +266,7 @@ void init_smb2_1_server(struct ksmbd_conn *conn)
*/
void init_smb3_0_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb30_server_values;
+ ksmbd_conn_init_vals(conn, &smb30_server_values);
conn->ops = &smb3_0_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
@@ -285,7 +296,7 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
*/
void init_smb3_02_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb302_server_values;
+ ksmbd_conn_init_vals(conn, &smb302_server_values);
conn->ops = &smb3_0_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
@@ -316,7 +327,7 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
*/
int init_smb3_11_server(struct ksmbd_conn *conn)
{
- conn->vals = &smb311_server_values;
+ ksmbd_conn_init_vals(conn, &smb311_server_values);
conn->ops = &smb3_11_server_ops;
conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/4] ksmbd: require signing on sessions that negotiated encryption
2026-11-26 15:08 ` [PATCH v2 " RootSys GmbH Research
2026-11-26 15:08 ` [PATCH v2 1/4] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
@ 2026-11-26 15:08 ` 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
3 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-26 15:08 UTC (permalink / raw)
To: Namjae Jeon
Cc: Michail Andreas Michalopoulos, Ian Bridges, Sergey Senozhatsky,
Tom Talpey, ChenXiaoSong, linux-cifs, RootSys GmbH Research
From: RootSys GmbH Research <research@rootsys.at>
ntlm_authenticate() and krb5_authenticate() clear sess->sign whenever
smb3_encryption_negotiated() is true, that is whenever the client
offered a cipher in NEGOTIATE. Offering a cipher does not mean the
client will encrypt: unless the server sets
SMB2_SESSION_FLAG_ENCRYPT_DATA, the client keeps sending plaintext
requests and signs them because signing is required.
__process_request() only refuses an unsigned plaintext request when
sess->sign is set, so on a server with "server signing = mandatory",
or for a client that sent SMB2_NEGOTIATE_SIGNING_REQUIRED, unsigned
plaintext requests are executed as soon as the client offered a
cipher. The Linux client always offers one, and so do current Windows
clients. An attacker on the path between client and server can then
inject requests that run with the victim's session and tree
connections, which mandatory signing is meant to prevent; commit
2bebf2470af1 ("ksmbd: enforce signing required by the session") closed
this only for sessions that did not negotiate encryption.
sess->sign_required already records that signing was required when
the session was set up. Use it in the request gate too.
Found with AI-assisted code review and testing.
Fixes: 2bebf2470af1 ("ksmbd: enforce signing required by the session")
Cc: stable@vger.kernel.org # 7.2.x: 16ab0adace8f: ksmbd: verify the signature of session binding requests
Cc: stable@vger.kernel.org # 7.2.x: 42a1d80e64a3: ksmbd: sign with the negotiated SMB 3.1.1 signing algorithm
Cc: stable@vger.kernel.org # 7.2.x: ea472ddf7a9a: ksmbd: use the channel signing key for session setup on a bound channel
Cc: stable@vger.kernel.org # 7.2.x
Tested-by: Michail Andreas Michalopoulos <mike.michalo@gmail.com>
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/server.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 962f12e969ba..5d94a3683f7f 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -203,8 +203,12 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
}
signed_req = conn->ops->is_sign_req && conn->ops->is_sign_req(work, command);
- if (work->sess && work->sess->sign && !work->encrypted &&
- !signed_req) {
+ /*
+ * sess->sign is cleared once encryption is negotiated, even when the
+ * client does not encrypt, so check sess->sign_required as well.
+ */
+ if (work->sess && (work->sess->sign || work->sess->sign_required) &&
+ !work->encrypted && !signed_req) {
conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED);
return SERVER_HANDLER_ABORT;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 3/4] ksmbd: reject plaintext requests on sessions that must be encrypted
2026-11-26 15:08 ` [PATCH v2 " RootSys GmbH Research
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 ` 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
3 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-26 15:08 UTC (permalink / raw)
To: Namjae Jeon
Cc: Michail Andreas Michalopoulos, Ian Bridges, Sergey Senozhatsky,
Tom Talpey, ChenXiaoSong, linux-cifs, RootSys GmbH Research
From: RootSys GmbH Research <research@rootsys.at>
With "smb3 encryption = mandatory" ksmbd sets
SMB2_SESSION_FLAG_ENCRYPT_DATA in the SESSION_SETUP response of every
session that negotiated a cipher, so the client encrypts all further
requests. Nothing on the request path checks this, though: a plaintext
request on such a session is executed like an encrypted one. Since
sess->sign is cleared for these sessions, it does not even have to be
signed. The only encryption check on the request path is the one for
shares carrying KSMBD_SHARE_FLAG_ENCRYPT_DATA.
An attacker on the path can therefore inject plaintext, unsigned
requests into a session that both sides believe to be encrypted.
MS-SMB2 3.3.5.2.9 requires the server to fail such a request with
STATUS_ACCESS_DENIED.
Record in the session that it was told to encrypt and refuse
unencrypted requests on it with STATUS_ACCESS_DENIED where the session
is verified, before the tree connect is looked up, in the order of
MS-SMB2 3.3.5.2.9. SESSION_SETUP is left to smb2_sess_setup(), which
checks the session it reauthenticates, and an ECHO without a SessionId
is not verified (3.3.5.17). A plaintext SMB2 CANCEL on such a session
is dropped without a response: 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 response to a reauthentication did not carry
SMB2_SESSION_FLAG_ENCRYPT_DATA; set it there too, as 3.3.5.5.3
requires, so that a client that takes its session flags from that
response keeps encrypting.
Found with AI-assisted code review and testing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/mgmt/user_session.h | 2 ++
fs/smb/server/server.c | 33 ++++++++++++++++++++++++++++++-
fs/smb/server/smb2pdu.c | 14 +++++++++++--
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/fs/smb/server/mgmt/user_session.h b/fs/smb/server/mgmt/user_session.h
index 423f0a10315a..81960f3334b6 100644
--- a/fs/smb/server/mgmt/user_session.h
+++ b/fs/smb/server/mgmt/user_session.h
@@ -62,6 +62,8 @@ struct ksmbd_session {
/* signing was required at setup; sign is cleared with encryption */
bool sign_required;
bool enc;
+ /* the session was told to encrypt (SMB2_SESSION_FLAG_ENCRYPT_DATA) */
+ bool enc_required;
bool tearing_down;
int state;
diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 5d94a3683f7f..8d1ad6495e35 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -245,6 +245,22 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
return SERVER_HANDLER_CONTINUE;
}
+/*
+ * MS-SMB2 3.3.5.2.9: a session that must encrypt takes no plaintext request.
+ * SESSION_SETUP checks its own session in smb2_sess_setup(), and an ECHO
+ * without a SessionId is not verified (3.3.5.17).
+ */
+static bool ksmbd_plaintext_refused(struct ksmbd_work *work, u16 cmd)
+{
+ struct smb2_hdr *hdr = ksmbd_req_buf_next(work);
+
+ if (!work->sess || !work->sess->enc_required || work->encrypted)
+ return false;
+ if (cmd == SMB2_SESSION_SETUP_HE)
+ return false;
+ return cmd != SMB2_ECHO_HE || le64_to_cpu(hdr->SessionId);
+}
+
static void __handle_ksmbd_work(struct ksmbd_work *work,
struct ksmbd_conn *conn)
{
@@ -371,7 +387,22 @@ static void __handle_ksmbd_work(struct ksmbd_work *work,
rsp_hdr->Flags |= SMB2_FLAGS_SIGNED;
}
goto send;
- } else if (rc > 0) {
+ }
+ /*
+ * Before the tree connect is looked up, so that a
+ * plaintext request learns nothing about its TreeId.
+ * A CANCEL is never answered (MS-SMB2 3.3.5.16).
+ */
+ command = conn->ops->get_cmd_val(work);
+ if (ksmbd_plaintext_refused(work, command)) {
+ if (command == SMB2_CANCEL_HE)
+ work->send_no_response = 1;
+ else
+ conn->ops->set_rsp_status(work,
+ STATUS_ACCESS_DENIED);
+ goto send;
+ }
+ if (rc > 0) {
rc = conn->ops->get_ksmbd_tcon(work);
if (rc < 0) {
if (rc == -EINVAL)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 5a7842264b98..a133437b94ab 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2419,8 +2419,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
conn->ops->generate_encryptionkey(conn, sess);
sess->enc = true;
- if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION) {
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
+ sess->enc_required = true;
+ }
/*
* signing is disable if encryption is enable
* on this session
@@ -2525,8 +2527,10 @@ static int krb5_authenticate(struct ksmbd_work *work,
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
conn->ops->generate_encryptionkey(conn, sess);
sess->enc = true;
- if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION) {
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
+ sess->enc_required = true;
+ }
sess->sign = false;
}
@@ -3052,6 +3056,12 @@ int smb2_sess_setup(struct ksmbd_work *work)
}
if (authenticated) {
+ /*
+ * MS-SMB2 3.3.5.5.3: the response to a reauthentication tells
+ * the client to keep encrypting, too.
+ */
+ if (sess->enc_required && !work->session_setup_binding)
+ rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
/*
* Draining the previous session drops srv_mutex. Finish using the
* connection's authentication state and free mechToken first, and
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 4/4] ksmbd: refuse session setup without encryption when it is mandatory
2026-11-26 15:08 ` [PATCH v2 " RootSys GmbH Research
` (2 preceding siblings ...)
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 ` RootSys GmbH Research
3 siblings, 0 replies; 13+ messages in thread
From: RootSys GmbH Research @ 2026-11-26 15:08 UTC (permalink / raw)
To: Namjae Jeon
Cc: Michail Andreas Michalopoulos, Ian Bridges, Sergey Senozhatsky,
Tom Talpey, ChenXiaoSong, linux-cifs, RootSys GmbH Research
From: RootSys GmbH Research <research@rootsys.at>
ksmbd.conf(5) documents "smb3 encryption = mandatory" as "clients that
do not support encryption will be denied access to all shares". The
kernel does not do that: KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION only makes
the server advertise the capability and set
SMB2_SESSION_FLAG_ENCRYPT_DATA on sessions that negotiated encryption.
A client that cannot encrypt (SMB 2.1, or SMB 3.1.1 without an
encryption context) gets an ordinary plaintext session and can use
every share. That includes an attacker relaying a victim's NTLM
authentication, who chooses the dialect and NEGOTIATE contexts itself.
MS-SMB2 3.3.5.5 stops such a client at SESSION_SETUP, before it
authenticates:
If the server implements the SMB 3.x dialect family,
Connection.Dialect does not belong to the SMB 3.x dialect family,
EncryptData is TRUE, and RejectUnencryptedAccess is TRUE, the server
MUST fail the request with STATUS_ACCESS_DENIED.
If Connection.Dialect belongs to the SMB 3.x dialect family,
EncryptData is TRUE, RejectUnencryptedAccess is TRUE, and
Connection.ClientCapabilities does not include the
SMB2_GLOBAL_CAP_ENCRYPTION bit, the server MUST fail the request with
STATUS_ACCESS_DENIED.
Do the same: when encryption is mandatory, fail every SESSION_SETUP
with STATUS_ACCESS_DENIED on a connection that has not negotiated
encryption, that is SMB 2.x, or SMB 3.1.1 without a common cipher.
On SMB 3.0 and 3.0.2 this check does not trigger:
init_smb3_0_server() and init_smb3_02_server() set
SMB2_GLOBAL_CAP_ENCRYPTION unconditionally when encryption is
mandatory, so every such session is told to encrypt, whatever the
client offered, and "ksmbd: reject plaintext requests on sessions that
must be encrypted" refuses its plaintext requests.
Found with AI-assisted code review and testing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/smb2pdu.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index a133437b94ab..a0dfe13894ba 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2658,6 +2658,17 @@ int smb2_sess_setup(struct ksmbd_work *work)
rsp->SecurityBufferLength = 0;
ksmbd_conn_lock(conn);
+ /*
+ * MS-SMB2 3.3.5.5: when encryption is mandatory, a connection that
+ * cannot encrypt gets no session. SMB 3.0 and 3.0.2 connections always
+ * negotiate encryption then, see init_smb3_0_server().
+ */
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION &&
+ !smb3_encryption_negotiated(conn)) {
+ rc = -EKEYREJECTED;
+ goto out_err;
+ }
+
if (!req->hdr.SessionId) {
/* Bound abandoned SessionId-zero authentication exchanges. */
if (ksmbd_too_many_session_setups(conn)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-26 15:08 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 " RootSys GmbH Research
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox