[BUG] smb: client: slab-out-of-bounds write in CIFSSMBSetCIFSACL() on chmod

From: Piyus Kedia

Date: Sat Dec 05 2026 - 15:13:09 EST


Hi,

With the cifsacl (or modefromsid) mount option, chmod() reads the
file's security descriptor from the server, builds a new one from it
and sends that back. On SMB1 the sending is CIFSSMBSetCIFSACL(), which
copies the descriptor into the request buffer without comparing its
length with the buffer:

fs/smb/client/cifssmb.c:3986 (CIFSSMBSetCIFSACL)
if (pntsd && acllen) {
memcpy((char *)pSMBr + data_offset, pntsd, acllen);

The buffer comes from cifs_buf_get() (smb_init(), cifssmb.c:3955) and
is CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes, 16588 by default;
data_offset is 84, so it holds 16504 bytes of descriptor. Nothing
keeps the descriptor that small. id_mode_to_cifs_acl() sizes it from
the server's:

fs/smb/client/cifsacl.c:1841 (id_mode_to_cifs_acl)
else /* cifsacl */
nsecdesclen += secdesclen + 5 * sizeof(struct smb_ace);

and set_chmod_dacl() copies every ACE of the server's DACL that is not
for the owner, the group, Everyone, Authenticated Users or the NFS mode
SID, and adds up to five ACEs for the new mode between the explicit and
the inherited ones (cifsacl.c:1286-1329). So the descriptor that goes
back is longer than the one that came in. Here the server's
descriptor is 16352 bytes - an owner and a group SID of 15
sub-authorities and 213 ACCESS_ALLOWED ACEs of 76 bytes, each for a SID
of its own - and chmod(file, 0640) adds an owner, a group and an
Everyone ACE, 172 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)
do_fchmodat (fs/open.c:731)
__x64_sys_chmod (fs/open.c:755 fs/open.c:753 fs/open.c:753)
do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)

Allocated by task 9447:
...
mempool_alloc_noprof (mm/mempool.c:572)
cifs_buf_get (fs/smb/client/misc.c:202)
smb_init (fs/smb/client/cifssmb.c:288 fs/smb/client/cifssmb.c:320)
CIFSSMBSetCIFSACL (fs/smb/client/cifssmb.c:3955)
set_cifs_acl (fs/smb/client/cifsacl.c:1723)
id_mode_to_cifs_acl (fs/smb/client/cifsacl.c:1903)

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)

That copy ends 20 bytes past the object. chmod(file, 0007) makes
populate_new_aces() add a DENY ACE for the owner and one for the group
as well, five in all: a 16676-byte copy, ending 172 bytes past it.

The request is never sent. SendReceive() refuses one longer than
CIFSMaxBufSize + MAX_CIFS_HDR_SIZE bytes (smb1transport.c:251):

CIFS: VFS: \\127.0.0.1 Invalid length, greater than maximum frame, 16608

and chmod() fails with EIO - but that check comes after the copy.

How it is reached. The reproducer runs a minimal SMB1 server on
loopback (NT LM 0.12 with extended security; NTLMSSP accepted
unchecked) whose files all have the descriptor above, mounts it with
vers=1.0,cifsacl and calls chmod() on a file. With 10 ACEs instead of
213 (a 924-byte descriptor) the same chmod(0640) works: the server
receives a 1096-byte descriptor, chmod() returns 0, no report.

The other way into CIFSSMBSetCIFSACL(), setxattr of system.cifs_acl and
the related names, is bounded: cifs_xattr_set() refuses a value larger
than CIFSMaxBufSize (xattr.c:127), which fits. chown() on such a mount
also builds its descriptor from the server's DACL in
id_mode_to_cifs_acl(); we did not try it.

Impact - who can trigger it:

- The length comes from the server, as the size of the descriptor it
returns for the file. Nothing in ours is malformed: it is a
self-relative descriptor with an owner, a group and a DACL, the
client parses it and maps it to a mode without complaint, and the
213 ACEs are ordinary ones. So it takes a malicious server, or a
file whose ACL has enough ACEs that the descriptor nearly fills a
response; we have not tried a Windows or Samba server and do
not know how such a server answers for an ACL that size.

