From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796050233; b=n62ngDQWQFBmsjcxpc8VW1mMERZvhcZLr2ZaAUu0V0FGU2PHIPNadkxnDwViemN+qelx ZCkfZvKXasN88KdGa+KfWJh5RVbQJMC8+WThjjDk4NZPD5O/TMOy+av/KZNc46pXjJrr4 PED1Uf3Whhx/pPv9yZEe33+6D606Y2yLu0R/eeyg+gWVuql+siv7WSLwW4/TIyuT/kfih S98fjymOzUfQhcXXxMUsNgGLETZyzaQSEtPPc9qW9bvoynB5fYji+xw+2PK4e+RP8j2Fr aHaBleQlpWl2VD/9ePoo79QOqiIqMgHmOD5tNQzBS8smmYfc8mctg/hhjOPas+mpzkQ== 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=VzY/zWy17NckxMmrHWUyVWMCEg8OaSfUyOP4ujBAvyUYvPoBaHRGMkbIeDsdg8TUV6xj YNgEzPgmeToHss0Pv2OryGnTYqyq+mNH7oMki0Pk0fTlS0WYHLjvKWxe48ZaLoZxreE6b CuusbwtBjkRKCCrwBBBORJZNYK8Y1zGWZvuBQrfDJsujJDexXCHJlpP4qm7lmsWSu/Dur akdPEtDCxyapYU36nawG/aLUCcMXylq6CSU+qO8vdiFpml5kAGAxEGC181XXTfx9qpSqD bwhj02Z759Xgyl1njQYhex6KLKDHIrLw3GnN5wZuPA3Z8h7LELxi9DP7uaBHi9ZH4Lg== 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.172 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 893D4606A334 for ; Mon, 30 Nov 2026 14:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 893D4606A334 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-f172.google.com with SMTP id d2e1a72fcca58-8d1aec63541so1560184b3a.3 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=tpNbxvLp5XyYh/pzAsh/92NWVxzuUb/0p7gPeG6wL1+jDp9y//NmrMPl5ezZQaD3Vq NVETWwEEzruZdbSqLmjn+34iehGkogYjFHoz0bWmWNiWojwxH3WhGEAQvje1yALAHhYQ cv1w3poMNCSIfgYNa8e2IVqN4wtIDzbowYgAIqY+MmJoODpaQQEDhY77hTg+vQDSAxh7 hlq8H+k/AGd9VvPDJOIJ7R8KBjZTTQDoBFNF5st8wXPNfvP2TYGE3Msqngff8x2/oRoK wR7rxK5ECiQRZbP0mkQWMMtT64V3qHJBl5qMe9lIBh2qsZsQ8IbmnJRm1QNqmkasR5fQ XIdQ== X-Forwarded-Encrypted: i=1; AL+hErHQEmttLTLSlimuk62WDxF15nHWSbKR6Gh4XN6oMOgIaNJvCrjAhDNed7K4tkl80lGZ9kVvFWeVShiShq0=@vger.kernel.org X-Gm-Message-State: APuU4Z+8Ng1HB3GlruOAxvRM0s33lRozsc1HAZIqDpwvhqPCF7qCf1ic zKsWQyRAHJKebROkZ+zGnRdb8XfwKSIdfuwR3x6IKpmBGW42L5XwnuWf X-Gm-Gg: AZFdTZcyMxHNo+blzo28hxWkVpdcQRR7uKabynZH7JX+3m/hyVOuHcl5Ke4E5ZcfcdP M0qU2FTLRQZcmjz5fnulIUsF7lknD+QeQSHwdRkJ9lkccacKwhH9QScpegBGBXvWBUjw0pmEgt3 eWFaOZ/IZzp5YwlNMkstnRm/K188GbfjyFRx1GJ8HI3Cwg4Ci1VxwRhumnTT2CNBZ9hb+PsS4Yl Tl7G+Z7JTxJYp/Gl0s4/S3H3iyQO9n052AqITqMXwuTtEC4Egpej8MFbff2UBw1/CTnDot4rFdJ 2+Q8V+Lp71UUf7TMYinw8N3XndbW5Q2OQfND9r8VenRj92PlB+G/pp3kv8n9JuIrSnDYR/hf0TD E3jX6Mob6JX81aFHIDrv6zGopkjTbT4Bbb/QJXiG7jqetVWB7RkD45HIGwoVRUlhHTr4Fb3NbRm fgY6SoaYFs5bL7GnKzyJYJMWDDar0ifgC7hi5OdREZRYlyMHAam9qEOWbQc4090O/vplckXB+Qn 9/ho3NKHO5ueR6SMGrrXJr1sGN0PW8rVbhvzrzY/InSk7BdhwpGWubfcrf2X1PMNz8Muoa/IE+o XqUGtVvQYduUur1JtTfCwFflRngdzriy 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: linux-kernel@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