From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A261A1F00897; Tue, 1 Dec 2026 21:55:55 +0000 (UTC) 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== Message-ID: <5b08f3401e844c184fdf3fba5ff403b716862d55.camel@kernel.org> Subject: Re: [PATCH net] rds: free zerocopy cookies when the socket is destroyed From: Allison Henderson To: Nguyen Ngoc Thang Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Willem de Bruijn , Santosh Shilimkar , Sowmini Varadhan , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org, syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com Date: Tue, 01 Dec 2026 14:55:54 -0700 In-Reply-To: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> References: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1.1 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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: >=20 > - over loopback, the receiver's queue holds the message itself, so it > outlives the sender if the sender closes first; >=20 > - 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(). >=20 > 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: >=20 > unreferenced object 0xffff88812a3e1880 (size 64): > backtrace: > __kmalloc_cache_noprof > rds_message_copy_from_user > rds_sendmsg >=20 > 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. >=20 > Fixes: 401910db4cd4 ("rds: deliver zerocopy completion notification with = data") > Reported-by: syzbot+b3f058b8e3b0d80d5bfb@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=3Db3f058b8e3b0d80d5bfb > Signed-off-by: Nguyen Ngoc Thang Hi Nguyen, This looks correct to me. Thanks! Reviewed-by: Allison Henderson Allison > --- > Testing (QEMU, 4 vCPUs, kmemleak and PROVE_LOCKING, on net e2fb9368a416): >=20 > 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. >=20 > - 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. >=20 > 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. >=20 > 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. >=20 > net/rds/af_rds.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) >=20 > 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); > =20 > spin_lock_bh(&rds_sock_lock); > list_del_init(&rs->rs_item); > @@ -672,6 +671,9 @@ static void rds_sock_destruct(struct sock *sk) > =20 > WARN_ON((&rs->rs_item !=3D rs->rs_item.next || > &rs->rs_item !=3D rs->rs_item.prev)); > + > + /* Messages hold a sock ref until they have queued their cookie. */ > + rds_notify_msg_zcopy_purge(&rs->rs_zcookie_queue); > } > =20 > static int __rds_create(struct socket *sock, struct sock *sk, int protoc= ol) >=20 > base-commit: e2fb9368a41662bc54624f9be87ea8989b109306