ksmbd: allocate the security descriptor reply at its padded size
Subsystems (3)
PATCH 1/1 ksmbd: allocate the security descriptor reply at its padded size
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.
---
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(-)
fs/smb/server/smb2pdu.c +3 -1
@@ -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 ;
Signature · 1 line
2.47.3
Quoted 11 lines · Ian Bridges
smb2_get_info_sec()allocates the security descriptor reply with the size thatsmb_acl_sec_desc_scratch_len()estimates. A compound response pads the reply to 8 bytes inside that buffer, so afterbuild_sec_desc()the query fails with-EFBIGwhen 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.
Quoted 5 lines
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")Signed-off-by Ian Bridges <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!