Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] tcp: avoid table_perturb overflow on single node hosts
@ 2026-12-01 19:31 Amir Hosseini via B4 Relay
  2026-12-02  9:51 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: Amir Hosseini via B4 Relay @ 2026-12-01 19:31 UTC (permalink / raw)
  To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Muchun Song
  Cc: Mike Rapoport, netdev, linux-mm, Amir Hosseini

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>




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  9:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:31 [PATCH net] tcp: avoid table_perturb overflow on single node hosts Amir Hosseini via B4 Relay
2026-12-02  9:51 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox