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=uRiMpmDeAKHv+/5ct/Iq35Cg+sEAs4OxzdP7/MYsizPBr7QYMMkovXBvUBfarGgOgEyU trB2zEExt2vtsGJkauXJRzDxVHiKdWuN0Pw0drIoPZ8fVHVaI3UH3bJ+hIFx8WJXnWRug C3mkM682a9mv5tZEDB52vW3SeapwIpI54+hiFvLHsbu5PSES8fB6HKqcH/BmlAsL9INud uaPszSv6OEFf5ybLvQHNYxHkiYYQ+VF4GDnSNZltEOkkgDuBTzyiFwAQwzc8Z9gqe1DmF AXTLozh/ZuhaXSHUKo9su0uulxLbCuCOJMG9GUijADKN+70KkSHAM1VNvDvnVXB2Wpg== 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=v1giMhWFC8Up8otPabXN/AJZ01wMGcnNubkGkPB0meik5N2pHFo4cnorOlmHOyy28iZc frEEPuYH+aOG5hbZjfrQOoIiJAHhqwsMj9YxLXluZaE7Q1zz8hzckUZcnXTJmcGwSLvXJ v4nfQOhYSvf2wrZkFarerVnIRKmwlP+WC3t6JR9HyQ/FAPytuppLaaqJhILvIRJRlNTe+ gFG+mSd80Uyoq/ryk6k+2Umms5aIBPHVH/DS/TasNH1dqyern10Lvc8dZij3isRWceGZo Us+pdWA5K0mOUgx+DFlvwnE0QvBHNc0Mhiks/UkvrGq0F0w0Oz43EpMX0CMZpCZLIlw== 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 5ED7A606A33B for ; Sun, 6 Dec 2026 04:15:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5ED7A606A33B 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-921df0f173cso44016306d6.1 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=BnW4Kwhx8r1/5UMsKXzRyVGkg4c/uH9F9uoqLMmYYxt3V/8HTlD7DJig6EnAptfdJV tDPHZnuc1eNHl7/BrO6/6ElAiYmbTavyQ54JkfMZez8263Hkcqrk57WEeb/6y3yTNqrF rax1TpZe61/LJi7wohLSLDxzU4t3zHU1mTX2P61aARkurptM0RfKwBWNlvizK2b3IKKz txDS+ZchkpCnEEHxZLTG6cuhXWZTa0u5fw71j7lLGUi8qb8XSMjjFi40iPE0CWdu+YEo 0boeAR0KB84tKIP/JpwEUIGdjzaltKkFJCjQwRqncRnG/FsEIEuyUz8O0XgW7hqCoReG OdrQ== X-Forwarded-Encrypted: i=1; AL+hErE6gE0KR1YwEG7cvUdmLdAXnE5s6H18NPQ6Vx5oB/MHgUFLllX+hCdn9L/qaVzEY7QjRKPQsftp3lOpjkc=@vger.kernel.org X-Gm-Message-State: AB4q+uEuWnnpRmNoemKUKDpKQ5MFf3sdq5y/3XL6jcVHbdTa9TVt2PDA AmzxkvBAdy3f6oIfJo6VxYF/huwkNf0BHi1wDB5xkop/8NH7rp3F0KjdOHQS684Wj7RELJuceHA FPhy2d6DEIg== 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-kernel@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