From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796530516; b=GSDLZ9Wrg036u+SvZtap/Wm7bi47hk3nYykA/GUYu44+U4F3oFy6uipavYVIJ5Ldpzfu +mdIXSrOf2ZWetqdTtChnbTJshyICSagXLp2d8Rx2tmtRq02/rOER9tORfallxlpif1BU 7Kbbc2Vs6eshUvcPKkyRXQkJSTXR/Wo+2zqbDDlwp81YNhHQl1gHdJDNmcGOJvsSXm4D4 VOm1kQwJ9qYMisborM8vMQVO7RcBCrjIK60ZgPne+3cGIc/t3DNp1bLBTUP0TCqof8AtH AWHrrUU5UcF9Rq+k77NuKS7B4vRrjelWTYuQPhL1VzMJaguWHdbaLaT7ZMq+iiHDv3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796530516; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=lLYk2bwllfug78ZwZCf0K42EVBj3aco5INKSY6XLWuk=; b=n8P51rOWYPF99J/HzD1ibgQxVVXn8TlqFhSMwGKTP/DzY8/hb7EoE1PmoKkAZsNP4FLS fJpwvXBLs/izPMiWo2jN1gk94m1q8MsMWtfRu5/zZCNDce54TaqNmBTgqsql4hKtJy23s 3Ll2zdDsdawD5X2PWyWc2VWBH7zYR2fXMkIBZqMAxrwPqmdEAYkGdISn+kIqcR0yuTP1H 1euDxpyUUsMrXetaqfG8Kxdc4EkMjO3PU16B3K9LgjSiPYf7A/HGdQnrcAr8XBagsjiv/ JjsTJYBeq0jKzuiFEpClYMG4UNvmLL1b9Tcb/3cknj4fKj5N01Pus70t1a2BT4pn6xg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ZzOC2zDy; arc=none smtp.remote-ip=209.85.219.70 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ED93606A33C for ; Sun, 6 Dec 2026 04:15:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5ED93606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ZzOC2zDy Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-92101559a2bso46268766d6.3 for ; Sat, 05 Dec 2026 20:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796530515; x=1797135315; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=lLYk2bwllfug78ZwZCf0K42EVBj3aco5INKSY6XLWuk=; b=ZzOC2zDyPuXZ6PRklDesTuZg6MPZnZ/L6V5M3wZ58q79L0q0qE5q6FGfbeSmk10shU uCSkE349Rj0VwcIvnbvn8M+Wjx8Lc4mx3Q/mAX5yiQ00hFg+9ifOLTQoTRx96uUJXtmm LsTaa173prfirSpGYAUTb/ONO24vRBi5dZhm9NXGNVHC4AY9HSJ8yRa82PxMQN7KT9gb Au8Hd0MrFi9nTfvgRhVcuLS5biS36isXrPh0r5EyAkfhKwoIv4bc/gyh1elWUwJlCNXU bREdqD3Pix7r4iKWuQqr7m5FQHfcL7IhcpAs3qIAlaZuai7x67W0S5Ocp8RYJLw2/b50 QkoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796530515; x=1797135315; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lLYk2bwllfug78ZwZCf0K42EVBj3aco5INKSY6XLWuk=; b=aXEyKrgD5gUQJe7q2verWDFQbuiyAYO+gNEJBydFcaYUM+DVH4oO8nx+Q8i2+j0QYw y9w0REjMxt4huybeCTsyIQ4DWUPgwmhkoxCJBwrdWpNR29OIMVmNUd63lgiPTgpWWhux 82KFK2GpXsap0N4A9xtCs5EQKG0JCW5kA6qyfc9/17eu/ypqV/hgBB+aY5DCd12hPXLg XmWReBWK7739yxlHTR92hVXxKmiiEv1uc+k1EWOAIKnYqA4y7/wQiRh/rrCiSzgLPkg0 9vNltBLYWr3eC/r4oMSp0Ye3tPPF1hdp8P8EoVUX4OFy0suMPtt08+czVzirFYrkEAOy QlJw== X-Forwarded-Encrypted: i=1; AL+hErENCqAipy3u2JifredJAfKreBE78fA4zsjxZEDP9XTSrIG8v/SH6BCxH61VPMWyExX3GLwL6fzYizF6@vger.kernel.org X-Gm-Message-State: AB4q+uFosW4ok0KcDfHNUSQtCVm4EDmOeu4wbTGCNyPwCDaVsty7+ekN pO3i9r06ZFeMJTey0muq/7bHsVR/fPHSTWY+OxTBt0v+DDWCjCyEgg/8yi5ZyRMxSkvhtE1jhwJ /YTiT7rufCA== X-Received: from qvbfh15.prod.google.com ([2002:a05:6214:1a0f:b0:921:2fdd:5df4]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:124c:b0:921:7e70:1374 with SMTP id 6a1803df08f44-921e245f6c2mr110554586d6.23.1796530515161; Sat, 05 Dec 2026 20:15:15 -0800 (PST) Date: Sat, 05 Dec 2026 23:15:14 -0500 In-Reply-To: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> 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 References: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> Message-ID: Subject: Re: [PATCH net] rds: free zerocopy cookies when the socket is destroyed From: willemb@google.com To: Nguyen Ngoc Thang , Allison Henderson 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 Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes 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; Does this mean that rds zerocopy packets can be queued indefinitely if a receiver does not read its queue? That is generally disallowed for MSG_ZEROCOPY. Packets get a deep copy on loop into __netif_receive_skb_core with skb_orphan_frags_rx. If RDS avoids that, that probably needs to be addressed. That said, even without that this race is probably reachable. Packets can be temporarily queued in the egress path as well. Will apply. > - 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 > --- > 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