[PATCH v2 01/12] smb: client: don't add a decrypted mid back to an exiting server

From: Stefan Metzmacher

Date: Fri Dec 04 2026 - 08:33:57 EST


If handle_read_data() fails in smb2_decrypt_offload(), e.g. for a
STATUS_PENDING interim response, the mid is added back to
pending_mid_q, unless the server needs a reconnect. The decrypt
offload work runs on decrypt_wq, so this can happen after
clean_demultiplex_info() completed all pending mids with
MID_SHUTDOWN. Nobody completes the mid added back then, so the
request waits forever, and the mid keeps pointing to the server,
which clean_demultiplex_info() frees after its 46 second wait.

While the server is exiting, complete the mid with MID_SHUTDOWN, as
clean_demultiplex_info() does, instead of adding it back. The status
is checked under srv_lock, and cifs_put_tcp_session() sets
CifsExiting under srv_lock before cifsd exits, so a mid added back
before that is still completed by clean_demultiplex_info().

Fixes: 1254100030b3 ("smb3: Handle error case during offload read path")
Cc: stable@xxxxxxxxxxxxxxx
Cc: Paulo Alcantara <pc@xxxxxxxxxxxxx>
Cc: Namjae Jeon <linkinjeon@xxxxxxxxxx>
Cc: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
Cc: Shyam Prasad N <sprasad@xxxxxxxxxxxxx>
Cc: Tom Talpey <tom@xxxxxxxxxx>
Cc: Bharath SM <bharathsm@xxxxxxxxxxxxx>
Cc: linux-cifs@xxxxxxxxxxxxxxx
Cc: samba-technical@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Stefan Metzmacher <metze@xxxxxxxxx>
---
fs/smb/client/smb2ops.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 8783738a31ad..91a32920aeab 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -5384,6 +5384,18 @@ static void smb2_decrypt_offload(struct work_struct *work)
spin_unlock(&dw->server->mid_queue_lock);
spin_unlock(&dw->server->srv_lock);
mid_execute_callback(dw->server, mid);
+ } else if (dw->server->tcpStatus == CifsExiting) {
+ /*
+ * clean_demultiplex_info() may already have
+ * completed the pending mids, so a mid added
+ * back now would never complete, finish it
+ * like clean_demultiplex_info() does.
+ */
+ spin_lock(&dw->server->mid_queue_lock);
+ mid->mid_state = MID_SHUTDOWN;
+ spin_unlock(&dw->server->mid_queue_lock);
+ spin_unlock(&dw->server->srv_lock);
+ mid_execute_callback(dw->server, mid);
} else {
spin_lock(&dw->server->mid_queue_lock);
mid->mid_state = MID_REQUEST_SUBMITTED;
--
2.43.0