[PATCH] smb: client: check the data length in SMB2_set_info_init()
From: Piyus Kedia
Date: Sat Dec 05 2026 - 15:14:36 EST
SMB2_set_info_init() copies data[0] into the request buffer after the
fixed part of the request (offset 96) without comparing its length with
the buffer, a cifs_buf_get() one of CIFSMaxBufSize + MAX_SMB2_HDR_SIZE
bytes (16588 by default). It has been so since the first caller with
data of a variable size, commit 366ed846df60 ("cifs: Use smb 2 - 3 and
cifsacl mount options setacl function"); commit f46ecbd97f50 ("cifs:
Fix slab-out-of-bounds in send_set_info() on SMB2 ACE setting") moved
SET_INFO from the small buffer to this one, without a bound. Two
callers can pass more than it holds:
- smb2_set_ea() builds a FILE_FULL_EA_INFORMATION of up to 16644 bytes
for a setxattr() of a user.* attribute. Its only limit is a check
that adds the OutputBufferLength of the server's
FILE_FULL_EA_INFORMATION response, as an int, to the size of the new
EA; a server that answers 0xFFFFC180 makes the sum wrap, and a
16384-byte value with a 250-character name is copied:
BUG: KASAN: slab-out-of-bounds in SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000)
Write of size 16643 at addr ffff8880436b0060 by task poc/9452
__asan_memcpy (mm/kasan/shadow.c:106)
SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000)
smb2_set_ea (fs/smb/client/smb2ops.c:1329)
cifs_xattr_set (fs/smb/client/xattr.c:156)
The buggy address belongs to the object at ffff8880436b0000
which belongs to the cache cifs_request of size 16588
The buggy address is located 96 bytes inside of
allocated 16588-byte region [ffff8880436b0000, ffff8880436b40cc)
- set_smb2_acl() sends the security descriptor id_mode_to_cifs_acl()
built for chmod() on a cifsacl or modefromsid mount: most of the
server's ACEs plus up to five new ones, which can be longer than the
buffer holds (a 16504-byte descriptor from the server made chmod()
copy 16676 bytes).
Check the length where the copy is, as commit 33eae65c6f49 ("smb:
client: fix OOB in SMB2_query_info_init()") did for
SMB2_query_info_init(), and refuse data longer than CIFSMaxBufSize with
-E2BIG, which setxattr() and chmod() then return. CIFSMaxBufSize
rather than the 16492 bytes that fit leaves room for the padding
smb2_set_next_command() writes into the buffer of an encrypted
compound, and is the limit setxattr() already puts on a security
descriptor (MAX_EA_VALUE_SIZE) and SendReceive() on SMB1; a descriptor
of up to 108 bytes more, which chmod() on SMB2 could send before, is
refused as well. The other callers pass fixed-size information of a
few dozen bytes. smb2_set_ea()'s check is left as it is: with this, a
negative OutputBufferLength can only let through an EA that fits.
We found this with a syzkaller-based fuzzing harness driven by an AI tool.
Fixes: 366ed846df60 ("cifs: Use smb 2 - 3 and cifsacl mount options setacl function")
Closes: https://lore.kernel.org/r/cifs-set-info-overflow.20261205@xxxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
---
Tested on ksmbd-for-next (d70570cf8003), whose fs/smb/client is the
same as mainline's, with KASAN; this patch was the only change between
the two builds. The reproducer runs a minimal SMB 3.0 server on
loopback and mounts it:
before ea: the server answers the EA query with OutputBufferLength
0xFFFFC180, setxattr(f, user.<250 x 'a'>, 16384 bytes): the
report above in 3 of 3 boots; acl: cifsacl, a 16504-byte
descriptor, chmod(f, 0640): a 16676-byte write in 3 of 3;
the server receives both SET_INFOs, setxattr() and chmod()
return 0
after no report in 6 boots (ea 3 times, acl 3 times); no
SET_INFO is sent and setxattr() and chmod() fail with E2BIG
both the server reporting its real 16 bytes of EAs: setxattr()
fails with ENOSPC; a 924-byte descriptor: chmod() returns 0
and the server receives the 1096-byte descriptor
The patch applies to cifs-next (9b62aa64ed00) and mainline
(c3500c5ef648).
fs/smb/client/smb2pdu.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index fd7499c79664..9ed88b034ad7 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -5982,6 +5982,14 @@ SMB2_set_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
unsigned int i, total_len;
int rc;
+ /*
+ * data[0] is copied into the request buffer, which holds
+ * CIFSMaxBufSize bytes beyond the largest SMB2 header; the other
+ * elements are sent from where they are.
+ */
+ if (*size > CIFSMaxBufSize)
+ return -E2BIG;
+
rc = smb2_plain_req_init(SMB2_SET_INFO, tcon, server,
(void **) &req, &total_len);
if (rc)
--
2.34.1