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=1796530517; b=GOepX6trj+QYwTiQMY+A5lw+O5Bo4HvPsXsoA5K20V4YyLtuYzC/AZ5dSbjhO02KtlQu +ydjhQT1pvRQ1mHRvi2cuQiYPHX06JpNgiOXXUdaPvvte/3Lgtj7wNDSYW1P0MQgm9Ooj tFhWtgyCd6Xu/TjhZgQYj7pceHQ/3EjCOVuM6dd3bnqBpj3GvGHkWDb7+OEE1j1MEcAPB QY5PKcQ7oJ0HmyCIDVqST1gYmewhX2ndjEWYh0QXH0oJt2G01b3nODFYERgoYrOHu7Tq9 k11UtbMsXR54f8+0uvITjjfAUePl7P1zVMGvY2tkZultZZr1a7ekZgf7d7u2P8ubtRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796530517; 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=pmFw5FE+eskrRcYfWJyDSAXTEr96robIR400S6lO2rkbZKz8q2iAlIgcmQg9QIP02/Do nDx8fofJtTlf08f8tJbEbIPk4fQPEnf8xfG3+160KBeiRNHlqT+ugBrofBO/X04x8Vqfi BNTsJm1O6U4cb3HvEpXSrGAHjz/LfiTfrzgaR8QaE5pocKAr08PU6eYG0LuBN8t9/V4zA R+IhOSQpcPr2IwF3qIxcwMJvHl2ZJ3U+0Ks+Dg11DNm/0nzHMo1gFem/aeZlmzK2rUF5d KL5hNHs+JMhVY8dK9IEYXYiZCSJbeom+MN7/ZA/5HWBHZv03M/sY0EU67kirKWwxVSg== 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 5FA84606A33D for ; Sun, 6 Dec 2026 04:15:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FA84606A33D 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) 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-921d248bf3eso41131906d6.2 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=AfNgppb49u/YmFJppq4PUTD2jq64v4zPx8N9OYa4UcjkMwwRm6//guTrFxWSbzgxSZ 8kDjAAQWks3bajbzbsWTTdwJIy+NFhtmgfE51ixPjx6XK2/43gsuNHduUo4Ou7qcK2wh P8PzgGcro4gfffBrw2+Cz3zTh6h2eK1DSwMMTNsDlCOYsZzIYLnXQRWL6RKU8YVyMc0O RwcforlwXCIiJNsef1KHFOvBdov1Q8GbMychEdMLCcRex5+PvRDsBLUFjqufrEbhAaEl FWe+MNRXsSzLLm5k4Vo96ejTdIQ+al9s9lSkD07VROTiHEQfXbsyIwtUtkV+DJCTXi4w uqJA== X-Forwarded-Encrypted: i=1; AL+hErEPPIVuQuyPTMtLUKqQhefitKVx5iNEyVcrKkibrDqqGGnZDY505NazUiDFLx+Lf8eIUDaX0cg=@vger.kernel.org X-Gm-Message-State: AB4q+uFxGZjMmdZSoDL95AR9d3pxgP20f4I8rl9m3u3J2QEoR0XX8aOe caZIPRkTtyiusrdANk4bzNwe/dRdol5fxFV2AJXJfmvo4Q2Lh2ZzWmA+Rrn5k5zOFu/kwx1DUHE TXHwWtJEUUw== 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: netdev@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