[PATCH] smb: client: allocate the encryption AEAD before encrypting a request

From: Piyus Kedia

Date: Fri Dec 04 2026 - 23:31:54 EST


crypt_message() is handed server->secmech.enc for every request that is
encrypted, and that AEAD is only allocated at negotiate time, by
SMB2_negotiate(), when the server named a cipher:

if (server->cipher_type && !rc)
rc = smb3_crypto_aead_allocate(server);

Whether a request is encrypted is decided separately, by
smb3_encryption_required(), from the session's SessionFlags, the share's
ShareFlags and the server's SMB2_GLOBAL_CAP_ENCRYPTION, all of which the
server sets. A server that negotiates SMB 3.1.1 without an encryption
context, so that no cipher is negotiated, and then sets
SMB2_SESSION_FLAG_ENCRYPT_DATA in the final SESSION_SETUP response or
SHI1005_FLAGS_ENCRYPT_DATA in a TREE_CONNECT response, or sets
SMB2_GLOBAL_CAP_ENCRYPTION in the NEGOTIATE response for a "seal" mount,
makes the client encrypt the next request with a NULL tfm:

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+0x2c/0x170 crypto/aead.c:47
crypt_message+0x27b/0x1300 fs/smb/client/smb2ops.c:4876
smb3_init_transform_rq+0x4bf/0x610 fs/smb/client/smb2ops.c:5003
smb_send_rqst+0x187/0x300 fs/smb/client/transport.c:419
compound_send_recv+0x89a/0x1fc0 fs/smb/client/transport.c:1014
cifs_send_recv+0x43/0x60 fs/smb/client/transport.c:1197
SMB2_tcon+0x42f/0x1080 fs/smb/client/smb2pdu.c:2252
cifs_setup_ipc+0x276/0x600 fs/smb/client/connect.c:2099
cifs_get_smb_ses+0x1070/0x14e0 fs/smb/client/connect.c:2565

Until commit b0abcd65ec54 ("smb: client: fix UAF in async decryption")
crypt_message() called smb3_crypto_aead_allocate() itself, for both
directions. That commit moved the call into decrypt_raw_data(), for the
receive side, and left the send side to rely on the allocation at
negotiate time. Allocate in smb3_init_transform_rq() too, as the
receive side does.

We found this with a syzkaller-based fuzzing harness driven by an AI tool.

Fixes: b0abcd65ec54 ("smb: client: fix UAF in async decryption")
Closes: https://lore.kernel.org/linux-cifs/cifs-encrypt-without-cipher.20261205@xxxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
---
Tested on ksmbd-for-next (d70570cf8003), whose fs/smb/client is the
same as mainline's, with KASAN; this patch was the only change to
fs/smb/client between the two builds. The reproducer is a minimal SMB
3.1.1 server on loopback, with no encryption context in its NEGOTIATE
response, and a mount of it:

before KASAN null-ptr-deref in crypto_aead_setkey() from
crypt_message(), for each of: SHI1005_FLAGS_ENCRYPT_DATA on
the share, SMB2_SESSION_FLAG_ENCRYPT_DATA on the session,
and SMB2_GLOBAL_CAP_ENCRYPTION with a "seal" mount
after the request goes out encrypted, the server (which cannot
decrypt it) closes the connection, and the mount fails with
-EHOSTDOWN or -EAGAIN; no report

The patch is against cifs-next (9b62aa64ed00) and applies to mainline.

fs/smb/client/smb2ops.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 8783738a31ad..2ea3a49fc4d5 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -5032,7 +5032,18 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
{
struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
unsigned int orig_len = 0;
- int rc = -ENOMEM;
+ int rc;
+
+ /*
+ * secmech.enc is only allocated at negotiate time when the server named
+ * a cipher, but a server can require encryption without one: with the
+ * session or share ENCRYPT_DATA flag, or SMB2_GLOBAL_CAP_ENCRYPTION and
+ * no encryption context. Allocate it here as decrypt_raw_data() does
+ * for the receive side, rather than pass crypt_message() a NULL tfm.
+ */
+ rc = smb3_crypto_aead_allocate(server);
+ if (unlikely(rc))
+ return rc;

for (int i = 1; i < num_rqst; i++) {
struct smb_rqst *old = &old_rq[i - 1];
--
2.34.1