[PATCH] ksmbd: allocate the security descriptor reply at its padded size
From: Ian Bridges
Date: Wed Nov 18 2026 - 12:35:07 EST
smb2_get_info_sec() allocates the security descriptor reply with the
size that smb_acl_sec_desc_scratch_len() estimates. A compound response
pads the reply to 8 bytes inside that buffer, so after build_sec_desc()
the query fails with -EFBIG when the padded length does not fit. The
estimate is not padded, so a descriptor that fits the estimate can
still fail. A query with AdditionalInformation 0 always fails with
-EFBIG. Its reply is the 20-byte header, the estimate is 20 bytes, and
the padded length is 24. The client gets an error instead of the
header.
Round the allocation up to 8 bytes, as READ does for its data buffer.
Fixes: fda9522ed6af ("ksmbd: fix OOB write in QUERY_INFO for compound requests")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
The size check after build_sec_desc() is kept. It still makes sure the
descriptor and its padding fit in the buffer.
Tested on ksmbd-for-next 267029b35ad1 with KASAN. A query with
AdditionalInformation 0 now returns the 20-byte header, both alone and
in the middle of a compound. Replies for the other tested
AdditionalInformation values are unchanged. smbtorture results match
the base.
This patch was developed with LLM assistance.
fs/smb/server/smb2pdu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 29750970f8da..84f840f51297 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -8510,11 +8510,13 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
scratch_len = smb_acl_sec_desc_scratch_len(&fattr, ppntsd,
ppntsd_size, addition_info);
- if (!scratch_len || scratch_len == SIZE_MAX) {
+ if (!scratch_len || scratch_len > SIZE_MAX - 7) {
rc = -EFBIG;
goto release_acl;
}
+ /* A compound response pads the descriptor to 8 bytes in this buffer */
+ scratch_len = ALIGN(scratch_len, 8);
pntsd = kvzalloc(scratch_len, KSMBD_DEFAULT_GFP);
if (!pntsd) {
rc = -ENOMEM;
--
2.47.3