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

From: Andreas Claesson via B4 Relay

Date: Wed Dec 02 2026 - 02:45:29 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 and stop processing the work, as the
other early error paths of __process_request() do. set_rsp_status()
writes the status into the response of the current command and pins an
error response. Returning SERVER_HANDLER_ABORT skips the credit and
signing steps. They must not run here, because the MessageId, the
CreditCharge and the signature of the stopped request have not been
checked.

A request that is stopped this way now gets an unsigned
STATUS_CONNECTION_DISCONNECTED response, where a single request got
none. The responses to the earlier commands of a compound are sent as
before.

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, and with the two cases from the review of v1.

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 one unsigned NEGOTIATE response with
STATUS_CONNECTION_DISCONNECTED. This is the same when the stopped
NEGOTIATE has a wrong signature and when it has a CreditCharge of
65535.
---
Changes in v2:
- Stop processing the work after the error response is built, so that
the credit and signing steps do not run for a request that was not
verified. v1 signed the response to a stopped command without checking
its signature, and pinned the error response twice when the credit
step failed. Both were found by the Sashiko review and confirmed by
Ian Bridges.
- Link to v1: https://patch.msgid.link/20261201-ksmbd-conn-state-rsp-v1-1-9a38d57ab0d5@xxxxxxxxxxxxx
---
fs/smb/server/server.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 962f12e969ba6..9fd45b114a403 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;
@@ -179,7 +177,7 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
int ret;

if (check_conn_state(work))
- return SERVER_HANDLER_CONTINUE;
+ return SERVER_HANDLER_ABORT;

if (ksmbd_verify_smb_message(work)) {
conn->ops->set_rsp_status(work, STATUS_INVALID_PARAMETER);

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

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