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

From: Namjae Jeon

Date: Sun Dec 06 2026 - 02:16:18 EST


On Fri, Dec 4, 2026 at 11:18 PM Andreas Claesson via B4 Relay
<devnull+andreas.aclaesson.com@xxxxxxxxxx> wrote:
>
> 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.
>
> Build the response with the set_rsp_status() operation, which writes
> the status into the response of the current command and pins an error
> response, and return SERVER_HANDLER_ABORT, as the other early error
> paths of __process_request() do. This skips the credit and signing
> steps of __handle_ksmbd_work(), which must not run for a request whose
> MessageId, CreditCharge and signature have not been checked.
>
> The stopped request is not charged. Its response ends the work, so it
> carries the credits that the earlier commands of a compound were
> granted.
>
> The response is signed only if the request is signed and passes
> validation and the signature check. Otherwise a single request that is
> signed, or whose session requires signing, gets no response, and a
> later command of a compound gets an unsigned response: the previous
> response already points to it, and dropping the message would also
> drop the earlier responses. An encrypted request is answered encrypted,
> as before.
>
> Move the handling of the last response of a compound out of
> is_chained_smb2_message() into smb2_end_compound_rsp(), so that it can
> be used here before signing.
>
> Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound")
> Assisted-by: Claude:claude-mythos-5-2
> Signed-off-by: Andreas Claesson <andreas@xxxxxxxxxxxxx>
Please check Sashiko's review comments.

https://sashiko.dev/#/patchset/20261204-ksmbd-conn-state-rsp-v3-1-b03e3c81743d%40aclaesson.com

Thanks.