Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/8] smb: client: fix use-after-free of server->smbd_conn and the encryption nonce
@ 2026-11-27 12:41 Stefan Metzmacher
  2026-11-27 12:41 ` [PATCH 1/8] smb: smbdirect: add smbdirect_socket_get() and smbdirect_socket_put() Stefan Metzmacher
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2026-11-27 12:41 UTC (permalink / raw)
  To: Paulo Alcantara
  Cc: metze, Namjae Jeon, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
	Bharath SM, linux-cifs, samba-technical, stable

Hi Paulo,

these are client fixes reported by Sashiko:

  - smbd_get_parameters(), smbd_register_mr() and
    smbd_debug_proc_show() used server->smbd_conn without any
    locking, while cifs_abort_connection() can destroy it at any
    time (use-after-free). server->smbd_conn is now only changed
    under srv_lock and only used with a reference on its socket
    (the new smbdirect_socket_get()/put()) or under the lock.

  - smb3_negotiate_wsize() and smb3_negotiate_rsize() used the zero
    limits of a missing connection during a reconnect, with signing
    the header sizes were subtracted from 0, which underflows, so the
    RDMA limit was lost.

  - smbd_get_connection() returns the real error instead of -ENOENT,
    the following patches depend on that.

  - The nonce of encrypted messages is a 64-bit counter of the
    session followed by random bits of the session, like Samba does,
    instead of random bytes, which only made a reuse unlikely. With
    AES-GCM a reused nonce reveals the authentication key.

"smb: smbdirect: add smbdirect_socket_get() and smbdirect_socket_put()"
touches fs/smb/smbdirect, it's only used by the client changes.

Reports fixed by this series:

  - https://sashiko.dev/#/patchset/cover.1791225453.git.metze%40samba.org
      smb: client: don't use server->smbd_conn without a reference or lock

  - https://sashiko.dev/#/bug/linux-211bb822-8907-4243-9dd3-da2595595552
      smb: client: don't use server->smbd_conn without a reference or lock

  - https://sashiko.dev/#/bug/linux-d40006cd-d7c3-4ea8-8ebb-1bf2b55b0db0
      smb: client: don't use zero RDMA limits without a connection

The other urgent fixes for fs/smb/smbdirect and ksmbd (including
the same nonce fix for the server) are posted separately, they are
independent of these, the remaining smbdirect fixes follow on top of
all of them.

This also covers the problem addressed by "[PATCH v3] smb: client:
protect server->smbd_conn with RCU and refcounting" from Qican Ma
(https://lore.kernel.org/all/179570959875.92741.4311009098248753929@gmail.com/),
without waiting for references in smbd_destroy(), which is called
with cifs_server_lock() held.

These patches were developed with the help of Claude (Anthropic),
which was used for code analysis, writing parts of the code and the
commit messages. I reviewed all changes and take full responsibility
for them.

Testing: on real hardware, client and server running the urgent
client and smbdirect series together, over RoCE with mlx5 (ConnectX),
irdma (Intel E810) and rxe:

  - xfstests (59 tests of the cifs and generic groups) and O_DIRECT
    reads/writes with data verification
  - removing the local address or setting the link down while a
    connection is established, the umount finishes in time
  - 2x10 ksmbd restarts while I/O is running and
    /proc/fs/cifs/DebugData is read in a loop, each restart reconnects
  - mounts killed by a signal while their RDMA connect is pending
    (the syzbot case), no tasks in D state and no warnings

Note I didn't test with iWarp as there are existing problems with it,
I have patches to fix iWarp, but I'll post them later, as they
also rely on some rdma-core changes.

As we are already late in the 7.4 cycle, I leave it up to you to
decide if they should still go into 7.4 or into the next merge
window, all of them are marked for stable.

Base: v7.4-rc4, like the other smb series. The patches also apply
cleanly (git am) on cifs-next (61c581ea62ee), on ksmbd-for-next
(3c31349456c5) and on both merged, with or without the urgent smbdirect
series, and build on both merged.

Stefan Metzmacher (8):
  smb: smbdirect: add smbdirect_socket_get() and smbdirect_socket_put()
  smb: client: return the real error from smbd_get_connection()
  smb: client: change server->smbd_conn only under server->srv_lock
  smb: client: pass server to smbd_get_parameters()
  smb: client: pass server to smbd_register_mr()
  smb: client: don't use server->smbd_conn without a reference or lock
  smb: client: don't use zero RDMA limits without a connection
  smb: client: use a counter for the nonce of encrypted messages

 fs/smb/client/cifsglob.h  |   3 +
 fs/smb/client/connect.c   |  18 ++--
 fs/smb/client/file.c      |  12 +--
 fs/smb/client/misc.c      |   2 +
 fs/smb/client/smb2ops.c   | 111 ++++++++++++++++++++-----
 fs/smb/client/smb2pdu.c   |   4 +-
 fs/smb/client/smbdirect.c | 170 ++++++++++++++++++++++++++++++--------
 fs/smb/client/smbdirect.h |  11 ++-
 fs/smb/smbdirect/socket.c |  27 ++++++
 include/linux/smbdirect.h |   3 +
 10 files changed, 291 insertions(+), 70 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-27 12:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 12:41 [PATCH 0/8] smb: client: fix use-after-free of server->smbd_conn and the encryption nonce Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 1/8] smb: smbdirect: add smbdirect_socket_get() and smbdirect_socket_put() Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 2/8] smb: client: return the real error from smbd_get_connection() Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 3/8] smb: client: change server->smbd_conn only under server->srv_lock Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 4/8] smb: client: pass server to smbd_get_parameters() Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 5/8] smb: client: pass server to smbd_register_mr() Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 6/8] smb: client: don't use server->smbd_conn without a reference or lock Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 7/8] smb: client: don't use zero RDMA limits without a connection Stefan Metzmacher
2026-11-27 12:41 ` [PATCH 8/8] smb: client: use a counter for the nonce of encrypted messages Stefan Metzmacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox