Article View: linux.kernel.netdev
Article #25949[PATCH net v2] tcp: avoid table_perturb overflow on single node hosts
From: Amir Hosseini via B4 Relay
Date: Wed, 02 Dec 2026 19:35
Date: Wed, 02 Dec 2026 19:35
86 lines
14134 bytes
14134 bytes
From: Amir Hosseini <me@amir.fyi>
Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to
allocate table_perturb"), table_perturb comes from
alloc_large_system_hash(). On 64-bit hosts with more than one node with
memory, hashdist is set and the table comes from vmalloc_huge().
Everywhere else it needs one contiguous 256KB block.
When that block isn't there, for example after many HugeTLB pages were
reserved at boot, alloc_large_system_hash() retries with smaller sizes
and ignores low_limit. The caller is never told. __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, using fail_page_alloc
to fail just this allocation. The table was halved to 32768 entries and
the kernel crashed on the first connect().
Switch to kvmalloc_array(). If a contiguous block is free, the table
comes from the linear map. If not, kvmalloc_array() falls back to
vmalloc(). Either way the table keeps its full size.
kvmalloc_array() was also proposed in 2022, but
alloc_large_system_hash() was picked because it spread the table across
NUMA nodes. That changed with commit a06157804399 ("mm/vmalloc: request
large order pages from buddy allocator"). Now vmalloc() takes the whole
table as one block from one node when it can, and only spreads the
pages when there is no such block. That is the same case where
kvmalloc_array() falls back to vmalloc(), so NUMA hosts lose nothing.
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/
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Amir Hosseini <me@amir.fyi>
---
I also tried a 2 node guest. When I forced vmalloc() to use smaller
blocks, the table was split evenly across both nodes.
The low_limit loop itself is fixed in a separate mm patch [1]. The 2022
discussion where alloc_large_system_hash() was picked is in [2].
[1] https://lore.kernel.org/all/20261202-mm-hash-low-limit-v2-1-44a8d2426acd@amir.fyi/
[2] https://lore.kernel.org/all/CANn89iKeOfDNmy0zPWHctuUQMb4UTiGxza9j3QVMsjuXFmeuhQ@mail.gmail.com/
---
Changes in v2:
- Drop the NUMA branch, use kvmalloc_array() everywhere (Mike)
- Explain why NUMA hosts keep the same spreading
- Say that alloc_large_system_hash() ignores low_limit, and fix the
hashdist wording (Mike)
- Link to v1: https://patch.msgid.link/20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@amir.fyi
---
net/ipv4/inet_hashtables.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 860145d810ed..59507d78b42f 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -1310,12 +1310,10 @@ 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);
+ 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: b6c8f45ed340f00bf2004d407cf7316fe3e24c48
change-id: 20261201-tcp-perturb-kvmalloc-2e3de54b992b
Best regards,
--
Amir Hosseini <me@amir.fyi>
Technical Details
Message-ID:
<20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376029-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376029-linux-kernel-netdev=dewy.ru From: devnull+me.amir.fyi@kernel.org (Amir Hosseini via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2] tcp: avoid table_perturb overflow on single node hosts Date: Wed, 02 Dec 2026 19:35:03 +0000 Organization: Usenet Network Message-ID: <20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2042863"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Hf+eHSNDqntSQg7TgsJsQCOSzcA= sha256:BTgNpSD5WKy1pibsOPngSLNnnGbJS59JQ5UkxyJAbBY= sha1:W98wJc8B8AKorHglNkPUefiQAUg= sha256:RnllL6D2VQk4moSA7RV7rRhKM7slfuofKpOKEMrVv8g= 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 31CC111770C; Wed, 2 Dec 2026 22:35:20 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 M7fxQZzY8eXz; Wed, 2 Dec 2026 22:35:16 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376029-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 5A337117709; Wed, 2 Dec 2026 22:35:08 +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 7467229616; Wed, 2 Dec 2026 19:35:06 +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=1796240105; b=k3L6ovXwW8NPGNEf8xuEfnvB2psf1hKuyXjReRbmgOfIgyPxym8FtodXYHiy5WxFY9Sc psrCfsZB6A8pD7lvHZjown916gybEvI4VUvv1AjbC9wR5DSWUvsor+VBN6gDeodx++NxS wqV4TLcSmufbkQYOloPRkPb4duQFHHQmzMJoRkQnDQB05QTVwgGO3ccFqU3SMiyqR1LBb XASyVQbZ4zaOEDsLWcyat2oD9PCTZBKbKu+A4SDhe3I13VkNoNde9nvjYWLtWjchanLEk dFERT6b8CXo1pRwALD22OatQJAcZqZGBF2o2HljAvbwTHyZ6/T4vkyTY/HVUz4/Oz8g== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796240105; 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=1ExXS1UxhIPH0wCjHRjFtaUwEdgpBT7awKaBmmDXSe0=; b=XygEiX9udk6K2KzKsqvBvfVug+SgAj2Qg1Vt0dTi2Jat/WvRQYiT9Thq1Y6lh3hypvfo UJb40EuvVhyehIhDKL3j9NTVUmiEVDR0WTbE1hCtZr8EQF67w6mQ8lI7r+AP7LuB8lEXs Ietek7mtPNM7qqsHWkoIwha3KDlcLCg9lf4tgM6mCS8Udwj6igZWWGddygPIFtKQIFz9I MzquRu7w4FH+t8AeQDWRMKXVtW+mdJn3MRI5HsAvagcYkAewZyr9upvc9+L1/6O74FhvF R2xt9NUcMMGUDsNa+xnzxwj30ac/xGTP/MLJu3ds0BCM2YG0uZbSPZ9p7+1Og1LruXw== 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=i2aGWiHf; 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 9F2EC606A333; Wed, 2 Dec 2026 19:35:05 +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=i2aGWiHf 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=1796240104; b=MP8rm8IQdgXMB8v5fTHewCSLrq4skTgKs54mU6SfIqRt96T4U9yOqms/d4E/6WnAOTy7 uW4o7FpmTcX3d7knV6qzKcjEvxuo35zn/rtMk7cnNSP3r/g1TbQYrIGjqLuKq7W17Ydno e9oJr0E56AEhrMs80OFnNhUzRKFHcSXEBCxy0cjGhA0LN0Qd5crSTMMKVUdIMGgyQEJtd kQZN4FuE05YiVJKPYJjJG/88r2/S3AHgKoBvATFSOQekIW8zi58slAbDoFXnNw9eTViZv zD+pv0j3B3ju0y4SVFfm9gBDknc9W2uZV91zl0Kq0iCuDiMAST0gXis8gVkA/wm2S0g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796240104; 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=1ExXS1UxhIPH0wCjHRjFtaUwEdgpBT7awKaBmmDXSe0=; b=hAGgzuZF38rcH2mfE62QPvgWVgn+M7ofX0Jxf0HTYjhx2vlKfqPEQvptkaNJDsa6SwY9 gfmwz/7dgNNfgKddR8iq09DteLqMm03+SVT49FQh3voCMrqRekgGEMxtsjttRE87Z96DR 5zmLJUdNyF8cv2lerOL8jq20bJjAuIawtxZBLfFKydE7ult0tqU9x/UmdnH6wa0xpoO6L lJbZqQG1S9zFiL6l92L8Li+HGzw9um2sc4/97MSjk/kcAKgt+FIpUSCKUswhhsHlqUuFF y6AvUuDHNlflu1VIRdZHALK7a9dSpx1Q+6m5jNwINY7LCBmUZMrGQGw3vnxrwh1S0oA== 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=i2aGWiHf; 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 B6FA4606A322 for <netdev@vger.kernel.org>; Wed, 2 Dec 2026 19:35:04 +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=1796240104; b=tD6XutyM2Ui+rXgJJy7T/kNFDiU3IiDrMRWCwyZC+tQ8ImeuF7wvbmYQi2ovtP8A6kRv MlbqVC1YLh+IfFGvOXJo2pLPRRENck+go+fub94x5RbvG+ROlkC/ef5LXgn8kKrI3gtd/ 6zDZ1mqQzZykOFTqIYbUSUoGsWoVLsKysBq4CLC/9yn5Lxi3cziFB53dY0JFtWVvPtjLt kLdabxoVWimnRrwIz285LHtRjjIT9IXH+BnpBaLNCacAaKzS+lBqPB8Amhnkpt+FAHPA2 GSLTHIo3kuaERbVHv3XzOMQ1o2SlyuhjI/87NBH0QwZ3YmIM4o+3xAU7syXqXvStumA== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796240104; 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=1ExXS1UxhIPH0wCjHRjFtaUwEdgpBT7awKaBmmDXSe0=; b=dkh2skR2QqObHo+qkZW5FR3Ltwg4wjPiJMUF+wdRBaHweLC87uq9onK4/AEEZjRU+6gd onp7+y2BC7YwNhtJeeTvk9ci+xzrmjq6VNRR79ar34sCW4/Lz80zdjkZfbfpazWgqQxCE 7A6GRf/iPcTevXe6F8YrIyPkejiqo1avcggVeKq0Ph+F6zS5ngKhYyUiLjTfA9Qeq4APc mF6khVZ7aIq2lSuRk5ZfV8MAVURXFWqYP2gJA9IUKu5DK97G2szjHEdcfksbHNxtHxjKS M+zIiJ4HBwvDiOQDdUSHbrRQ5N+VEPMz20b9GYMJr4Uo1OGvi/D+igC+GD/1oRCfTNg== 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 98C701F00893; Wed, 2 Dec 2026 19:35:03 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796240104; bh=1ExXS1UxhIPH0wCjHRjFtaUwEdgpBT7awKaBmmDXSe0=; h=From:Date:Subject:To:Cc:Reply-To; b=i2aGWiHfkX+B2LrpaqxoFm2QWxtSIs2cpZagK7Y8LUX9dSg+LJDwrYF2H4BrdDJ/i DLHHWc+f2yqOtz/fgQC8d76oiP7gXBwMeDP3nvseTk/+qOgcxU49SlWPNFSSGBiqxN k8+f+atlrA8inDieW2BcpYr5LpP/5nrh2KAzgwQZQMlfWRF3R3mYQM6fn7W3XtDV4D EmrSssU3C3WUrTJHsSqO7xs+ZqwGujpbo5b+NZwW0o6hyWcxrsrhed7alpiSbnFjMa my3mdQqVLPhwRE6KwACS8ldI+QijZL7VuCXklO28+VgVJz4QApYGrFKiQckMkihax6 5FxEX0AsqnAYA== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id E76D34F5FE; Wed, 2 Dec 2026 19:35:02 +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/32NzQ6CMBCEX4Xs2RpaQIIn3sNwaMsiq/xlWxoJ4 d0FvHucyTffrOCQCR3coxUYAzkahz2oSwS21cMTBdV7BhWrm1SxFN5OYkL2MxvxDr3uutEKhUm NWWqKQhnYpxNjQ59T+4ABPVS/0s3mhdYfwgNryfmRl/M8yBP+/xOkkKJGxNzmadbopNQ98bVZC Kpt275iSodwzgAAAA== 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=1796240102; l=3685; i=me@amir.fyi; s=archbox; h=from:subject:message-id; bh=GKbDYa4hZsbcCtmXQRRjMD47MzoBLPoozfRqzXsCNHU=; b=XQAGh0uO4RQeC8eH5d/r+OJvRxMvNR5xu1ky9zRVKI/M4CnJs70Y6/XC+zeJJrPoEb7hrY7QG VCElL+nuosjDgcex7k0S8tJjh1TBkKHP0TMQ4CdnxB1Df7EO3p55GTT 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