- On the client it takes chmod(2) of that file on an SMB1 mount with
cifsacl or modefromsid. The mount needs CAP_SYS_ADMIN in the
initial user namespace and vers=1.0 (SMB1 is only negotiated when
asked for, and needs CONFIG_CIFS_ALLOW_INSECURE_LEGACY). chmod(2)
needs the caller to own the file as the client sees it: with
cifsacl the uid comes from the owner SID, or is the mount's uid=
when the SID does not map, as ours did not. We ran as root.

- What the write does. KASAN reports the copy and skips it
(__asan_memcpy() returns without copying), so our runs show its
size and place, not its effect. Without KASAN the copy is done and
the request then refused: the end of the descriptor the client
built is written past the 16588-byte object, 20 bytes in the first
run above and 172 with chmod 0007. The server's descriptor has to
arrive in one response of at most CIFSMaxBufSize + MAX_CIFS_HDR_SIZE
bytes (connect.c:1200) and chmod adds at most five ACEs, so from the
code the overrun is at most a few hundred bytes.
In our runs the bytes written past the end are the new ACEs, made
from the server's owner and group SIDs and the mode;
set_chmod_dacl() puts the server's inherited ACEs after the new ones
(cifsacl.c:1290-1298), so a server that sends inherited ACEs chooses
those bytes - their type, flags, mask and SID. We did not run that,
and did not establish what lies past a cifs_request object on a
production kernel, which depends on the slab layout and so on
CIFSMaxBufSize.

Seen on 7.4.0-rc5, where the fuzzer's server sent the same 16352-byte
descriptor and the same write was reported at the same lines (twice),
and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04), whose
fs/smb/client is identical to mainline (c3500c5ef648, 2026-12-04), with
KASAN: chmod 0640 gave the report above in 3 of 3 boots (and the
hunt's own program in 1 of 1), chmod 0007 the 16676-byte write in 1 of
1, and the 924-byte control none. CIFSSMBSetCIFSACL(),
id_mode_to_cifs_acl() and set_chmod_dacl() are the same in cifs-next
(9b62aa64ed00, 2026-12-03).

The copy has been unbounded since CIFSSMBSetCIFSACL() was added in
97837582bc1e ("[CIFS] Allow setting mode via cifs acl"), v2.6.25, but
until v5.12 chmod sent back a descriptor of the length it had received.
f5065508897a ("cifs: Retain old ACEs when converting between mode bits
and ACL."), v5.12, made it keep the server's ACEs and add new ones.
0ee150794c75 and a377a3645c7d have since fixed the size of the buffer
that descriptor is built in, not of the request it is copied to.

A patch follows in reply to this mail. It refuses, with -E2BIG and
before the copy, a descriptor that would make the request longer than
SendReceive() sends, which also keeps the copy inside the buffer; that
is CIFSMaxBufSize bytes of descriptor. CIFSSMBSetPosixACL() refuses a
POSIX ACL that does not fit the same way (cifssmb.c:3610-3614). A
request that size could never be sent, so nothing that works now is
refused. On ksmbd-for-next, same config and image, the patch the only
change between the two builds:

without the patch the reports above; chmod() fails with EIO
with the patch no report in 4 boots (chmod 0640 3 times, 0007
once); no SET_SECURITY_DESC is sent and chmod()
fails with E2BIG
both the 924-byte control: the server receives the
1096-byte descriptor and chmod() returns 0

The SMB2 side has the same problem in SMB2_set_info_init(), which
set_smb2_acl() uses to send the same descriptor; we report that, with
a large EA that reaches the same copy, in a separate mail ("[BUG] smb:
client: slab-out-of-bounds write in SMB2_set_info_init()"), with its own
patch.

This was found by AI-driven fuzzing built on top of syzkaller; its
analysis was then checked by hand against the code and every claim
above was reproduced. The reproducer is fuzzer-generated, runs a
minimal SMB1 server and the mount in one program over loopback, and we
are happy to send it on request.

Kapil Vaswani
Piyus Kedia