mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ksmbd: allocate the security descriptor reply at its padded size
@ 2026-11-18 17:34 Ian Bridges
  0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-11-18 17:34 UTC (permalink / raw)
  To: linkinjeon
  Cc: senozhatsky, tom, chenxiaosong, manizada, linux-cifs,
	linux-kernel, Ian Bridges, stable

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@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-18 17:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 17:34 [PATCH] ksmbd: allocate the security descriptor reply at its padded size Ian Bridges

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®