🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21048

[PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition

#21048
From: Pablo Neira Ayuso
Date: Mon, 23 Nov 2026 13:57
81 lines
11127 bytes
From: Fernando Fernandez Mancera <fmancera@suse.de>

There is a race condition in the nf_conntrack_buckets sysctl handler.
The implementation uses a single global variable as a temporary buffer
to parse user input. Because sysctl handlers are not locked, a
concurrent read or write can overwrite this shared variable after a
writer has parsed its input but before the actual resize occurs.

While this sysctl is only writable from the initial network namespace,
the race can trigger if a monitoring daemon reads the sysctl while an
administrator or orchestrator is writing to it.

Fix this by removing the unnecessary global state by using a local-stack
table instead and delegating the locking/serialization to
nf_conntrack_hash_resize() function.

Fixes: 3183ab8997a4 ("netfilter: conntrack: allow increasing bucket size via sysctl too")
Reported-by: VEGA <vega@nebusec.ai>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_standalone.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index d88a10230862..9775efe4e2c9 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -533,27 +533,22 @@ EXPORT_SYMBOL_GPL(nf_conntrack_count);
 /* Sysctl support */
 
 #ifdef CONFIG_SYSCTL
-/* size the user *wants to set */
-static unsigned int nf_conntrack_htable_size_user __read_mostly;
-
 static int
 nf_conntrack_hash_sysctl(const struct ctl_table *table, int write,
 			 void *buffer, size_t *lenp, loff_t *ppos)
 {
+	unsigned int htable_size = READ_ONCE(nf_conntrack_htable_size);
+	struct ctl_table tmp = *table;
 	int ret;
 
-	/* module_param hashsize could have changed value */
-	nf_conntrack_htable_size_user = nf_conntrack_htable_size;
+	tmp.data = &htable_size;
 
-	ret = proc_dointvec(table, write, buffer, lenp, ppos);
+	ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
 	if (ret < 0 || !write)
 		return ret;
 
 	/* update ret, we might not be able to satisfy request */
-	ret = nf_conntrack_hash_resize(nf_conntrack_htable_size_user);
-
-	/* update it to the actual value used by conntrack */
-	nf_conntrack_htable_size_user = nf_conntrack_htable_size;
+	ret = nf_conntrack_hash_resize(htable_size);
 	return ret;
 }
 
@@ -657,7 +652,6 @@ static const struct ctl_table nf_ct_sysctl_table[] = {
 	},
 	[NF_SYSCTL_CT_BUCKETS] = {
 		.procname       = "nf_conntrack_buckets",
-		.data           = &nf_conntrack_htable_size_user,
 		.maxlen         = sizeof(unsigned int),
 		.mode           = 0644,
 		.proc_handler   = nf_conntrack_hash_sysctl,
@@ -1153,8 +1147,6 @@ static int __init nf_conntrack_standalone_init(void)
 		ret = -ENOMEM;
 		goto out_sysctl;
 	}
-
-	nf_conntrack_htable_size_user = nf_conntrack_htable_size;
 #endif
 
 	nf_conntrack_init_end();
-- 
2.47.3
Technical Details
Message-ID: <20261123135726.3940688-2-pablo@netfilter.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369441-linux-kernel-netdev=dewy.ru
References: <20261123135726.3940688-1-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369441-linux-kernel-netdev=dewy.ru
From: pablo@netfilter.org (Pablo Neira Ayuso)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition
Date: Mon, 23 Nov 2026 14:57:12 +0100
Organization: Usenet Network
Message-ID: <20261123135726.3940688-2-pablo@netfilter.org>
References: <20261123135726.3940688-1-pablo@netfilter.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3894636"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dTiWfFKehy/kIuEGPNfJViYZNOo= sha256:cnoaaFhcxSPs7l7tGydAq/ZoNtgL7TUuhcIj1vPA/m4=
	sha1:BzlWSCCuLZGIP8AaaHxf45XO7a8= sha256:m3QpIkuVRS2bu8uV0BKHaEo9e+SeCBcsvEHs+Xa5XeM=
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 5606D125DB6; Mon, 23 Nov 2026 16:58:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	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=netfilter.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 59mUzbzUwYyQ;
	Mon, 23 Nov 2026 16:58:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-369441-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=netfilter.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id B5941125DB8; Mon, 23 Nov 2026 16:58:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 151E433BBD; Mon, 23 Nov 2026 13:57:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1795442255;
	b=d0tnYPbql7DiVoBBF0B2gZ/9slr8SvY6PGJkX79P77V2qoMcpxHbOxlU7SWR/l0kDwJ5
	 vqfXvCvSqPn7plRSag47T7T2oJKH3gaywusmfBfkh7Myt+pYrAbtglbdDMQk+JNaA9dn2
	 sEXfLIByKer0bMXXYRIG0d4p7zESYLxoablFCxG4wkBSIMZeYwxQ+RZMBUpT5+T5UClK5
	 gGcEHrCuqi8RHCFWJpdaMN8tx2tNLl3qvbFKEFDzvOFFetVU7SDc51Juf+3fbp3a4zY2r
	 G2yR2h76c4yjjrykNt5LhGTVb/ouZsu0YQwXsaIvqBE3rM/KH+vsJroL8GDW9DNhq6g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795442255;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=7l6ujBlvopYz8h/a09FCsFReMdf0JytvichTI5tBd2g=;
	b=vk6p6gjiw81YcASNgrp8VhQ5cxMGuK72Sc1Saw6uEBge6sS5BLvKYREp6FbV9o1oIHqL
	 4zQg7Ust30HBckHhINpOswrIFbs+SWDTFitLTgO8c7CtCobtEDk6P+hO+9YgihiV0FE4E
	 4MTc5RaTfg51bbZED+ysrLcQXQ/GbXJvpc8ZIIPNWXZg4Fh1xYgRFxgjuqiA+hoPekSrM
	 ga3LqHv+LYSYscMPyzKUCkxWd1ES1kF4kuKJ8BUJ+Wvh/EWbeoFoafpoksZ17+Uh7qSaG
	 esnOUmlHnKUsxZGxHpboH2H2uEeyerZrkGACRGfF2mjQbWYevzAUC4eKgJhah3Hiq6w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=qha833XN;
	dmarc=none header.from=netfilter.org;
	spf=pass smtp.mailfrom=netfilter.org;
	arc=fail 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 804F5606A332;
	Mon, 23 Nov 2026 13:57:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=qha833XN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.190.124
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795442254;
	b=W34qeQuI/jrdj7Y5dL2qomlriqcyZl0c1J0Kgzup1M3WW8TCFjWjaYF2SkJnVpoQnrzR
	 eYkk6yX48XvWEealY+mOJzpifp3K7uceMW1yl6qYcJ9PBUaefzrHDRfTMBG9gXwRz9d5X
	 UxRWYoAsrQTCdex/vZ1mvKiTR4aEqPnRIrUYFi86+uM7BWIT/b4TTNv49XJz34cKtB4nM
	 ZPzZUrB4Ys+PWRB/iuNdJfvxftSsUJtWRhePhVUYx3SzP/K2hHi/rZMlI7Jz/DD3QPTf/
	 FXH1/x+AV6iep8TcMefje+RDnS3wo5ciDtGOaPBkCa/NM9vz1slyJ65fkHMZEOR5tqg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795442254;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-Spam-Status:X-Spam-Checker-Version;
	bh=7l6ujBlvopYz8h/a09FCsFReMdf0JytvichTI5tBd2g=;
	b=qBmnY8ronN2ILTis8rnWQor948pPm2AcwIlgbv5PI3j1EmCmk2Ou6LW9GkmAyDMQGSCH
	 jCPBFil4F/agoxoaXDFYmxpvafNdIxESNh7IeWCyOjcHHWE0X/LtVZG5GyCCTFwXoqDG7
	 O3vB4oLj+MJRj+OTGJrUVaWDt8YVwjFTEV/eB6jGmXxD0FN2NHjOgK8vWhBDgMx4rxKfB
	 HZJXyP2BGWhXcLA2zGm8hgayGTY3DNba8xMmgfVG5RrINoOsDn1wCsX3jAFCB86SUnJqb
	 VAPS2w4P+zW9DfUV1kSsC2xdCL9gmtwsrg4KVzb+pvSoTd7GpbH8G2muuMhL+/HGQQQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=netfilter.org;
	spf=pass smtp.mailfrom=netfilter.org;
	dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=qha833XN;
	arc=none smtp.remote-ip=217.70.190.124
X-Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124])
	(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 3B789606A33B;
	Mon, 23 Nov 2026 13:57:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B789606A33B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org;
	s=2025; t=1795442252;
	bh=7l6ujBlvopYz8h/a09FCsFReMdf0JytvichTI5tBd2g=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=qha833XNxJNZ3YSWZD0UkPLXJEw247TObNeQCekU4ZKw60iWO6ixXeRxbe8IqAjBj
	 5u/HRo94/mGo2ZHe/GXO3eXvBmG+VLLOqa84RKC4j+OHZh1FTzQvk6L5guKLcJnc6F
	 npnRbbQfUxwyAOh7qA2wipDqLw02PhgrQeYr2eKG3HuPloLhsbPMj77dZJW9YlS6XQ
	 c/Hr21jELXdW/LPouW2fQ5F4e3fbF2eul8iqRBDoBxYnaT6p9/6NF+1Lak+Kn4H/Vp
	 BWeL4+C+1CWu4u71FCpVKlnTvmdEO97dynsoEKPdBgO5ORsg5AjXL1T9w+XsH5zBW+
	 znhIspEc9Qskg==
X-Received: from localhost.localdomain (mail-agni [217.70.190.124])
	by mail.netfilter.org (Postfix) with ESMTPSA id CEAEA602EB;
	Mon, 23 Nov 2026 14:57:31 +0100 (CET)
X-Cc: davem@davemloft.net,
	netdev@vger.kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	edumazet@kernel.org,
	horms@kernel.org,
	fw@strlen.de,
	ja@ssi.bg
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261123135726.3940688-1-pablo@netfilter.org>
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