From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796050233; b=zySDszt1Qn3draXvyRlwBKnYRyUNEvgXEQB/GfZDTB/OY7nPoNXu3KdK6Bj/K9AkMqqY 7wDTE2sKWgu6QZ8e75bJUCfDYtUHy6gYgym+pGBMsViNqg62trGvWqgXCDDWnQOICP3Ek G6JGxvnxxIJaGmnAiD5r9yLDW14bkCd7xV1MoBQ38Tw4zHADRJJZeKHw+PLb8JEjWRcsb PRHUMrxPKwpju0rzT0lKmjy4MNh2pNRHT2qI65BzQ5APmPiyvHmyjbIghkYp0qsaLoobB uPtzcYn3iZLWXojpxBmnJ1G+HrP0TUYQ7Xz8tCV4oENNGvl4nA8cBxeZdTar36D/R6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796050233; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=B0B0wSHJ5vjknORh+V6QdK+ooXOq3/1az0+gbryey+w=; b=cYStEj6pwTim07QwxDudteLfd0KZx9Xznk2hRy5bXaB880qtaEWPjOaONjMsF9ud6h1k qwr2h4PP6I/HQxPNE+iXV+Eb48Px11bJGKDm32GfghxIxSzIE972a5RqF3fx1NqW5eZSW IkzTRLuAxTybOewaOTOhSuuX2479LBcWBzjT3OMbqGA/UfECdTTAe0XwVaaX2V55SFJNC 4tiel282SHnp1KgKYDDB116T7aCiu02xznwuVyDXGlum6bOx3WXBaCxxHO2Q9uzVR84oE Vyxe9yLsPcz6+6ORai8SlqGXv/ggL9ZZF7Ftpcy/rN3dG3EueO5YTPvT2EfqwRKzzkQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Rs75bX35; arc=none smtp.remote-ip=209.85.210.170 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 94A03606A325 for ; Mon, 30 Nov 2026 14:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 94A03606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Rs75bX35 Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-8b32bc605d9so5052697b3a.2 for ; Mon, 30 Nov 2026 06:50:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796050232; x=1796655032; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=B0B0wSHJ5vjknORh+V6QdK+ooXOq3/1az0+gbryey+w=; b=Rs75bX356aRKYjcWSEJcJJtH89SPbiDTnzf9LlepZs46h9YP/FnEEUdbez3tS5bTcY ht3Toxuk4temvlNXh7nNjjqKD6sGTahywGXt4Z3bbIRso7BlFReZbD96nl7qaByGJGWH Movh5Iep2ysuI3yep5M/JJpa2R2Dg2frkufrbVipM5AJC/OoFVOkQdnfAvqG+IM1ca/b ax4pR503N2LSHfUAHNaP42V1OlHoLjSyBSEke+0403TGfOFLGtzvww9huQeDHMAq+Sp1 +a1xn8+M5xaeQqtMEG1djXu+fwIm5VDl0Js31HOXxHqByTGwp7Gt1H4TTHH2fW4xsHZC YqbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796050232; x=1796655032; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=B0B0wSHJ5vjknORh+V6QdK+ooXOq3/1az0+gbryey+w=; b=Qw35eIibIEmwWbht5tYAjqgEjf2q1EwdVU0siRFaI/zxUia2jl49trbDSgjjrjqS1z MHi5LixU/hVh03ff7gDLd0zH7l/ZLYu6TADoPOxGPzblJjqORvUg3rHYwNzxNKOR0v4R 9MyfOO9QvLWOnIdMraMVJySQxYQz/5UkUMTlJUgU9lrAl3sQmXzNhs/0daU2NzSnz3DH qU1Ttfh0y7HPJ0Gj47GE2KtwME/hiRwwa4EaKIvzIpWc+c8nheFEC9jUS49jvsOmtVrD hut3ll+Pr3rxrFZHUI7R4QMewuIOgsycfXzwd+I7sXK426pkfblVpQbDWfT/hnkSdKWA SPzw== X-Forwarded-Encrypted: i=1; AL+hErHlxgS+c91a/3qaGUs7geSUUE0PGw5wYtgDbOkxuA4vgMSr0MynQk6X7RrdjlB6aixSZDeK2bg=@vger.kernel.org X-Gm-Message-State: APuU4Z/Z/uRja5dfXEZFZr3z29H+Sexv+HuimByXKvn9L3qTw+41z/UT Nf8kxB/4R7tkgu+Wqdid2sJh6OStaojJTTTO8KWoI+Puo6fSBdWzrrH/ X-Gm-Gg: AZFdTZfXc2GlpTpRC7Gbij4Ha5IDF2BbXXOYvR3hBtFY/JTghxThtZJ2rA1Vrqanq2F IWhAEGwWuVmTLNMHVtj4hekHRT++gmY9gJ3cgUNWSwJzENsI47doLjS5cB1Cnr5PTXEtWdwsfpA 2i3C8HWLM1F40qNBGr+xBQMN1VdIgD+aEhxbCyYw6AmuCLXaWSLxJiArzghdTX44Wtrfz/aDnXd fJ50nbqmdhn74QRGetJp0LiqwEJBGVcAToszfHCtG2dDbxR+QHGfgl6iv/DDqOqM3ggHjnUJjRh 3WJJoQrFLCVOaOJ5slLZOHY5VvrcIvB74JRlNroFhcfCHPMNp3dv8gG3+pptCzBI3qfsQhAzr+E 0p8l/lSXzh8WHHvfYkUQXdWFYWXMN+FK8XIYn0BdC8B0U9FHYf2MewqJvW5u2PjJZMxgO3zMfIs vqszHFv9tSmXnfmANg0kSwTLshFiMJkN+ALPndDKGTZeCEQCk1yURMFMzpgCAioSPmYSlsE3ebS 733Hhs1LK1u+c/VkSiKx1H7cCERMfLBxj+IMuvfC8EaNaIcAst+Zj7nytKLRgbst//Uh7rWd3Yg 960PRfacqC6SS/PNrdIjjrsijSA4yTIB X-Received: by 2002:a05:6a21:6f89:b0:3e2:7225:d14b with SMTP id adf61e73a8af0-4014c94c9famr35579326637.72.1796050231794; Mon, 30 Nov 2026 06:50:31 -0800 (PST) Received: from thangnn-ASUS.. ([2a09:bac5:d45c:2e1e::498:28]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6d0332bfsm18398602a12.22.2026.11.30.06.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 06:50:31 -0800 (PST) From: Nguyen Ngoc Thang To: 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 Subject: [PATCH net] rds: free zerocopy cookies when the socket is destroyed Date: Mon, 30 Nov 2026 21:50:25 +0700 Message-ID: <20261130145025.123903-1-ngocthang2710.1999@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Transfer-Encoding: 8bit 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 --- 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