[BUG] smb: client: Kerberos session setup reads past a cifs.spnego key's payload

From: Piyus Kedia

Date: Sat Dec 05 2026 - 05:16:00 EST


Hi,

The payload of a cifs.spnego key, which the request-key helper
(cifs.upcall) supplies for a sec=krb5 session setup, is a struct
cifs_spnego_msg - version, flags, sesskey_len, secblob_len - followed
by the session key and the security blob. The key type stores it as
it comes:

fs/smb/client/cifs_spnego.c:28 (cifs_spnego_key_instantiate)
char *payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);

and records no length for it, so both session setup paths go by the
two lengths in the header alone. The only field they check is
msg->version (smb2pdu.c:1775, smb1session.c:559):

fs/smb/client/smb2pdu.c:1809 (SMB2_auth_kerberos)
memcpy(ses->auth_key.response, msg->data, msg->sesskey_len);

sess_data->iov[1].iov_base = msg->data + msg->sesskey_len;
sess_data->iov[1].iov_len = msg->secblob_len;

fs/smb/client/smb1session.c:567 (sess_auth_kerberos)
ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
GFP_KERNEL);
...
sess_data->iov[1].iov_base = msg->data + msg->sesskey_len;
sess_data->iov[1].iov_len = msg->secblob_len;

A payload whose header claims more than follows it makes them read
past its end. Here the payload is the 16-byte header alone, claiming
a 4096-byte session key and an 8-byte blob:

BUG: KASAN: slab-out-of-bounds in SMB2_auth_kerberos+0x3a8/0x5b0
Read of size 4096 at addr ffff888040f862b0 by task poc/9451
__asan_memcpy+0x24/0x60 mm/kasan/shadow.c:105
SMB2_auth_kerberos+0x3a8/0x5b0 fs/smb/client/smb2pdu.c:1809
SMB2_sess_setup+0x1b4/0x470 fs/smb/client/smb2pdu.c:2087
cifs_setup_session+0x49d/0xaf0 fs/smb/client/connect.c:4240
cifs_get_smb_ses+0xf4a/0x14e0 fs/smb/client/connect.c:2535
cifs_mount_get_session+0xc0/0x2e0 fs/smb/client/connect.c:3660
dfs_mount_share+0x2c7/0x1a40 fs/smb/client/dfs.c:352
cifs_mount+0xbd/0x810 fs/smb/client/connect.c:3942
...
__x64_sys_mount+0x22a/0x270 fs/namespace.c:4540

Allocated by task 9458:
kmemdup_noprof+0x2b/0x60 mm/util.c:138
cifs_spnego_key_instantiate+0x3a/0x80 fs/smb/client/cifs_spnego.c:28
__key_instantiate_and_link+0xf6/0x3f0 security/keys/key.c:449
key_instantiate_and_link+0x314/0x330 security/keys/key.c:544
keyctl_instantiate_key_common+0x240/0x350 security/keys/keyctl.c:1228

The buggy address belongs to the object at ffff888040f862a0
which belongs to the cache kmalloc-16 of size 16
The buggy address is located 0 bytes to the right of
allocated 16-byte region [ffff888040f862a0, ffff888040f862b0)

(task 9458 is the request-key helper), and the same payload with
vers=1.0:

BUG: KASAN: slab-out-of-bounds in kmemdup_noprof+0x46/0x60 mm/util.c:140
Read of size 4096 at addr ffff88801dde3190 by task poc/9452
__asan_memcpy+0x24/0x60 mm/kasan/shadow.c:105
kmemdup_noprof+0x46/0x60 mm/util.c:140
sess_auth_kerberos+0x2a7/0xa20 fs/smb/client/smb1session.c:567
CIFS_SessSetup+0x236/0x2f0 fs/smb/client/smb1session.c:972
cifs_setup_session+0x49d/0xaf0 fs/smb/client/connect.c:4240
...
The buggy address is located 0 bytes to the right of
allocated 16-byte region [ffff88801dde3180, ffff88801dde3190)

How it is reached. The reproducer copies itself over /sbin/request-key,
so the kernel runs it as the helper for the key cifs requests; it
assumes the authority for that key and instantiates it with the
payload above. The same program runs a minimal SMB server on loopback
(SMB 3.1.1, or NT LM 0.12 with extended security), which prints the
security blob of the SESSION_SETUP it gets and refuses it with
STATUS_LOGON_FAILURE, and mounts it with sec=krb5,username=u. The
mount fails with EACCES after the report. With consistent lengths
(a 16-byte session key and an 8-byte blob that are in the payload)
there is no report, the server receives exactly those 8 bytes, and the
mount fails the same way.

Impact - who can trigger it:

- The two lengths come from whatever instantiates the key, and only
the request-key helper can. cifs requests the key under its own
credentials, spnego_cred (cifs_spnego.c:176-177); the kernel runs
/sbin/request-key for it as root, with the key's authorisation key
in a new session keyring for the helper
(security/keys/request_key.c:137-150 and 196); and
KEYCTL_INSTANTIATE is refused to a caller that has not assumed that
authority (security/keys/keyctl.c:1194-1205). Since 3da1fdf4efbc
("smb: client: reject userspace cifs.spnego descriptions"), in
v7.1, the type's vet_description also refuses cifs.spnego keys
that userspace creates with add_key(2) or request_key(2)
(cifs_spnego.c:54); on ksmbd-for-next both failed with EPERM for us
as root. So the trigger is a root helper that sends a malformed
payload - a buggy or compromised cifs.upcall, or whatever else
/etc/request-key.conf runs for cifs.spnego - and the patch is
hardening against that helper, not a fix for something an
unprivileged user or an SMB server can reach.

