smb: client: fix use-after-free of server->smbd_conn and the encryption nonce
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest8 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/8 | smb: smbdirect: add smbdirect_socket_get() and smbdirect_socket_put()fs/ include/ | +30 | 0 replies | |
| 2/8 | smb: client: return the real error from smbd_get_connection()fs/ fs/ fs/ | +33 | 0 replies | |
| 3/8 | smb: client: change server->smbd_conn only under server->srv_lockfs/ fs/ fs/ | +40 | 0 replies | |
| 4/8 | smb: client: pass server to smbd_get_parameters()fs/ fs/ fs/ +1 more | +10 | 0 replies | |
| 5/8 | smb: client: pass server to smbd_register_mr()fs/ fs/ fs/ | +5 | 0 replies | |
| 6/8 | smb: client: don't use server->smbd_conn without a reference or lockfs/ fs/ fs/ +1 more | +94 | 0 replies | |
| 7/8 | smb: client: don't use zero RDMA limits without a connectionfs/ fs/ fs/ +1 more | +38 | 0 replies | |
| 8/8 | smb: client: use a counter for the nonce of encrypted messagesfs/ fs/ fs/ | +71 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/8] smb: client: fix use-after-free of server->smbd_conn and the encryption nonce
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/[email protected]/),
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(-)
Signature · 1 line
2.43.0