syzbot
memory leak in rds_sendmsg
Status:
upstream: reported C repro on 2026/11/29 23:17
Subsystems:
rds
Labels:
prio:high
[Documentation on labels]
Reported-by: syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com
First crash: 1d01h, last: 1d01h
✨ AI-generated root cause summary:
A struct rds_msg_zcopy_info object allocated in rds_message_zcopy_from_user() can be leaked when an RDS socket is closed before all of its queued zerocopy rds_message objects have been freed. rds_release() purges rs->rs_zcookie_queue after rds_send_drop_to(), which removes messages from the socket and connection queues but does not clear rm->m_rs or wait for transport references such as cp->cp_xmit_rm to be dropped. When the last reference to the rds_message is later released, rds_message_purge() unconditionally calls rds_rm_zerocopy_callback(), inserting the rds_msg_zcopy_info into rs->rs_zcookie_queue before calling sock_put() to drop the final socket reference. Because rds_sock_destruct() does not purge rs->rs_zcookie_queue, the socket is freed while the zcopy notification object remains linked in the now-freed queue.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
The leaked 64-byte object is a struct rds_msg_zcopy_info allocated in rds_message_zcopy_from_user() (net/rds/message.c:456), with zcookies.num == 1, zcookies.cookies[0] == 0x42, and rs_zcookie_next pointing to &rs->rs_zcookie_queue.zcookie_head of a freed struct rds_sock.
Triggering Sequence and Violated Lifecycle Invariant
-
Zerocopy allocation and queuing (rds_sendmsg -> rds_message_zcopy_from_user -> rds_send_queue_rm):
- When
sendmsg() is called on an AF_RDS socket with SO_ZEROCOPY and MSG_ZEROCOPY, rds_message_zcopy_from_user() (net/rds/message.c:442) allocates struct rds_msg_zcopy_info *info and stores &info->znotif in rm->data.op_mmp_znotifier.
rds_cmsg_send() -> rds_cmsg_zcopy() (net/rds/send.c:1057) records the user cookie (0x42) in rm->data.op_mmp_znotifier->z_cookie.
rds_send_queue_rm() (net/rds/send.c:905) queues rm onto rs->rs_send_queue and cp->cp_send_queue, sets rm->m_rs = rs, and takes a socket reference via sock_hold(rds_rs_to_sk(rs)).
-
Transmission reference outliving socket close (rds_send_xmit):
rds_send_xmit() (net/rds/send.c:192) dequeues rm from cp->cp_send_queue, moves it to cp->cp_retrans, takes an additional reference via rds_message_addref(rm) (net/rds/send.c:332), and assigns cp->cp_xmit_rm = rm (net/rds/send.c:392).
- If
conn->c_trans->xmit() returns <= 0 (e.g., -EAGAIN turned into 0 or a connection error in rds_tcp_xmit()), rds_send_xmit() breaks out of its loop without clearing cp->cp_xmit_rm (net/rds/send.c:457-458), or rds_send_xmit() may still be running concurrently when the socket is closed.
-
Premature zcopy queue purge in rds_release() (net/rds/af_rds.c:59):
- On
close(), rds_release() marks the socket SOCK_DEAD (sock_orphan(sk)), calls rds_send_drop_to(rs, NULL) (net/rds/af_rds.c:78), and then calls rds_notify_msg_zcopy_purge(&rs->rs_zcookie_queue) (net/rds/af_rds.c:81), followed by sock_put(sk) (net/rds/af_rds.c:90).
rds_send_drop_to() (net/rds/send.c:809) removes rm from rs->rs_send_queue and cp->cp_send_queue/cp->cp_retrans, drops those list references, and waits in rds_message_wait(rm) (net/rds/message.c:587) only for RDS_MSG_MAPPED (which is only set for RDMA/atomic operations, never for data payloads). It neither clears rm->m_rs nor waits for cp->cp_xmit_rm (or any concurrent rds_send_xmit()) to drop its reference.
- As a result,
rm remains alive with rm->m_rs == rs (keeping sk alive via sock_hold) after rds_notify_msg_zcopy_purge(&rs->rs_zcookie_queue) has already run.
-
Post-release queuing in rds_message_purge() and missing cleanup in rds_sock_destruct():
- When the final reference to
rm is later dropped (for instance, in rds_send_path_reset() at net/rds/send.c:70-79 or rds_conn_path_destroy() at net/rds/connection.c:549-550), rds_message_put() calls rds_message_purge(rm) (net/rds/message.c:132).
- Unlike the RDMA/atomic notification paths (
rds_rdma_send_complete(), rds_send_remove_from_sock()), which check RDS_MSG_ON_SOCK before adding to rs->rs_notify_queue, rds_message_purge() (net/rds/message.c:146-155) unconditionally calls rds_rm_zerocopy_callback(rs, znotifier) whenever rm->m_rs is non-NULL, without checking sock_flag(rds_rs_to_sk(rs), SOCK_DEAD).
rds_rm_zerocopy_callback() (net/rds/message.c:94) initializes info->zcookies (num = 1, cookies[0] = 0x42) and links info->rs_zcookie_next onto rs->rs_zcookie_queue.zcookie_head.
rds_message_purge() then calls sock_put(rds_rs_to_sk(rs)), dropping the last reference to sk and invoking rds_sock_destruct() (net/rds/af_rds.c:669), which does not call rds_notify_msg_zcopy_purge(&rs->rs_zcookie_queue).
- Consequently,
rs is freed while info remains linked in rs->rs_zcookie_queue.zcookie_head, leaking the struct rds_msg_zcopy_info object.
Sample crash report:
* Struck through repros no longer work on HEAD.