Article View: linux.kernel.netdev
Article #25479Re: [PATCH net] rds: free zerocopy cookies when the socket is destroyed
From: Allison Henderson
Date: Tue, 01 Dec 2026 21:55
Date: Tue, 01 Dec 2026 21:55
92 lines
11898 bytes
11898 bytes
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
Technical Details
Message-ID:
<5b08f3401e844c184fdf3fba5ff403b716862d55.camel@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375371-linux-kernel-netdev=dewy.ruReferences:
<20261130145025.123903-1-ngocthang2710.1999@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375371-linux-kernel-netdev=dewy.ru From: achender@kernel.org (Allison Henderson) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] rds: free zerocopy cookies when the socket is destroyed Date: Tue, 01 Dec 2026 14:55:54 -0700 Organization: Usenet Network Message-ID: <5b08f3401e844c184fdf3fba5ff403b716862d55.camel@kernel.org> References: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="1826339"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:9pHaXg19ssv1sNfKcSGqbj9dO4M= sha256:5acCZLC77mqarive3P0+9WSErwpvJS2t7oQm/aIeW/g= sha1:WqJNL8u3VnommoRWmTYu+FDztJo= sha256:lPNRx2DE9F8GHxM7QCBKYNK4IKHKgTtkcYmmw/g/aOQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id E69861174B3; Wed, 2 Dec 2026 00:56:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.3 X-Spam-Status: No, score=-3.3 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TRACKER_ID=0.1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g4giTJoxvgN9; Wed, 2 Dec 2026 00:56:14 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375371-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id E86351174AD; Wed, 2 Dec 2026 00:56:03 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id DFAB12B3E8; Tue, 1 Dec 2026 21:55:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796162157; b=Zle1xWhbVb288lTSZmVg6j9h0O+QdXIkirmaIvkDymnj5THyaJT6QDNbH8bXT6RVNKiR +hpW7NUYL1eHJDzOtjXEhrjg/JPIu1frFqb335sijml0F/SC+s9B0F8eBMCpkQqKSS8RQ 0+JNPq0hZj14cmEAUa9XLjJg7rLuSQqMW25m2WQN1XoJoiZcCk5O64cnSf5dR3rR63BtH 59J9hy9RIEFkGVbLijv1LmiTSSrNhR54t9wguOVzeJIUKDOnM6WMSkUvAdp/x0UWdWQtv E9n6LPN6n1PwJQCBKmItrzQ/r3EWxpX2lULEjYcbiIZl3XNWElcasOhSPf5Pv4e1Kpw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796162157; h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject: From:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version; bh=ophzPsb90DmnSdrZ9P3otwMm69UGgGiAa/YPJHrRgtU=; b=kBPqSrZyhsFj1zV0p78IUYd/iyvdE4pH6h7YuqjPCoo18CAlc6oyax2xffy4cGeD4KWd chwWxmdrsjtn+Yxrdt5e6+vNQNf96pd4RmAgcJc2saf9VYOlx1BVMw0H3zf0MgtZbOYcK cqM4biGsTcrzwss64rP646425gJlPV/bDCNJQNvfZkxbDBeaTbIG9TsDigUdTJS2oIozf J+Qfyu2exNxEx37rBmAjZyVz9fMZiRyLSlM7Ul+/Qcisl8hve81dB/xl8bkF8IIK8cdQr U0P8Ij02OLDtmEZY2Hp6N6X2a5HLDy9PvJYY1PhmSycpUBQv9PPLuMn2ZRBKi5Lgz2w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QbLyOYPk; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94029606A32E; Tue, 1 Dec 2026 21:55:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QbLyOYPk X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796162156; b=DsacrULlQQv+DeUiNKd33JROS7hRZfcoFVVPSoKCIa8gAU/fscDxbf/2D4jI+1LDF0P9 fdVaDrFrCtVEGwA9RMh5Hn+CnUPdeCvByevA3SUulbdK+Gw+/JiwuFbTU5rscimT3KlTe hTE6Gj982tvHZe2gl9f7JEY9BroNU47LQ91LkXqSyhE1Ns82FQBIeJm+IAt1VsCqehcjE FKC96//JnKr4ED8pM6dbCVHR7hC7Gw/kb2DdcatOQ7BcORUVJuLP2kqmCw7XyD/AePWDX wr2a1khHrL1tM/YzpIq2kfbc6qmNtDFF74jGU5Ly4XBnwGP2dnBbsE84JBEMgAyxOEw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796162156; h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version; bh=ophzPsb90DmnSdrZ9P3otwMm69UGgGiAa/YPJHrRgtU=; b=xw5QcnD6i4dPrNh8mGcRyqa0/zG50Nslet8tETdB7zOuf/XHbcrpyQG9W3tC6AxWBLG0 0QTPFzZruoX5Rw6KWVrGfMwceib5azM81tawR3FzGstlZgvPBHChENe/jEgPvipdw8p6F wFL9E+OUwmloocOkpBAD/F3TqI+GHDhQpBcT89pvNXvKziwbGFECYaQ9AqkgbVXK2mHcW yn2n0sZyLjnxLjYCjTxgJlcsQHUIYoDXfVs0Z+rfhLQDwDpfUP1LV6vc9OgjmUknGtE3E 5e41pBJ/xVhSolqaDNqK08nZf6+2SG2wfQ+9bP/KZXtDZqzkOcOL0+7cP31D7UiICXQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QbLyOYPk; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2BF8606A31A; Tue, 1 Dec 2026 21:55:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A261A1F00897; Tue, 1 Dec 2026 21:55:55 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796162156; bh=ophzPsb90DmnSdrZ9P3otwMm69UGgGiAa/YPJHrRgtU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=QbLyOYPklPSRVPMwK4XgZyerPmgEZcy3jNV0a6tthkPqwNCi64Px9wS6V9jn63RN7 kzw88AdLREwQktYullhJyN1TuRva1E/5OlVUWDowSG/A3P338D7+Jsb7FVD7Bb50gC oP7LBZXLPVf9y31guJKSacTiSN+6DWUNj7zgfd0oP/2vF8R4B6lLCAj5AgfZ7RKYvR cQO+C5jvfAnzuRI1xL6wOTpM+9HK3ZTUc32YKyupxL9DFGrUGeY3b9DGYIOu9QRDlQ yfBuhiRq/mQAWRlRvE6JcaK4LJDGWZ+OktBd0OCJKTWXyGpcOrLwsS3imerjzICAQX oR5t5Ro51T+jg== X-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 X-In-Reply-To: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> X-User-Agent: Evolution 3.52.3-0ubuntu1.1 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list