]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
ksmbd: apply the pre-authentication PDU limit when decompressing
authorSujal Tuladhar <sujaltuladhar1231@gmail.com>
Sat, 1 Aug 2026 15:53:03 +0000 (00:53 +0900)
committerSteve French <stfrench@microsoft.com>
Mon, 3 Aug 2026 16:21:22 +0000 (11:21 -0500)
commitab88cb66cb0028cb8038b64c2fa71b0f3e91d5f2
tree21fdb885425bced6c7062b953830cfa62e3cf109
parentba3afa8ccd154962c4a6b975b6e8b11027c5ab95
ksmbd: apply the pre-authentication PDU limit when decompressing

ksmbd_conn_handler_loop() caps a request from an unauthenticated
connection at SMB3_MAX_MSGSIZE, and only allows the larger
SMB3_MAX_MSGSIZE + conn->vals->max_write_size once the connection has
authenticated.

ksmbd_decompress_request() runs inside that same loop but applies the
authenticated limit unconditionally, and then allocates from it. The
unauthenticated cap is not re-applied afterwards, as the caller only
refreshes pdu_size from the new RFC1002 header.

An unauthenticated client that negotiates SMB 3.1.1 with a compression
context can therefore send a 104 byte chained transform whose
OriginalCompressedSegmentSize is SMB3_MAX_MSGSIZE + max_write_size and
have ksmbd kvmalloc() that much memory, 4210693 bytes by default. The
payload costs the client nothing, because a SMB3_COMPRESS_PATTERN
payload expands an eight byte structure into arbitrarily many output
bytes.

The decompressed PDU is rejected later by ksmbd_smb2_check_message(),
but that happens in the worker, after the allocation has been made and
conn->req_running has been incremented, and it results in an error
response rather than dropping the connection. A client that stops
reading its socket keeps each work queued for up to KSMBD_TCP_SEND_TIMEOUT
while ksmbd_conn_write() holds conn->srv_mutex, so the allocations
accumulate up to server_conf.max_inflight_req per connection.

Move the limit into ksmbd_max_allowed_pdu_size() and call it from both
sites, so the authentication state is consulted in one place and the two
ceilings cannot drift apart again.

Fixes: a08de24c2b85 ("ksmbd: negotiate and decode SMB2 compression")
Signed-off-by: Sujal Tuladhar <sujaltuladhar1231@gmail.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/compress.c
fs/smb/server/connection.c
fs/smb/server/connection.h