[PATCH] smb: client: check the security descriptor length in CIFSSMBSetCIFSACL()
From: Piyus Kedia
Date: Sat Dec 05 2026 - 15:13:14 EST
CIFSSMBSetCIFSACL() copies the security descriptor into the request
buffer at data_offset (84) without comparing its length with the
buffer, a cifs_buf_get() one of CIFSMaxBufSize + MAX_SMB2_HDR_SIZE
bytes (16588 by default).
chmod() on a cifsacl or modefromsid mount sends a descriptor that
id_mode_to_cifs_acl() built from the one the server returned: since
commit f5065508897a ("cifs: Retain old ACEs when converting between
mode bits and ACL."), set_chmod_dacl() keeps the server's ACEs, except
those for the owner, the group and three well-known SIDs, and adds up
to five of its own. So the descriptor sent back is longer than the one
received, and one that arrived in a single response can come back too
long for the request. A 16352-byte server descriptor (213 ACEs) makes
chmod(0640) copy 16524 bytes:
BUG: KASAN: slab-out-of-bounds in CIFSSMBSetCIFSACL (fs/smb/client/cifssmb.c:3986)
Write of size 16524 at addr ffff888049550054 by task poc/9447
__asan_memcpy (mm/kasan/shadow.c:106)
CIFSSMBSetCIFSACL (fs/smb/client/cifssmb.c:3986)
set_cifs_acl (fs/smb/client/cifsacl.c:1723)
id_mode_to_cifs_acl (fs/smb/client/cifsacl.c:1903)
cifs_setattr (fs/smb/client/inode.c:3490 fs/smb/client/inode.c:3592)
notify_change (fs/attr.c:556)
chmod_common (fs/open.c:686)
The buggy address belongs to the object at ffff888049550000
which belongs to the cache cifs_request of size 16588
The buggy address is located 84 bytes inside of
allocated 16588-byte region [ffff888049550000, ffff8880495540cc)
SendReceive() refuses the request afterwards, since it does not send
more than CIFSMaxBufSize + MAX_CIFS_HDR_SIZE bytes, and chmod() fails
with -EIO, but by then the copy has run past the buffer.
Refuse a descriptor that would make the request longer than that
before copying it, with -E2BIG as CIFSSMBSetPosixACL() does for a POSIX
ACL that does not fit; chmod() then fails with -E2BIG. Such a request
could never be sent, so nothing that works now is refused.
We found this with a syzkaller-based fuzzing harness driven by an AI tool.
Fixes: f5065508897a ("cifs: Retain old ACEs when converting between mode bits and ACL.")
Closes: https://lore.kernel.org/r/cifs-setcifsacl-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 SMB1 server on loopback,
mounts it with vers=1.0,cifsacl and calls chmod() on a file whose
descriptor has two 15-sub-authority SIDs and N ACEs of 76 bytes:
before N = 213 (16352 bytes): the report above with chmod 0640 in
3 of 3 boots, a 16676-byte write with chmod 0007 in 1 of 1;
chmod() fails with EIO
after no report in 4 boots (0640 three times, 0007 once); no
SET_SECURITY_DESC is sent and chmod() fails with E2BIG
both N = 10: the server receives the descriptor (1096 bytes for
0640, 1248 for 0007) and chmod() returns 0
The patch applies to cifs-next (9b62aa64ed00) and mainline
(c3500c5ef648).
fs/smb/client/cifssmb.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c
index 68f05a52605f..f0392cbde2c1 100644
--- a/fs/smb/client/cifssmb.c
+++ b/fs/smb/client/cifssmb.c
@@ -3966,6 +3966,16 @@ CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid,
data_offset = param_offset + param_count;
byte_count = 3 /* pad */ + param_count;
+ /*
+ * The descriptor is copied into the request buffer at data_offset,
+ * and SendReceive() does not send a request longer than
+ * CIFSMaxBufSize + MAX_CIFS_HDR_SIZE.
+ */
+ if (acllen > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - data_offset) {
+ cifs_buf_release(pSMB);
+ return -E2BIG;
+ }
+
pSMB->DataCount = cpu_to_le32(data_count);
pSMB->TotalDataCount = pSMB->DataCount;
pSMB->MaxParameterCount = cpu_to_le32(4);
--
2.34.1