receive_encrypted_read() queues smb2_decrypt_offload() on decrypt_wq with a bare server pointer. The work doesn't own a mid reference until smb2_find_dequeue_mid() found the mid, but it uses the server before that for decrypt_raw_data() and server->lstrp. clean_demultiplex_info() doesn't wait for decrypt_wq, so cifsd can drop its server reference, which can be the last one, before the work runs or while it runs. Take a server reference before queueing the work and drop it at the end of the work. Fixes: 482c117c6dbe ("smb: client: hold server info until cifsd exits") Fixes: 35cf94a39728 ("smb3: allow parallelizing decryption of reads") Cc: stable@vger.kernel.org Cc: Eduard Zateev Cc: Paulo Alcantara Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- fs/smb/client/smb2ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 91a32920aeab..3dbc70cb52ff 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -5344,6 +5344,7 @@ static void smb2_decrypt_offload(struct work_struct *work) { struct smb2_decrypt_work *dw = container_of(work, struct smb2_decrypt_work, decrypt); + struct TCP_Server_Info *server = dw->server; int rc; struct mid_q_entry *mid; struct iov_iter iter; @@ -5413,6 +5414,8 @@ static void smb2_decrypt_offload(struct work_struct *work) netfs_free_folioq_buffer(dw->buffer); cifs_small_buf_release(dw->buf); kfree(dw); + /* taken by receive_encrypted_read() */ + cifs_tcp_server_put(server); } @@ -5491,6 +5494,11 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, dw->buf = server->smallbuf; server->smallbuf = (char *)cifs_small_buf_get(); + /* + * The worker runs independently of cifsd, which can + * exit and drop its server reference meanwhile. + */ + cifs_tcp_server_get(server); queue_work(decrypt_wq, &dw->decrypt); *num_mids = 0; /* worker thread takes care of finding mid */ return -1; -- 2.43.0