[PATCH] ksmbd: build a response when the connection state stops a request

From: Andreas Claesson via B4 Relay

Date: Tue Dec 01 2026 - 08:14:57 EST


From: Andreas Claesson <andreas@xxxxxxxxxxxxx>

__process_request() does not run a request when the connection is
exiting or needs to reconnect. check_conn_state() then writes
STATUS_CONNECTION_DISCONNECTED at the start of the response buffer,
through a struct smb_hdr, which is the SMB1 header, and
__process_request() returns SERVER_HANDLER_CONTINUE, so
__handle_ksmbd_work() goes on to set the credits and to decide whether
to sign the response.

Since commit e2b76ab8b5c9 ("ksmbd: add support for read compound") a
response is only sent if it is pinned with ksmbd_iov_pin_rsp(), and
check_conn_state() does not pin one.

For a single request nothing is sent. On a session that does not
require signing nothing is signed either, because the command value
that is passed to is_sign_req() has not been read yet and is still
zero, which smb2_is_sign_req() takes for a NEGOTIATE.

For a later command of a compound, that value is still the one of the
previous command, so a signed compound is signed. The status is not in
the response of that command either: with the SMB1 layout it overwrites
part of StructureSize, CreditCharge and the low byte of Status in the
header of the first response. The signing code then does not find the
response it is asked to sign:

WARNING: fs/smb/server/smb2pdu.c:13151 at smb2_get_sign_rsp_iov+0x13d/0x260
Workqueue: ksmbd-io handle_ksmbd_work
Call Trace:
smb3_set_sign_rsp+0x2ba/0x510
handle_ksmbd_work+0x10a2/0x27a0

A client with a session can trigger this. One connection sends a signed
compound of a LOCK that blocks and a NEGOTIATE. A second connection
then sends a SESSION_SETUP with the PreviousSessionId of that session.
destroy_previous_session() marks the first connection as
KSMBD_SESS_NEED_RECONNECT and wakes the blocked LOCK, and the NEGOTIATE
that follows it is stopped by check_conn_state(). A second NEGOTIATE on
the connection of the compound, which sets it exiting, has the same
effect on the command after the blocked LOCK.

Use the set_rsp_status() operation, as the other early error paths of
__process_request() do. It writes the status into the response of the
current command and pins an error response, so there is a response to
sign.

A single request that is stopped this way now gets a
STATUS_CONNECTION_DISCONNECTED response where it got none. Whether that
response is signed is decided as before, so on a session that does not
require signing it is not signed even if the request was. This is left
as it is, since the connection is being torn down.

Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound")
Assisted-by: Claude:claude-mythos-5-2
Signed-off-by: Andreas Claesson <andreas@xxxxxxxxxxxxx>
---
Found with syzkaller, using local descriptions for ksmbd.

Tested on ksmbd-for-next (87ff512becd4) in QEMU with KASAN, with the
PreviousSessionId reproducer from the commit message, on a session that
does not require signing.

Without the patch: the warning above. The compound response carries
only the LOCK response, with status 0xc00000c0 instead of 0xc000007e:
with the SMB1 layout the last byte of STATUS_CONNECTION_DISCONNECTED
lands in the first byte of Status.

With the patch: no warning. The LOCK response has status 0xc000007e and
is followed by a signed NEGOTIATE response with
STATUS_CONNECTION_DISCONNECTED.

Not tested: a single request that is stopped this way on a session that
requires signing. From the code the new error response is signed there
like any other response, but I have no reproducer for that case.
---
fs/smb/server/server.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 962f12e969ba6..4405e717737dc 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -96,12 +96,10 @@ char *ksmbd_work_group(void)
*/
static inline int check_conn_state(struct ksmbd_work *work)
{
- struct smb_hdr *rsp_hdr;
+ struct ksmbd_conn *conn = work->conn;

- if (ksmbd_conn_exiting(work->conn) ||
- ksmbd_conn_need_reconnect(work->conn)) {
- rsp_hdr = smb_get_msg(work->response_buf);
- rsp_hdr->Status.CifsError = STATUS_CONNECTION_DISCONNECTED;
+ if (ksmbd_conn_exiting(conn) || ksmbd_conn_need_reconnect(conn)) {
+ conn->ops->set_rsp_status(work, STATUS_CONNECTION_DISCONNECTED);
return 1;
}
return 0;

---
base-commit: 87ff512becd45a08c44fd47a9f03e607af9ef6bd
change-id: 20261201-ksmbd-conn-state-rsp-372fd8567ae0

Best regards,
--
Andreas Claesson <andreas@xxxxxxxxxxxxx>