- cifs.upcall from cifs-utils sizes the payload from the session key
and blob it gets from GSSAPI and writes the same two lengths into
the header, so its keys are consistent whatever a user's
credentials hold. That is from its source, not from a test:
cifs-utils was not on our test machine and we did not run it. We
know of no way to make it send inconsistent lengths.

- What the reads do. Both happen in the task doing the session
setup (the mount, in our runs). The sesskey_len bytes are copied
into ses->auth_key.response, the session key that signing and (for
SMB3) encryption keys come from; the key itself is not sent. The
secblob_len bytes at msg->data + sesskey_len are sent to the server
as the security blob of the SESSION_SETUP request, so memory beyond
the payload goes out on the wire. With the 16-byte payload above,
our server received 8 bytes read from 4096 bytes past the payload's
end; in one of the four SMB 3.1.1 runs they were
f8 68 6a 19 80 88 ff ff, a kernel address (ffff8880196a68f8) read
little-endian. With a 32-byte payload that holds the 16-byte
session key it claims but no blob, and claims a 64-byte blob, KASAN
reports the read where the request is copied into the socket:

BUG: KASAN: slab-out-of-bounds in _copy_from_iter+0x75e/0xea0
Read of size 64 at addr ffff888043e38de0 by task poc/9450
_copy_from_iter+0x75e/0xea0
tcp_sendmsg_locked+0xd78/0x2740
...
smb_send_kvec+0x130/0x410
__smb_send_rqst+0x494/0xc20
...
SMB2_sess_sendreceive+0x145/0x520
SMB2_auth_kerberos+0x3ec/0x5b0
The buggy address is located 0 bytes to the right of
allocated 32-byte region [ffff888043e38dc0, ffff888043e38de0)

and the same with vers=1.0. KASAN skips a copy it reports, so in
those runs the server got zeros. KASAN also reports only once per
boot, so we ran the same payload again after the 16-byte one, in
the same boot: the server then received the 64 bytes that follow
the payload, which held two direct-map addresses
(ffff8880217807c0, ffff888021136318) and the address of
slab_free_after_rcu_debug (ffffffff81d6ff20; this config has no
KASLR), and the same pattern with vers=1.0. The helper picks both
lengths, 32 bits each, so it picks how much is read and how far
from the payload. We did not try lengths large enough to run the
reads into unmapped memory.

Seen on 7.4.0-rc5, where the fuzzer's helper sent the same 16-byte
payload, with the same two reports at the same lines, and REPRODUCED
ON ksmbd-for-next (d70570cf8003, 2026-12-04), whose fs/smb/client is
identical to mainline (c3500c5ef648, 2026-12-04), with KASAN: the
16-byte payload gave the reports above in 4 of 4 boots with SMB 3.1.1
and 4 of 4 with vers=1.0, the 64-byte-blob payload and a payload one
byte of blob short of what it claims gave a report in the send path
in 1 of 1 boot each with either dialect, and the consistent payloads,
exact or with 4 bytes to spare, gave none in 2 of 2 boots each. The
code is the same in cifs-next (9b62aa64ed00, 2026-12-03).

The key type has stored the payload unchecked since it was added in
f1d662a7d5e5 ("[CIFS] Add upcall files for cifs to use
spnego/kerberos"), v2.6.24, whose debug dump of the payload already
went by the two lengths (as the CONFIG_CIFS_DEBUG2 dump in
cifs_get_spnego_key() still does, cifs_spnego.c:183-184). The SMB1
session setup started using them in 2442421b1764 ("[CIFS] Have
CIFS_SessSetup build correct SPNEGO SessionSetup request"), in the
same release, and SMB2 in ceb1b0b9b4d1 ("[SMB3] Fix sec=krb5 on smb3
mounts"), v4.3.

A patch follows in reply to this mail. The readers have no length to
check against, so it checks the lengths once, when the key is
instantiated: the header has to be there, and the session key and the
blob have to fit in what follows it. A payload longer than that is
still accepted. On ksmbd-for-next, same config and image, the patch
the only change between the two builds:

without the patch the reports above, and the over-reads in the
send path for the other two malformed payloads
with the patch KEYCTL_INSTANTIATE fails with EINVAL for all
three malformed payloads, the client sends no
SESSION_SETUP and the mount fails with ENOKEY;
no report in any of 12 boots, which ran the
16-byte payload 3 times per dialect (once
fewer than without the patch) and each of the
other two once per dialect
both the consistent payloads, exact and with 4 bytes
to spare, are accepted, the server receives
their 8-byte blob and the mount fails with
EACCES when the server refuses the setup

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, plays the
request-key helper, a minimal SMB server and the mount in one program
over loopback, and we are happy to send it on request.

Kapil Vaswani
Piyus Kedia