Re: [PATCH] ksmbd: fix smb2_cancel() use-after-free during request decompression

From: Namjae Jeon

Date: Sun Nov 15 2026 - 08:53:14 EST


On Sun, Nov 15, 2026 at 10:10 PM Ian Bridges <icb@xxxxxxxxxxxx> wrote:
>
> smb2_cancel() finds the request to cancel by reading the SMB2 header in
> the request_buf of each queued struct ksmbd_work. A queued request may
> still be in preprocessing. smb3_decrypt_req() decrypts it in place, and
> ksmbd_decompress_work_request() frees request_buf and replaces it with
> the decompressed buffer. Neither runs under conn->request_lock. A
> concurrent CANCEL can therefore compare a transform header as if it were
> an SMB2 header, or read freed memory.
>
> BUG: KASAN: slab-use-after-free in smb2_cancel+0x73b/0x840 [ksmbd]
> Call Trace:
> smb2_cancel+0x73b/0x840 [ksmbd]
> handle_ksmbd_work+0xa90/0x2110 [ksmbd]
> Freed by task 53136:
> ksmbd_decompress_work_request+0x10d/0x180 [ksmbd]
>
> Record the MessageId and Command of each request in its struct
> ksmbd_work, under conn->request_lock. A plain SMB2 request gets them
> when it is queued, because its request_buf does not change. An encrypted
> request gets them once it is decrypted and decompressed. smb2_cancel()
> matches on these fields and skips a request that does not have them yet.
> It no longer reads the request_buf of another request.
>
> Fixes: 6639b6928ba2 ("ksmbd: handle encrypted compressed requests")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
Applied it to #ksmbd-for-next.
Thanks!