* [PATCH v3 1/5] ksmbd: keep negotiated capabilities per connection
2026-12-04 6:53 [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
@ 2026-12-04 6:53 ` RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 2/5] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: RootSys GmbH Research @ 2026-12-04 6:53 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] 8+ messages in thread* [PATCH v3 2/5] ksmbd: require signing on sessions that negotiated encryption
2026-12-04 6:53 [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 1/5] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
@ 2026-12-04 6:53 ` RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 3/5] ksmbd: refuse a binding request without a SessionId RootSys GmbH Research
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: RootSys GmbH Research @ 2026-12-04 6:53 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: e1b357794105: ksmbd: verify the signature of session binding requests
Cc: stable@vger.kernel.org # 7.2.x: 9834c8c44feb: ksmbd: sign with the negotiated SMB 3.1.1 signing algorithm
Cc: stable@vger.kernel.org # 7.2.x: 4e23a40e3e69: 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 a376e2bed59b..74851291b9b2 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] 8+ messages in thread* [PATCH v3 3/5] ksmbd: refuse a binding request without a SessionId
2026-12-04 6:53 [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 1/5] ksmbd: keep negotiated capabilities per connection RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 2/5] ksmbd: require signing on sessions that negotiated encryption RootSys GmbH Research
@ 2026-12-04 6:53 ` RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 4/5] ksmbd: reject plaintext requests on sessions that must be encrypted RootSys GmbH Research
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: RootSys GmbH Research @ 2026-12-04 6:53 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>
smb2_sess_setup() handles a SESSION_SETUP with SessionId 0 as the start
of a new session and clears conn->binding, whatever its Flags say. The
authentication paths, though, decide whether to derive encryption keys
from the request's SMB2_SESSION_REQ_FLAG_BINDING bit. A request with
SessionId 0 and that bit set therefore sets up a new session without
encryption keys: sess->enc stays false, and with "smb3 encryption =
mandatory" the response does not carry SMB2_SESSION_FLAG_ENCRYPT_DATA.
A client, or an attacker relaying a client's NTLM authentication, gets
a plaintext session from a server that requires encryption.
A binding request always names the session it binds to (MS-SMB2
3.2.4.2.3, 3.3.5.5). Fail one without a SessionId with
STATUS_INVALID_PARAMETER, as Samba does, and use conn->binding in
ntlm_authenticate() and krb5_authenticate(), which is what the rest of
both functions already looks at.
Found with AI-assisted code review and testing.
Fixes: f5a544e3bab7 ("ksmbd: add support for SMB3 multichannel")
Cc: stable@vger.kernel.org
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/smb2pdu.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 0e0946bd5684..589155469134 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2415,8 +2415,7 @@ static int ntlm_authenticate(struct ksmbd_work *work,
sess->sign_required = true;
}
- if (smb3_encryption_negotiated(conn) &&
- !(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
+ if (smb3_encryption_negotiated(conn) && !conn->binding) {
conn->ops->generate_encryptionkey(conn, sess);
sess->enc = true;
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
@@ -2521,8 +2520,7 @@ static int krb5_authenticate(struct ksmbd_work *work,
sess->sign_required = true;
}
- if (smb3_encryption_negotiated(conn) &&
- !(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
+ if (smb3_encryption_negotiated(conn) && !conn->binding) {
conn->ops->generate_encryptionkey(conn, sess);
sess->enc = true;
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
@@ -2654,6 +2652,15 @@ int smb2_sess_setup(struct ksmbd_work *work)
rsp->SecurityBufferLength = 0;
ksmbd_conn_lock(conn);
+ /*
+ * A binding request names the session it binds to. Without one, the
+ * request would set up a new session as if it were binding, skipping
+ * the encryption setup.
+ */
+ if (!req->hdr.SessionId && req->Flags & SMB2_SESSION_REQ_FLAG_BINDING) {
+ rc = -EINVAL;
+ 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] 8+ messages in thread* [PATCH v3 4/5] ksmbd: reject plaintext requests on sessions that must be encrypted
2026-12-04 6:53 [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (2 preceding siblings ...)
2026-12-04 6:53 ` [PATCH v3 3/5] ksmbd: refuse a binding request without a SessionId RootSys GmbH Research
@ 2026-12-04 6:53 ` RootSys GmbH Research
2026-12-04 6:53 ` [PATCH v3 5/5] ksmbd: refuse session setup without encryption when it is mandatory RootSys GmbH Research
2026-12-04 10:04 ` [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests mixalhs
5 siblings, 0 replies; 8+ messages in thread
From: RootSys GmbH Research @ 2026-12-04 6:53 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.
A refused request is otherwise handled like one on a failed session in
__handle_ksmbd_work(): it is verified first, which consumes its
MessageId, and its credits are charged and new ones granted, so that
refused requests neither pin the command sequence window nor use up the
client's credits.
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 # 7.3.x: ac68edfa99c7: ksmbd: consume the sequence number of a request on a failed session
Cc: stable@vger.kernel.org # 7.3.x: 332ac50e7533: ksmbd: account for the credits of a request on a failed session
Cc: stable@vger.kernel.org # 7.3.x
Signed-off-by: RootSys GmbH Research <research@rootsys.at>
---
fs/smb/server/mgmt/user_session.h | 2 ++
fs/smb/server/server.c | 43 ++++++++++++++++++++++++++++++-
fs/smb/server/smb2pdu.c | 14 ++++++++--
3 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/fs/smb/server/mgmt/user_session.h b/fs/smb/server/mgmt/user_session.h
index e494da25da2c..f8e4ee501cb9 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 74851291b9b2..3f952baea1d4 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,32 @@ 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.
+ * As for a failed session above, consume the MessageId
+ * and settle the credits. 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 (ksmbd_verify_smb_message(work)) {
+ conn->ops->set_rsp_status(work,
+ STATUS_INVALID_PARAMETER);
+ goto send;
+ }
+ if (command == SMB2_CANCEL_HE)
+ work->send_no_response = 1;
+ else
+ conn->ops->set_rsp_status(work,
+ STATUS_ACCESS_DENIED);
+ if (ksmbd_set_failed_rsp_credits(work))
+ conn->ops->set_rsp_status(work,
+ STATUS_INVALID_PARAMETER);
+ 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 589155469134..02474030f211 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2418,8 +2418,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,
if (smb3_encryption_negotiated(conn) && !conn->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
@@ -2523,8 +2525,10 @@ static int krb5_authenticate(struct ksmbd_work *work,
if (smb3_encryption_negotiated(conn) && !conn->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;
}
@@ -3059,6 +3063,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] 8+ messages in thread* [PATCH v3 5/5] ksmbd: refuse session setup without encryption when it is mandatory
2026-12-04 6:53 [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (3 preceding siblings ...)
2026-12-04 6:53 ` [PATCH v3 4/5] ksmbd: reject plaintext requests on sessions that must be encrypted RootSys GmbH Research
@ 2026-12-04 6:53 ` RootSys GmbH Research
2026-12-04 10:04 ` [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests mixalhs
5 siblings, 0 replies; 8+ messages in thread
From: RootSys GmbH Research @ 2026-12-04 6:53 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 SMB 2.x, on SMB 3.0 and 3.0.2 when the
client's NEGOTIATE did not offer SMB2_GLOBAL_CAP_ENCRYPTION, and on SMB
3.1.1 when no common cipher was negotiated. smb3_encryption_negotiated()
cannot be used for this: init_smb3_0_server() and init_smb3_02_server()
set SMB2_GLOBAL_CAP_ENCRYPTION in the server's capabilities
unconditionally when encryption is mandatory, so it holds on SMB 3.0
and 3.0.2 whatever the client offered.
A guest session cannot be encrypted either: no session key comes out
of a guest login, and 3.3.5.5.3 derives encryption keys only for a
session that is neither anonymous nor guest. ksmbd still derived them,
from an all-zero session key, and replaced SMB2_SESSION_FLAG_IS_GUEST
with SMB2_SESSION_FLAG_ENCRYPT_DATA in the response. Fail a guest login
with STATUS_ACCESS_DENIED when encryption is mandatory, as Samba does.
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 | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 02474030f211..51d7b6357ebc 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -1689,6 +1689,21 @@ bool smb3_encryption_negotiated(struct ksmbd_conn *conn)
conn->cipher_type;
}
+/*
+ * smb3_encryption_negotiated() also holds on SMB 3.0 and 3.0.2 when only the
+ * server set SMB2_GLOBAL_CAP_ENCRYPTION, as it does when encryption is
+ * mandatory. Whether the client can encrypt is in its own capabilities, and
+ * on SMB 3.1.1 in the cipher both sides agreed on.
+ */
+static bool smb3_client_can_encrypt(struct ksmbd_conn *conn)
+{
+ if (conn->dialect == SMB311_PROT_ID)
+ return conn->cipher_type;
+ if (conn->dialect >= SMB30_PROT_ID)
+ return conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION;
+ return false;
+}
+
static __le32 decode_compress_ctxt(struct ksmbd_conn *conn,
struct smb2_compression_capabilities_context *pneg_ctxt,
int ctxt_len)
@@ -2376,6 +2391,12 @@ static int ntlm_authenticate(struct ksmbd_work *work,
}
if (conn->binding == false && user_guest(sess->user)) {
+ /*
+ * A guest session has no session key to derive encryption
+ * keys from (MS-SMB2 3.3.5.5.3), so it cannot be encrypted.
+ */
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+ return -EKEYREJECTED;
rsp->SessionFlags = SMB2_SESSION_FLAG_IS_GUEST_LE;
} else {
struct authenticate_message *authblob;
@@ -2656,6 +2677,16 @@ 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 client that cannot
+ * encrypt gets no session.
+ */
+ if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION &&
+ !smb3_client_can_encrypt(conn)) {
+ rc = -EKEYREJECTED;
+ goto out_err;
+ }
+
/*
* A binding request names the session it binds to. Without one, the
* request would set up a new session as if it were binding, skipping
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests
2026-12-04 6:53 [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests RootSys GmbH Research
` (4 preceding siblings ...)
2026-12-04 6:53 ` [PATCH v3 5/5] ksmbd: refuse session setup without encryption when it is mandatory RootSys GmbH Research
@ 2026-12-04 10:04 ` mixalhs
2026-12-04 10:54 ` RootSys GmbH Research
5 siblings, 1 reply; 8+ messages in thread
From: mixalhs @ 2026-12-04 10:04 UTC (permalink / raw)
To: RootSys GmbH Research
Cc: Namjae Jeon, Ian Bridges, Sergey Senozhatsky, Tom Talpey,
ChenXiaoSong, linux-cifs, RootSys GmbH Research
Hi,
> - 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.
[...]
> On every other path that reaches them, conn->binding and the bit
> agree.
I don't think they always agree. The branch in smb2_sess_setup() that
refuses a binding request is:
} else if ((conn->dialect < SMB30_PROT_ID ||
server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL) &&
(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
With multichannel enabled, the branch above it already takes an SMB 3.x
binding request, so this one only catches SMB 2.x. On SMB 3.x with
"server multi channel support = no", the default in ksmbd.conf(5), a
request with the binding bit and a non-zero SessionId falls through to
the last branch with conn->binding false. That includes the
AUTHENTICATE leg of an ordinary NTLM login, whose SessionId is the
pending session from the first leg, so nothing has to fail first.
I checked this with "smb3 encryption = mandatory", NTLM over SMB 3.1.1:
- mainline 007722b8211f, multichannel off, binding bit set on the
AUTHENTICATE leg: the response has SessionFlags 0; without the bit
it carries SMB2_SESSION_FLAG_ENCRYPT_DATA
- multichannel on: the same request fails with
STATUS_INVALID_PARAMETER
- 007722b8211f with patch 3 applied by hand (its auth-path hunks
need fuzz without the ksmbd-for-next commits), multichannel off:
the response carries SMB2_SESSION_FLAG_ENCRYPT_DATA
So patch 3 already closes this through the switch to conn->binding.
Without that switch, patch 4 would not set sess->enc_required on such
a session and would still take plaintext requests on it. Could the
commit message and the cover letter describe this case as well, and
could your tests cover it? It needs only the default multichannel
setting, so it is the more likely of the two.
The condition itself looks like it was meant to test
!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL). It may be
worth fixing separately, since the error path in smb2_sess_setup() also
goes by the bit: a failed request that carries it without binding is
neither unpublished nor expired, so its pending session stays.
Minor: between patches 4 and 5, a guest login under mandatory
encryption gets sess->enc_required set, with keys derived from a zero
session key, until patch 5 refuses it. It is not a regression, but
moving the guest check before patch 4 would avoid that state.
Thanks,
Michail
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests
2026-12-04 10:04 ` [PATCH v3 0/5] ksmbd: enforce mandatory signing and encryption on requests mixalhs
@ 2026-12-04 10:54 ` RootSys GmbH Research
0 siblings, 0 replies; 8+ messages in thread
From: RootSys GmbH Research @ 2026-12-04 10:54 UTC (permalink / raw)
To: Michail Andreas Michalopoulos
Cc: RootSys GmbH Research, Namjae Jeon, Ian Bridges,
Sergey Senozhatsky, Tom Talpey, ChenXiaoSong, linux-cifs
From: RootSys GmbH Research <research@rootsys.at>
Hi Michail,
thanks, and you are right about mainline.
> I don't think they always agree. The branch in smb2_sess_setup() that
> refuses a binding request is:
> } else if ((conn->dialect < SMB30_PROT_ID ||
> server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL) &&
> (req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
> [...] On SMB 3.x with "server multi channel support = no" [...] a
> request with the binding bit and a non-zero SessionId falls through to
> the last branch with conn->binding false.
On 007722b8211f alone, yes. With multichannel off that branch catches
only SMB 2.x, so the SMB 3.x AUTHENTICATE with the bit set reaches
ntlm_authenticate, and patch 3's switch to conn->binding is what makes
it encrypt. We reproduced your two mainline results.
That condition is negated by e1b357794105 ("ksmbd: verify the signature
of session binding requests"):
} else if ((conn->dialect < SMB30_PROT_ID ||
!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)) &&
(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
which is the "it may be worth fixing separately" you suspected, already
done. It is in ksmbd-for-next, the base of this series, and is the first
of the eight commits the cover letter lists for applying on mainline.
With it, a binding request on a non-zero SessionId with multichannel off
is refused at that branch with STATUS_REQUEST_NOT_ACCEPTED before the
authentication paths, so the only binding request that reaches them is a
real channel bind, where conn->binding is true and the bit is set. That
is what the cover-letter sentence means; we will add "on this base" so it
is not read as a claim about bare mainline.
Your case on the series base (ksmbd-for-next 43dc36660aff), multichannel
off, mandatory encryption, with and without the series:
leg 2 (AUTHENTICATE, pending non-zero SessionId), binding bit set:
STATUS_REQUEST_NOT_ACCEPTED (0xc00000d0), no session
control, no binding bit:
session with SMB2_SESSION_FLAG_ENCRYPT_DATA; a plaintext
TREE_CONNECT on it is accepted on the base and refused with
STATUS_ACCESS_DENIED by patch 4.
So on this base patch 3 closes the SessionId-0 variant (the -EINVAL in
smb2_sess_setup(), STATUS_INVALID_PARAMETER) and e1b357794105 closes the
non-zero one; the conn->binding switch in the two authenticate functions
is then behaviour-neutral and kept for consistency. We will add this case
to the test matrix next to the SessionId-0 one.
On the error path going by the bit: on this base the last branch is
reached only with the bit clear, so the unregister/expire checks in
smb2_sess_setup() that test the bit run only for a real binding request,
where they are correct. On bare mainline, as you note, a failed
AUTHENTICATE carrying the bit without binding would leave its
IN_PROGRESS session unexpired; e1b357794105 refuses it before that too.
> Minor: between patches 4 and 5, a guest login under mandatory
> encryption gets sess->enc_required set [...] moving the guest check
> before patch 4 would avoid that state.
Agreed. v4 moves the guest refusal ahead of the enc_required patch, so
the intermediate state does not exist at any point in the series.
Thanks,
RootSys GmbH Research
^ permalink raw reply [flat|nested] 8+ messages in thread