Article View: linux.kernel.netdev
Article #8303[PATCH net] tcp: wait for TIME_WAIT teardown before freeing per-netns ehash
From: Eric Dumazet
Date: Wed, 28 Oct 2026 16:25
Date: Wed, 28 Oct 2026 16:25
52 lines
9644 bytes
9644 bytes
From: Kyle Zeng <kylebot@openai.com>
inet_twsk_kill() removes a TIME_WAIT socket from the established hash
before it finishes using the ehash lock, hashinfo and bind tables, and
before it drops the death-row reference. A running timer can therefore
unhash its socket before inet_twsk_purge() reaches it. The purge cannot
synchronize with that timer, and tcp_sk_exit_batch() can free the
private ehash and hashinfo while inet_twsk_kill() is still using them.
An unprivileged reproducer using user and network namespaces, a private
TCP ehash and a FIN_WAIT2 timer triggers a KASAN slab-use-after-free in
inet_twsk_kill(). The allocation and free stacks point to
inet_pernet_hashinfo_alloc() and inet_pernet_hashinfo_free().
Wait for an RCU grace period after purging the whole batch.
TIME_WAIT removal runs with bottom halves disabled, so this also waits
for removers that were already invisible to the purge. Keep the wait
under tcp_exit_batch_mutex, before freeing any private hashinfo.
Fixes: d1e5e6408b30 ("tcp: Introduce optional per-netns ehash.")
Signed-off-by: Kyle Zeng <kylebot@openai.com>
[edumazet: only call synchronize_net() if one netns in the batch uses a private ehash]
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/ipv4/tcp_ipv4.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index ebe5aa70374a3fd9e3305377efebec3004989945..3f8563a36db1e9ea853699ecb547af7ee9491b11 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -3561,6 +3561,17 @@ static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list)
tcp_twsk_purge(net_exit_list);
+ /* inet_twsk_kill() can unhash a socket before the purge sees it.
+ * Wait for such BH-disabled callers to finish before freeing a
+ * private ehash. This is not needed for the shared tcp_hashinfo.
+ */
+ list_for_each_entry(net, net_exit_list, exit_list) {
+ if (net->ipv4.tcp_death_row.hashinfo->pernet) {
+ synchronize_net();
+ break;
+ }
+ }
+
list_for_each_entry(net, net_exit_list, exit_list) {
inet_pernet_hashinfo_free(net->ipv4.tcp_death_row.hashinfo);
WARN_ON_ONCE(!refcount_dec_and_test(&net->ipv4.tcp_death_row.tw_refcount));
--
2.53.0
Technical Details
Message-ID:
<20261028162510.2180528-1-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352941-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352941-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net] tcp: wait for TIME_WAIT teardown before freeing per-netns ehash Date: Wed, 28 Oct 2026 17:25:10 +0100 Organization: Usenet Network Message-ID: <20261028162510.2180528-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1812923"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1Kk+wU5HqgDgbwUdHDODtGCr1Rk= sha256:rjXQIoNw3D6kbj06MDrwzqfyBIhc0hFjx3iI1htfcyg= sha1:n8UxfmpS1FCQqdPWXvujC1gmBgs= sha256:Zor97XrW1LsuEVWg7tSHJYPPzsM3j5e/A7V4vgksm4k= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9C1C1125C3F; Wed, 28 Oct 2026 19:28:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DyeGzUbzkbfO; Wed, 28 Oct 2026 19:28:05 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352941-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 09F43125C42; Wed, 28 Oct 2026 19:27:57 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 491C92994B; Wed, 28 Oct 2026 16:25:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793204716; b=SLwWwg5OU5lpPCpHSmutZ9/wM+CsDC35CZWpF0Y9d/LgOjGaW6SnYiyBVnV0b5cdP0Nk 88n5OoOKmz9teV6veDrWchGUTaBpdFSvFhPU9wHx1zRj2bpK1Q032kVq1a3DAOvUfHAci ofnK8UG6cKeJ9l065TXSMSqV2PS9ltODHS9RKbNMsmb2XIzUDMU6jfjc9g183CE2n3mfA FXMKGOiL/IezmhwxK1cihHWwpV9THURfNuG9mUCrSVcIjXfWzPttJanw7l77Z2se9zij3 sW5AxKPoWBa2neWUvHVgJbx5PwB85re/xJo8T1x4za+YVfavDKI+UuDQVfKbYAKH0/w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793204716; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=Nr8ebwQFBYYb53uHRZdPV3FvCBtaiAM6QgdoRj8eGSw=; b=Ury+MRrtOn6035QDvhYnGnZ4MxbNzHOq09Ckixj8rC648C8WySn4uvXsjdzrnqVg+I7B IeMzWrqmeGBATwzkUi2HXC9Tn1UngQA6V6McuIjSnoEbEDaZViX7hlsptDCJxEJWJiPBn 1iv1+ebVIbscv9bMaTUc+GDSTv07jtAC6iIwN7UajXh481WlU135KMsAMOFk8AHWIDDCb 4va+ldPz64rgIVAlT2QjrmsQWu0cSXzl2leSGgqsGW9vD0RQCsI0PS8V/U357EltaWRbv GsL6Kj2poEZIsYevUCyh4FN8gu+wGJRq7YN4QrFviPuw9dTM+Hv9RO1R3jNUnR8XXNQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OWz30qJL; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 205C6606A322; Wed, 28 Oct 2026 16:25:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OWz30qJL X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793204715; b=KStQ32oS8NbUHuygLf7H55asa6wRbIzImX7aYx6wxjVZW5HJUl3HFNEVS8ZGNFY4AXmX 092ObP2LMehKqp0nVS9MOe5G1hquZ8v3YxDRv0iyYmddfEhvjDMvApShGAAvEoKoICGPu TDFNL7eCqY2K5gmNt1pXZ4YNn3RRhLF0d9NyeHo4fzTp9QGwrVAri0mrPye6wK6o40cx0 ZysOVsk8qWY/whUL+WblpzDr6qaWpthNZfa36MPTnDnEJcfmtM4dPHgoWGM6To8c7hDsd ncnbBOcomE0YwYazceB6ILPROJEPX+5Q5Lq7keNPAL05Ddr6rZiNge8C9NTVntA9uug== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793204715; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=Nr8ebwQFBYYb53uHRZdPV3FvCBtaiAM6QgdoRj8eGSw=; b=LBgklbkN+ugm46ziG4U60W5qF6tI+2CQQovZZtRL8FMFiEpxRi1+4aVbocD3UZpbvSi2 9z+c4tsA7nes8H9OPZ03A06UAFhFI9VH9axYJ2ZhWKDAlXS3Td1sVlLyss3LI/rllDwZ2 kQ2RWNiYyohe8rBR56EZz+HTmCsNzdpeKJrSTTb5bHvThTA/gNHOez5OsXCErU1isSsNE MTaj5QnWsaKfHt9SMFv3uiDtY2AtL/TnXI+Kag+6ud25Y33K9aXetERT0mitIyMELHuXi top4o6X24HYV1ZWJqmlQtIEn6MJtDYWQtsRoxx51fUi0mqyrWkh/zQV6ghOGaHtTT8g== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OWz30qJL; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F34E0606A31C for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 16:25:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 989CC1F01825; Wed, 28 Oct 2026 16:25:12 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793204714; bh=Nr8ebwQFBYYb53uHRZdPV3FvCBtaiAM6QgdoRj8eGSw=; h=From:To:Cc:Subject:Date; b=OWz30qJLxMltfO3VsL6upxuRHud8jatnTrHCKLPZIoKIJmP7QrRWufk0QhKb3Duuw Z0b9jbHr55JK/K2+8WcWLS7cSwJBRLbC7Cf45PD/r7gWx0xPEG1k+b/foxiNqjvSek h3O7L0zz05/nnZrTN0iOIWCGF64w2rBC5oKkqc8310qhXLxiaJHDSl9r0cgjb/ThcV Hw6Q//7enRWOekIHd0AgjHT8s2iIk+1ISvamT7iEyqIucWrS3tjBQbKkCnvjPV+sPe 8KCoTfjnR7vFJb9lwJzTF1WDdBuVPZYLZgG8mmigKJ0rLEUGhNnK4d2OoVNiZdzU+S mA5j1yyXCIKug== X-Cc: Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Kyle Zeng <kylebot@openai.com>, Eric Dumazet <edumazet@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list