From: Piyus Kedia <piyus@iiitd.ac.in>
To: Paulo Alcantara <pc@manguebit.org>,
Namjae Jeon <linkinjeon@kernel.org>,
linux-cifs@vger.kernel.org
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
samba-technical@lists.samba.org, linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>
Subject: [BUG] smb: client: slab-out-of-bounds write in SMB2_set_info_init()
Date: Sun, 6 Dec 2026 01:44:17 +0530 [thread overview]
Message-ID: <cifs-set-info-overflow.20261205@iiitd.ac.in> (raw)
Hi,
SMB2_set_info_init() copies the first data element of a SET_INFO
request into the request buffer, after the fixed part of the request,
without comparing its length with the buffer:
fs/smb/client/smb2pdu.c:6000 (SMB2_set_info_init)
req->BufferLength = cpu_to_le32(*size);
memcpy(req->Buffer, *data, *size);
The buffer comes from cifs_buf_get() (smb2_plain_req_init(),
smb2pdu.c:5985) and is CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes, 16588
by default; req->Buffer is at offset 96, so it holds 16492 bytes. Two
callers can pass more.
1. smb2_set_ea(), for setxattr() of a user.* attribute.
cifs_xattr_set() lets a value of up to CIFSMaxBufSize (16384) bytes
through (xattr.c:127) and smb2_set_ea() makes it a
FILE_FULL_EA_INFORMATION of 8 + name + 1 + value bytes
(smb2ops.c:1314): up to 16644, since the VFS allows 255 bytes for
the whole name and os2.* is treated like user.*. The one limit on
that is a check meant to keep the file's EAs readable, which first
asks the server how many bytes of EAs the file has:
fs/smb/client/smb2ops.c:1270 (smb2_set_ea)
used_len = le32_to_cpu(rsp->OutputBufferLength);
...
fs/smb/client/smb2ops.c:1280
if (CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
used_len + ea_name_len + ea_value_len + 1) {
rc = -ENOSPC;
used_len is an int, and nothing holds the server's value to the
data that came with it: smb2_get_data_area_len() logs a length that
is negative as an int ("invalid data area (off=72 len=-16000)") and
counts no data area (smb2misc.c:438-444), and smb2_check_message()
accepts a response longer than that (smb2misc.c:339). With
OutputBufferLength 0xFFFFC180 (-16000), a 250-character name and a
16384-byte value the right-hand side is 635, the check passes, and:
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)
__vfs_setxattr (fs/xattr.c:223)
...
__x64_sys_setxattr (fs/xattr.c:768 fs/xattr.c:764 fs/xattr.c:764)
Allocated by task 9452:
...
cifs_buf_get (fs/smb/client/misc.c:202)
__smb2_plain_req_init (fs/smb/client/smb2pdu.c:591)
SMB2_set_info_init (fs/smb/client/smb2pdu.c:625 fs/smb/client/smb2pdu.c:5985)
smb2_set_ea (fs/smb/client/smb2ops.c:1329)
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)
151 bytes past the object. The check is the only bound: it runs
whenever a value is set (query_all_EAs is set in every SMB2
operations table next to set_EA), with used_len 0 if the query
fails, and with a used_len between 0 and 2^31 it does keep the EA
(at most 15132 bytes) inside the buffer.
2. set_smb2_acl() -> SMB2_set_acl() -> send_set_info(), for chmod() on
a cifsacl or modefromsid mount. As on SMB1, where we report the
same thing in CIFSSMBSetCIFSACL() separately ("[BUG] smb: client:
slab-out-of-bounds write in CIFSSMBSetCIFSACL() on chmod"),
id_mode_to_cifs_acl() builds the descriptor from the server's:
set_chmod_dacl() keeps the server's ACEs other than those for the
owner, the group and three well-known SIDs, and adds up to five for
the new mode (cifsacl.c:1286-1329), so it goes back longer than it
came in. On SMB2 the server's descriptor alone may already be too
long: a response of up to CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes
is accepted (connect.c:1200), which leaves 16516 bytes for it.
With a well-formed 16504-byte descriptor (an owner and a group SID
of 15 sub-authorities and 215 ACCESS_ALLOWED ACEs of 76 bytes)
chmod(file, 0640) adds 172 bytes:
BUG: KASAN: slab-out-of-bounds in SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000)
Write of size 16676 at addr ffff888043750060 by task poc/9458
__asan_memcpy (mm/kasan/shadow.c:106)
SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000)
send_set_info (fs/smb/client/smb2pdu.c:6062)
SMB2_set_acl (fs/smb/client/smb2pdu.c:6144)
set_smb2_acl (fs/smb/client/smb2ops.c:3479)
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 is located 96 bytes inside of
allocated 16588-byte region [ffff888043750000, ffff8880437540cc)
184 bytes past the object.
KASAN skips a copy it reports (__asan_memcpy() returns without
copying), and on SMB2 nothing else stops the request: in both cases our
server received the SET_INFO, with BufferLength 16643 and 16676, and
setxattr() and chmod() returned 0.
The other callers of SMB2_set_info_init() pass data of a fixed size
(disposition, end of file, basic, rename and link information - the
new name goes in an iov of its own - and the set-info passthrough's 8
bytes), and setxattr() of system.cifs_acl and the related names passes
a descriptor of at most CIFSMaxBufSize bytes (xattr.c:127), which fits.
How it is reached. The reproducer runs a minimal SMB 3.0 server on
loopback (NTLMSSP accepted unchecked) and mounts it. For the EA, the
server answers the FILE_FULL_EA_INFORMATION query with
OutputBufferLength 0xFFFFC180 over 16 bytes of data, and the program
sets user.<250 x 'a'> to a 16384-byte value; for the descriptor it
mounts with cifsacl and calls chmod() on a file. The controls: when
the server reports the 16 bytes of EAs it really sends, the same
setxattr() fails with ENOSPC from the check above and no SET_INFO is
built; with 10 ACEs (a 924-byte descriptor) the chmod() works - the
server receives a 1096-byte descriptor and chmod() returns 0. Neither
gives a report.
Impact - who can trigger it:
- The EA write needs two parties. The server has to answer the EA
query with an OutputBufferLength of 2^31 or more that makes the sum
wrap; an honest server does not, but one value covers every EA large
enough to overflow (-16000 wraps for anything from 16000 to 31124
bytes). And someone on the client has to set a user.* attribute
whose name and value come to more than 16484 bytes - with the
16384-byte maximum value, a name of 100 characters or more. That
needs write permission to the file as the client sees it, no
privilege, on any SMB2/3 mount that has not turned user xattrs off
(nouser_xattr). The bytes written past the buffer are the end of
that caller's value.
- The descriptor write needs a server descriptor that nearly fills a
response, which need not be malformed - ours is not - and chmod(2)
of that file by its owner (as the client sees it) on an SMB2/3
mount with cifsacl or modefromsid. As on SMB1, the bytes written
past the buffer are the end of the descriptor the client built: the
new ACEs in our runs, or the server's inherited ACEs, which
set_chmod_dacl() puts after them. We have not tried a Windows or
Samba server and do not know how one answers for an ACL that size.
- Mounting needs CAP_SYS_ADMIN in the initial user namespace. We ran
everything as root.
- What the write does: without KASAN the copy is done and the request
is sent. With the default CIFSMaxBufSize the EA can end at most
152 bytes past the object (from the code: a 251-character os2.*
name); we measured 151, and 184 for the descriptor. We 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 EA answer
and the same 16643-byte write was reported at the same lines (twice);
the descriptor path we found while writing this up. REPRODUCED ON
ksmbd-for-next (d70570cf8003, 2026-12-04), whose fs/smb/client is
identical to mainline (c3500c5ef648, 2026-12-04), with KASAN: the EA
gave the first report above in 3 of 3 boots (and the hunt's own program
in 1 of 1), the descriptor the second in 3 of 3, and the controls none.
SMB2_set_info_init(), smb2_set_ea() and set_smb2_acl() are the same in
cifs-next (9b62aa64ed00, 2026-12-03).
History. SET_INFO data first went into a 448-byte small buffer, and
the first caller with data of a variable size, 366ed846df60 ("cifs: Use
smb 2 - 3 and cifsacl mount options setacl function"), v4.13, overflowed
it with security descriptors; f46ecbd97f50 ("cifs: Fix
slab-out-of-bounds in send_set_info() on SMB2 ACE setting"), v4.18,
moved SET_INFO to the large buffer, without a bound. smb2_set_ea()
came in 5517554e4313 ("cifs: Add support for writing attributes on
SMB2+"), v4.14, with no limit; 63d37fb4ce5a ("CIFS: fix max ea value
size"), v5.4, capped the value at CIFSMaxBufSize for this copy, but not
the name and the header; the check above came in 85db6b7ae65f ("cifs:
make sure we do not overflow the max EA buffer size"), v5.6, for the
EAs' sake, and bounds the copy only while used_len is not negative.
f5065508897a ("cifs: Retain old ACEs when converting between mode bits
and ACL."), v5.12, made the chmod descriptor grow. 33eae65c6f49 ("smb:
client: fix OOB in SMB2_query_info_init()"), v6.7, fixed the same kind
of overflow in SMB2_query_info_init() by checking the length there.
A patch follows in reply to this mail. Like 33eae65c6f49, it checks
the length where the copy is, so that it holds for both callers: data
longer than CIFSMaxBufSize is refused with -E2BIG before the buffer is
allocated. 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 (smb2_set_ea()'s is one), and it is the limit
setxattr() already puts on a descriptor and that SMB1 has
(SendReceive()). A descriptor of 16385 to 16492 bytes, which chmod()
on SMB2 could send before, is refused too. smb2_set_ea()'s check
still accepts a negative used_len, but with the patch that can only let
through an EA that fits the request, so we left it alone. On
ksmbd-for-next, same config and image, the patch the only change
between the two builds:
without the patch the reports above; setxattr() and chmod()
return 0
with the patch no report in 6 boots (the EA 3 times, the
descriptor 3 times); no SET_INFO is sent and
setxattr() and chmod() fail with E2BIG
both the controls: setxattr() fails with ENOSPC, the
924-byte-descriptor chmod() returns 0 and the
server receives the 1096-byte descriptor
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 SMB 3.0 server and the mount in one program over loopback, and
we are happy to send it on request.
Kapil Vaswani
Piyus Kedia
next reply other threads:[~2026-12-05 20:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 20:14 Piyus Kedia [this message]
2026-12-05 20:14 ` [PATCH] smb: client: check the data length " Piyus Kedia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cifs-set-info-overflow.20261205@iiitd.ac.in \
--to=piyus@iiitd.ac.in \
--cc=bharathsm@microsoft.com \
--cc=kapil@presceralabs.ai \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pc@manguebit.org \
--cc=ronniesahlberg@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®