Netdev List
 help / color / mirror / Atom feed
From: Allison Henderson <achender@kernel.org>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Santosh Shilimkar <santosh.shilimkar@oracle.com>,
	Sowmini Varadhan <sowmini.varadhan@oracle.com>,
	 netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	rds-devel@oss.oracle.com,  linux-kernel@vger.kernel.org,
	 syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com
Subject: Re: [PATCH net] rds: free zerocopy cookies when the socket is destroyed
Date: Tue, 01 Dec 2026 14:55:54 -0700	[thread overview]
Message-ID: <5b08f3401e844c184fdf3fba5ff403b716862d55.camel@kernel.org> (raw)
In-Reply-To: <20261130145025.123903-1-ngocthang2710.1999@gmail.com>

On Mon, 2026-11-30 at 21:50 +0700, Nguyen Ngoc Thang wrote:
> 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>

Hi Nguyen,

This looks correct to me.  Thanks!
Reviewed-by: Allison Henderson <achender@kernel.org>

Allison

> ---
> 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


      reply	other threads:[~2026-12-01 21:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:50 [PATCH net] rds: free zerocopy cookies when the socket is destroyed Nguyen Ngoc Thang
2026-12-01 21:55 ` Allison Henderson [this message]

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=5b08f3401e844c184fdf3fba5ff403b716862d55.camel@kernel.org \
    --to=achender@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ngocthang2710.1999@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=rds-devel@oss.oracle.com \
    --cc=santosh.shilimkar@oracle.com \
    --cc=sowmini.varadhan@oracle.com \
    --cc=syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com \
    --cc=willemb@google.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