[BUG] smb: client: NULL tfm in crypt_message() when the server requires encryption without a cipher
From: Piyus Kedia
Date: Fri Dec 04 2026 - 23:31:52 EST
Hi,
The client encrypts a request with server->secmech.enc whenever
smb3_encryption_required() says the session or share needs it, but
that AEAD is only allocated at negotiate time, and only when the server
named a cipher:
fs/smb/client/smb2pdu.c:1391 (SMB2_negotiate)
if (server->cipher_type && !rc)
rc = smb3_crypto_aead_allocate(server);
smb3_encryption_required() (smb2pdu.c:77) decides from values the
server sends: SMB2_SESSION_FLAG_ENCRYPT_DATA in the session flags,
SHI1005_FLAGS_ENCRYPT_DATA in the share flags, and, for a "seal" mount,
SMB2_GLOBAL_CAP_ENCRYPTION in the server capabilities. For SMB 3.1.1
a cipher is negotiated only through an encryption context, which a
server can leave out of its NEGOTIATE response. The next request is
then encrypted with a NULL tfm:
fs/smb/client/smb2ops.c:5003 (smb3_init_transform_rq)
rc = crypt_message(server, num_rqst, new_rq, 1, server->secmech.enc);
BUG: KASAN: null-ptr-deref in crypto_aead_setkey+0x2c/0x170
Read of size 8 at addr 0000000000000020 by task poc/9466
crypto_aead_setkey (include/linux/crypto.h:458 crypto/aead.c:47)
crypt_message (fs/smb/client/smb2ops.c:4876)
smb3_init_transform_rq (fs/smb/client/smb2ops.c:5003)
smb_send_rqst (fs/smb/client/transport.c:419)
compound_send_recv (fs/smb/client/transport.c:1014)
cifs_send_recv (fs/smb/client/transport.c:1197)
SMB2_tcon (fs/smb/client/smb2pdu.c:2252)
cifs_setup_ipc (fs/smb/client/connect.c:2099)
cifs_get_smb_ses (fs/smb/client/connect.c:2565)
cifs_mount_get_session (fs/smb/client/connect.c:3660)
dfs_mount_share (fs/smb/client/dfs.c:352)
cifs_mount (fs/smb/client/connect.c:3942)
cifs_smb3_do_mount (fs/smb/client/cifsfs.c:1132)
smb3_get_tree (fs/smb/client/fs_context.c:917)
vfs_get_tree (fs/super.c:1881)
...
__x64_sys_mount (fs/namespace.c:4540)
BUG: kernel NULL pointer dereference, address: 0000000000000020
How it is reached. The reproducer is a minimal SMB 3.1.1 server on
loopback and a mount of it in the same program. Its NEGOTIATE response
carries a preauth integrity context and no encryption context, so no
cipher is negotiated, and any one of these then crashes the mount:
1. SHI1005_FLAGS_ENCRYPT_DATA in the TREE_CONNECT response's
ShareFlags (SMB2_tcon() stores them unchecked, smb2pdu.c:2281);
2. SMB2_SESSION_FLAG_ENCRYPT_DATA in the final SESSION_SETUP
response; the crash is then in the IPC tree connect,
cifs_setup_ipc() -> SMB2_tcon(), as in the trace above;
3. SMB2_GLOBAL_CAP_ENCRYPTION in the NEGOTIATE Capabilities and the
"seal" mount option. The check that refuses a seal mount on a
server without encryption reads that capability bit, not whether a
cipher was negotiated; without the bit the same mount fails
cleanly with -EOPNOTSUPP.
All three crashed the client on 7.4.0-rc5, where we found them, and
each crashed it again on upstream (below).
The receive side does not have the problem: decrypt_raw_data()
allocates the AEAD itself when it is missing. Until b0abcd65ec54
("smb: client: fix UAF in async decryption"), in v6.12, crypt_message()
called smb3_crypto_aead_allocate() for both directions; that commit
moved the call into decrypt_raw_data() and left the send side relying
on the allocation in SMB2_negotiate().
Impact - who can trigger it:
- The SMB server the client connects to. All three triggers are
values in the server's own NEGOTIATE, SESSION_SETUP and
TREE_CONNECT responses, so a malicious or compromised server can
crash any client that mounts it, including one a DFS referral
sends the client to. Our server accepted the client's NTLMSSP
authentication without checking it, and the mount options were
ordinary ones.
- A local unprivileged user cannot trigger it directly: mount(2) of
cifs needs CAP_SYS_ADMIN in the initial user namespace (the
filesystem is not FS_USERNS_MOUNT). Where an administrator allows
user mounts through mount.cifs, the server is the one the
administrator configured; we have not tested that.
- What happens: a read through a NULL pointer (address 0x20) in the
task that sends the request - the mounting task in our runs. The
kernel oopses and kills that task; on a system with panic_on_oops
set it panics. It is a denial of service; nothing is written and
nothing is read back to the server.
Seen on 7.4.0-rc5 and REPRODUCED ON UPSTREAM: on ksmbd-for-next
(d70570cf8003, 2026-12-04), whose fs/smb/client is identical to
mainline (c3500c5ef648, 2026-12-04), with KASAN, each of the three
triggers gave the report above in its run (the trace is trigger 2's).
The code is the same in cifs-next (9b62aa64ed00, 2026-12-04), which
changes fill_transform_hdr() beside the call but not the tfm passed to
crypt_message().
A patch follows in reply to this mail. It allocates the AEAD in
smb3_init_transform_rq() when it is missing, as decrypt_raw_data()
does on the receive side. With it, same config and image and no
other change to fs/smb/client, none of the three crashes: the client
sends the request encrypted (with AES-128-CCM, since no cipher was
negotiated, as it did before v6.12), our minimal server, which cannot
decrypt it, closes the connection, and the mount fails with -EHOSTDOWN
(trigger 1) or -EAGAIN (2 and 3). No KASAN report.
Whether the client should refuse such a server outright - for example
not accept SMB2_GLOBAL_CAP_ENCRYPTION from a 3.1.1 NEGOTIATE response
that has no encryption context - is a separate question that we leave
to you; the patch only restores the behaviour from before v6.12.
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 server and the mount in one program over loopback, and we
are happy to send it on request.
Kapil Vaswani
Piyus Kedia