Article View: linux.kernel.netdev
Article #25445[PATCH net] tcp: avoid table_perturb overflow on single node hosts
From: Amir Hosseini via B4 Relay
Date: Tue, 01 Dec 2026 19:31
Date: Tue, 01 Dec 2026 19:31
82 lines
13588 bytes
13588 bytes
From: Amir Hosseini <me@amir.fyi>
Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to
allocate table_perturb"), table_perturb is allocated with
alloc_large_system_hash(). On NUMA hosts it uses vmalloc(), but on
single node hosts it needs one contiguous 256KB block.
When there is no such block, for example after many HugeTLB pages were
reserved at boot, the table is made smaller without telling the caller.
__inet_hash_connect() still uses all INET_TABLE_PERTURB_SIZE entries,
so the first connect() writes past the end of the table.
I hit this on a single node QEMU guest with KASAN and
fail_page_alloc=1,100,1578,1. The table got half its size and the
kernel crashed in __inet_lookup_established().
Allocate the table the same way inet_ehash_locks_alloc() does. Use
vmalloc() on NUMA hosts as before, and kvmalloc() on other hosts. If
there is no contiguous block, kvmalloc() falls back to vmalloc().
The reproducer and testing were done with the help of Claude Code.
Fixes: e67b72b90b7e ("tcp: use alloc_large_system_hash() to allocate table_perturb")
Cc: stable@vger.kernel.org
Suggested-by: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/all/aw7fxwCeHX5jFYW1@kernel.org/
Signed-off-by: Amir Hosseini <me@amir.fyi>
---
Mike suggested kvmalloc_array() in the mm thread [1]. In 2022 Eric
preferred to spread this table over NUMA nodes [2], so this patch keeps
vmalloc() on NUMA hosts.
Since commit a06157804399 ("mm/vmalloc: request large order pages from
buddy allocator"), vmalloc() takes this table as one large page. So in
my 2 node test it stays on one node anyway, like the other boot time
hash tables.
[1] https://lore.kernel.org/all/20261123-mm-hash-low-limit-v1-1-8a803aa8ac70@amir.fyi/
[2] https://lore.kernel.org/all/CANn89iKeOfDNmy0zPWHctuUQMb4UTiGxza9j3QVMsjuXFmeuhQ@mail.gmail.com/
---
net/ipv4/inet_hashtables.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 860145d810ed..e6a531e1b2cf 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -1310,12 +1310,19 @@ void __init inet_hashinfo2_init(struct inet_hashinfo *h, const char *name,
}
/* this one is used for source ports of outgoing connections */
- table_perturb = alloc_large_system_hash("Table-perturb",
- sizeof(*table_perturb),
- INET_TABLE_PERTURB_SIZE,
- 0, 0, NULL, NULL,
- INET_TABLE_PERTURB_SIZE,
- INET_TABLE_PERTURB_SIZE);
+ if (num_online_nodes() > 1) {
+ /* Use vmalloc() to allow NUMA policy to spread pages
+ * on all available nodes if desired.
+ */
+ table_perturb = vmalloc_array(INET_TABLE_PERTURB_SIZE,
+ sizeof(*table_perturb));
+ }
+ if (!table_perturb)
+ table_perturb = kvmalloc_array(INET_TABLE_PERTURB_SIZE,
+ sizeof(*table_perturb),
+ GFP_KERNEL);
+ if (!table_perturb)
+ panic("TCP: failed to alloc table_perturb");
}
int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo)
---
base-commit: c712df600d056cc35ef7621e43c8e12513bae886
change-id: 20261201-tcp-perturb-kvmalloc-2e3de54b992b
Best regards,
--
Amir Hosseini <me@amir.fyi>
Technical Details
Message-ID:
<20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@amir.fyi>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375330-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375330-linux-kernel-netdev=dewy.ru From: devnull+me.amir.fyi@kernel.org (Amir Hosseini via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net] tcp: avoid table_perturb overflow on single node hosts Date: Tue, 01 Dec 2026 19:31:32 +0000 Organization: Usenet Network Message-ID: <20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@amir.fyi> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1803201"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:zh4pU+zMVdU1G/ZHZLBkw5HEkyA= sha256:Nvwu9Wp4cUT67UCfKLbd1iDQC9FA8vTkiXAvbm3QWFc= sha1:BJ5ixYrLD4fCt8R2ygiYXLxp9VI= sha256:KjPjTGYt+XXPn05lPHq6XIVWko24G6U0YzJYPn64EoA= 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 30076117481; Tue, 1 Dec 2026 22:32:05 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 M6DXs-b7HUp9; Tue, 1 Dec 2026 22:32:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375330-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 9A0BA11746B; Tue, 1 Dec 2026 22:31:52 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 52A30602AFB; Tue, 1 Dec 2026 19:31:52 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796153511; b=vOShd1xtLJkGpuF9ogxTZHdz3feiWOlN6huNmhBjgqivJzy8ov1VZ1rLquc9vNWbwNBS P2n7xDnfBtPlYRdlTDLhIdAPOfwAu+q2+UrFvn79e/aLC7LibkTRaFr1Se4v/xHxu3UT0 JPoaFRorht1VfabOpNgEhFTi4FheJ295e1euKFxFXBpU04f6j1MkYSLis+jfQ0WLO6tLV GP5nW5Xdm2GvXCqR4By2NIguCmzsBrp2SEa61SoMMnX7558Sd2gGMYrRFYWUyuRHDYq+Z 01etbr1vYYXaNM+3ZADHdGjGWCqEJnHnZwaElqBFcbtcmqr3qS/ULQuCoMEjAggegAg== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796153511; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=/K7jQwN2DjsDfsnek6lfqm2UM1GeekeqSGZlUvxpx/A=; b=Nd9eB86GhZDaRSg94erK0ENmoNlY9Cms53v1sJmJbtvNsuuagKnZPzWsY76XR0QkSzAi CMcJIXATixT4MU+61N1cE1m3iKfl+bKrMI7Oxyn3kQfIN93JtgxnmjM1UaqgN3FgOuj/j njNI2n2HuK+dhsALGsscYrPKuI3pPSTeUAyq/QD38Ez2uiZ57IlA5nzZpdd1W7MXCDAtK XhwyLJ/ddqttsjx5a8qMggqH8TU/76dleEql0+mNcL0u4qBqEs3LwJtCVcDvkgAe9tUSN rvm51M+e0Mtf65k1txbrpr0+3aKJ08V/GLbndQkivNrpeK4ElULx6dgtc8ucG1+nFHw== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lzhYyonW; 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 A0097606A32A; Tue, 1 Dec 2026 19:31:51 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lzhYyonW X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796153510; b=x+5/kxj+fw+wMb6SmY/zT0R+Zga8gE8G2pWkqf19YkDfHFeAuJBQqrNwOzSi6lEvIeMU GtXMmwGrb4PZAYt0G3VtSdSPV0FZ0tFnmscoZRDlL9wxFA4SmWi2LsHUMStxMHh/gWViN 44TUq6yyH3zADFdpZGOYav0RYvajGkkBR5osaK4i1d8X2vch2HJz/YiQ5hnytuciP4b0z rKluyKdNsyI9aGyTzyxApnqvoPNJj6/7mXQPhf+9oFPMsqag7gJj8XE8yVotq87va5/ye YzG92TJHt7rWRAaT9iw/p0EWTWUWrXDEbYehV23OAPUn7KKZ5DGuPBDV+PuVOcRzdYg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796153510; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=/K7jQwN2DjsDfsnek6lfqm2UM1GeekeqSGZlUvxpx/A=; b=jrhowiuMc+57PDigcKLUT4LvfvcQIrDVuKK2SmNF/v0BEpEeUEKfazGFakCHF6P1euKT 8eUxUyWzM9qyZ5KN9797BI8iYG6/OYDjuUD8lREC52fgn+Bj56lLWOXkCuhIv7pQz8TDd ggwmLpiLh0Ymol2UUovohes1GWOSJYYZI2qV/JbY/79VK7j/FnXqrTuPgyGKzSe9g7Oh9 REOsLpBCelal/SudeTjilqGI9zdHymhfXK3ukivePXfnq2qtxcPHkkghtRTSkqQUfqTtf heT9JNujW9AQjAZXlurixSf1IdfN+sEdpJIGwZzPOaMJ9k3wLsK5qIZ4Q5b1yz4HhPQ== 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=lzhYyonW; arc=pass header.oldest-pass=0 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 BAAC3606A31A for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 19:31:50 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796153510; b=2+q5MdlXRG+9JsTNBB42ahAeycb36v8xU1DkXK32EHSTQka3Wq2ygVWITXJZtK++D8x6 50+uzK++M7N/iHXFKBctDJbACYJkBLp52rVr1ztWccJfLVMJu4lpeuWQd4Oom12sao9Qg a/5PLgdPyCDk2zNQMXVLtgKWm0OCoSla3mtuK7rQOK72T8C72ZDfeSiBXHXfuMn+GbrBz RWJGtkbJHDDQiXe0GlFTPfz/wivtzmS5smnPIcIP4ZpY7Tc+ouItI6O7r48iejZc69FQ4 LDAIbbYtJ8K63DHN6XMAMoI95DpYoN0On13Ana2K4rFqBbvPUXyOt7U8Eovyznb6KiQ== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796153510; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=/K7jQwN2DjsDfsnek6lfqm2UM1GeekeqSGZlUvxpx/A=; b=kO3OfjiN0WrmJTsRksoBYzjvKSnmJU3TIftzIlrwatpFqmGE8X5LTQi9Apn+Kexibe1P I9TZi6mtTQlo8RD6hsFhJ0+a4DGIX/haO6S7vOpRFnDnujrC3boEX5llVjcK3JZP5GWRs pwzMD2gpy6XN37nZ2Jb1FlQlvxRQMjhYzpAiWpYQ2VkqI0AAKZpwvRHBcofb1+jUUBnIP 5cMP+SA5JSxuATag8BZLF3068p85p7wW0MmbNLqO2qYCDOh4QJVCkGQ9mjgZHM51/lOYE xE4PYG2m8LF0CUC98JaBpufJKt5RT7HmRxGwbEiNQw7Dd/1WNhsfxi0DdghAZBKzxVA== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 9B6AD1F00893; Tue, 1 Dec 2026 19:31:49 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796153510; bh=/K7jQwN2DjsDfsnek6lfqm2UM1GeekeqSGZlUvxpx/A=; h=From:Date:Subject:To:Cc:Reply-To; b=lzhYyonWFxOCKj27D+eY2dry0lE3kdHQDoO5VLsdmfHNXnJOi4jF9gav3w7fNpWUF 7BFAQfU6pNNOtUTpq+Yo3rYticNbk5uHMUNjOkC+mgY61CuKIBI2ScNRBa2oU+A1S1 SpodZGqdU8HGRTiCNj+mZSXwppWpI7jz4mx2Fup3nUD42siYsCmX0r9J1vDht0KhlZ PUsu0zR1ZbgSji4F+vzf+RweaQZ/uCciZnGoN1oChxweWfepJA+buhWHCWywXkLTzj 9+tPNCx0ky54jyl4YhO/W2ifEy4Prk3karHm7z+Jd9HZL5JLHiLtfb9MsfEnWzJwd0 JorsuFY1mV4pg== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 00D294EFBE; Tue, 1 Dec 2026 19:31:48 +0000 (UTC) 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 X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWMwQ6CMBAFf4Xs2SZ0URP8FeOBloeuYmm2hZgQ/ p2qx5lkZqUEFSS6VCspFkkyhQL2UJF/dOEOI31h4prPlmtrso8mQvOszryWdzeOkzeMpsfp6Nq WHZU0Kgb5/LZXCsh0+8s0uyd8/g5p23aPjf2VfQAAAA== X-Change-ID: 20261201-tcp-perturb-kvmalloc-2e3de54b992b X-Cc: Mike Rapoport <rppt@kernel.org>, netdev@vger.kernel.org, linux-mm@kvack.org, Amir Hosseini <me@amir.fyi> X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796153508; l=3223; i=me@amir.fyi; s=archbox; h=from:subject:message-id; bh=Ai3HPZihEw+5Hz9flZcmgpEEsuAzaMDkx4DOoIO1QLg=; b=s3dhcGGtlkpw6JjlHaQas76jqCioUncm9Pi9ucGyfkkq9zBFvf7ZVYsGtKna1fpVZnZeMxyLA kQHzQf/1Ph3B/J65ekbusCaZjnbnRJxfbp2BCXSfIdrTGMA/rSwSVe5 X-Developer-Key: i=me@amir.fyi; a=ed25519; pk=YmuzvXl0k+J8pTqIG0kjwtCeJ1ggyIgBHm2jFmzNbeU= X-Endpoint-Received: by B4 Relay for me@amir.fyi/archbox with auth_id=1620 X-Original-From: Amir Hosseini <me@amir.fyi> X-Reply-To: me@amir.fyi