The Linux Kernel Mailing List
 help / color / mirror / Atom feed
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: NULL tfm in crypt_message() when the server requires encryption without a cipher
Date: Sat,  5 Dec 2026 10:01:35 +0530	[thread overview]
Message-ID: <cifs-encrypt-without-cipher.20261205@iiitd.ac.in> (raw)

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

             reply	other threads:[~2026-12-05  4:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  4:31 Piyus Kedia [this message]
2026-12-05  4:31 ` [PATCH] smb: client: allocate the encryption AEAD before encrypting a request Piyus Kedia
2026-12-05  7:20   ` Namjae Jeon

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-encrypt-without-cipher.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