* [PATCH net] rds: free zerocopy cookies when the socket is destroyed
@ 2026-11-30 14:50 Nguyen Ngoc Thang
2026-11-30 14:58 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Nguyen Ngoc Thang @ 2026-11-30 14:50 UTC (permalink / raw)
To: Allison Henderson
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Willem de Bruijn, Santosh Shilimkar,
Sowmini Varadhan, netdev, linux-rdma, rds-devel, linux-kernel,
syzbot+b3f058b8e3b0d80d5bfb
rds_release() frees the zerocopy completion cookies still queued on the
socket, but more can be queued after that. A cookie is only queued when
the last reference to its message is dropped, and rds_send_drop_to()
does not wait for references held elsewhere:
- over loopback, the receiver's queue holds the message itself, so it
outlives the sender if the sender closes first;
- rds_send_xmit() holds a reference to the message it is sending, and
may be running in a worker or in another socket's sendmsg().
rds_message_purge() then adds the cookie to the closed socket and drops
the message's socket reference. Nothing empties the queue again before
the socket is freed, so the cookie is leaked:
unreferenced object 0xffff88812a3e1880 (size 64):
backtrace:
__kmalloc_cache_noprof
rds_message_copy_from_user
rds_sendmsg
Free the cookies in rds_sock_destruct() instead. Each queued message
holds a socket reference until its cookie has been queued, so none can
be added after that. The purge doesn't sleep, so it is safe in the RCU
callback that destroys bound sockets.
Fixes: 401910db4cd4 ("rds: deliver zerocopy completion notification with data")
Reported-by: syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b3f058b8e3b0d80d5bfb
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
Testing (QEMU, 4 vCPUs, kmemleak and PROVE_LOCKING, on net e2fb9368a416):
I used my own test program rather than the syzbot reproducer. It sends to
a local, non-127/8 address, so the sockets use TCP but the connection
uses the loopback transport.
- Sender closes before the receiver reads, 51 messages. This needs no
race. Leaked cookies: 51 before, 0 after.
- 8 threads that each open a socket, send to it and close it: one run
of 400 sends, then three of 40000. Total leaked cookies, including
the 51 above: 2243 before, 0 after, in each of three boots.
- Cookies are still delivered to an open sender: 100 of 100, both
before and after the 40000-send runs.
Lockdep reported nothing up to and including the 400-send run. The
40000-send runs then hit "MAX_LOCKDEP_KEYS too low!", with and without
this patch, which turns lockdep off. The trace points at workqueues that
__rds_conn_create() allocates and destroys, so it is a separate issue.
This does not apply directly to linux-next, where net-next adds code next
to the line removed from rds_release(), but a 3-way merge is clean.
net/rds/af_rds.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c
index fb6b8ddb2d111..2e4d7888c9851 100644
--- a/net/rds/af_rds.c
+++ b/net/rds/af_rds.c
@@ -78,7 +78,6 @@ static int rds_release(struct socket *sock)
rds_send_drop_to(rs, NULL);
rds_rdma_drop_keys(rs);
rds_notify_queue_get(rs, NULL);
- rds_notify_msg_zcopy_purge(&rs->rs_zcookie_queue);
spin_lock_bh(&rds_sock_lock);
list_del_init(&rs->rs_item);
@@ -672,6 +671,9 @@ static void rds_sock_destruct(struct sock *sk)
WARN_ON((&rs->rs_item != rs->rs_item.next ||
&rs->rs_item != rs->rs_item.prev));
+
+ /* Messages hold a sock ref until they have queued their cookie. */
+ rds_notify_msg_zcopy_purge(&rs->rs_zcookie_queue);
}
static int __rds_create(struct socket *sock, struct sock *sk, int protocol)
base-commit: e2fb9368a41662bc54624f9be87ea8989b109306
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] rds: free zerocopy cookies when the socket is destroyed
2026-11-30 14:50 [PATCH net] rds: free zerocopy cookies when the socket is destroyed Nguyen Ngoc Thang
@ 2026-11-30 14:58 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 14:58 UTC (permalink / raw)
To: Nguyen Ngoc Thang; +Cc: linux-rdma
> rds_release() frees the zerocopy completion cookies still queued on the
> socket, but more can be queued after that. A cookie is only queued when
> the last reference to its message is dropped, and rds_send_drop_to()
> does not wait for references held elsewhere:
>
> - over loopback, the receiver's queue holds the message itself, so it
> outlives the sender if the sender closes first;
>
> - rds_send_xmit() holds a reference to the message it is sending, and
> may be running in a worker or in another socket's sendmsg().
>
> rds_message_purge() then adds the cookie to the closed socket and drops
> the message's socket reference. Nothing empties the queue again before
> the socket is freed, so the cookie is leaked:
>
> unreferenced object 0xffff88812a3e1880 (size 64):
> backtrace:
> __kmalloc_cache_noprof
> rds_message_copy_from_user
> rds_sendmsg
>
> Free the cookies in rds_sock_destruct() instead. Each queued message
> holds a socket reference until its cookie has been queued, so none can
> be added after that. The purge doesn't sleep, so it is safe in the RCU
> callback that destroys bound sockets.
>
> Fixes: 401910db4cd4 ("rds: deliver zerocopy completion notification with data")
> Reported-by: syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b3f058b8e3b0d80d5bfb
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130145025.123903-1-ngocthang2710.1999@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 14:50 [PATCH net] rds: free zerocopy cookies when the socket is destroyed Nguyen Ngoc Thang
2026-11-30 14:58 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox