Article View: linux.kernel.netdev
Article #21032[PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition
From: Pablo Neira Ayuso
Date: Mon, 23 Nov 2026 13:54
Date: Mon, 23 Nov 2026 13:54
81 lines
11144 bytes
11144 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:
<20261123135442.3940372-2-pablo@netfilter.org>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-369424-linux-kernel-netdev=dewy.ruReferences:
<20261123135442.3940372-1-pablo@netfilter.org>Show 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-369424-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:54:28 +0100 Organization: Usenet Network Message-ID: <20261123135442.3940372-2-pablo@netfilter.org> References: <20261123135442.3940372-1-pablo@netfilter.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3893488"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:pXPFhnsjNIn6oVETROdqGsF6NTw= sha256:SVpqjdk19e0UbKKQu/taG5J9IFfqfOcsHspBJy3TmN8= sha1:ttQBnQAHlezLmnM4vnGYWSWh8ag= sha256:SP1OFcX/aKjA1YOI4xvUo1P1PZtkmSXVMg2itJgRmLA= 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 619EF125DB9; Mon, 23 Nov 2026 16:56:03 +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 8eB4jJNzZ-yF; Mon, 23 Nov 2026 16:56:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369424-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id CFC02125DB6; Mon, 23 Nov 2026 16:55:51 +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 45BD333EF6; Mon, 23 Nov 2026 13:54:59 +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=1795442098; b=nCkQNyLnoyhUH/E+Z2ytBhZznmwjQVzQaD9CWJt8iBfOG4xhsdjgPGDweXpE90aVaQrA dHXDtxtQhws+n74mLIPrcuLusR+l+EFpf3rV6APolbYbGS7aRQNVKU8KlifMaz0yV4hWx pLmcyrqMk81Y4JvWdTB4ihV/bcOcKZ/S8JPXtkElYDIObXb67L/RDNRu5PuHrnVyZDmZD gn2ut8rbVs7h5ah+L4DYHpcoO43TUbpDnz1HA69UeCMnk+8K+xwNVhpHaVyTWPh0NlkIT 0EafRQv6AnZdcTqJrJ7Kww+Ule9Vo+M+mCx8q/KXaMZg95LktsRcg6CZcKTL05uuKYQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795442098; 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=shcd2gXqo5R4dHnlCbeb6NK9OGjzaMyYcM6Dn0UCMeZ6DtwySUcMW2ZhSPcq8nPV8F5f AaZ3h6Fq48+YapxrGZZwNX5yiORXxmZrpmWtlZzhiVR37+2HgDdl9ivqxdZRxIOaEik08 aO7LjXlfFq3cUZpF1HgNr18n/zq4kzE+89ujcEBhVfOEFE2EOKiho6RmrgvC5gCt4F63j nunlxlDcxFAK3U1O5sXxAjLTzUhWAA6+oJrlvzJfAyQlZgCbw5Sj9uLxiOZBrUN4fxQW7 crfWWlKbrx7RRmUAQU6n6U+qRQhRaM9CZgjS9Lc/hC6xkbcutAnDW5ee25DVXEmrKIA== 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=Cxa8ViT5; 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 A0029606A682; Mon, 23 Nov 2026 13:54:58 +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=Cxa8ViT5 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=1795442097; b=ALU1W5zuhYemX8EnFlgWGdDn50WQw2st5NCYHxRWZutRzmRyMfYxTr59hy+0FffOZ3To mOwdmhkQL0nh8HZPyjmkwLMcwDnHk0SY9t7ZjGcmnC3y60JYsAcLTAC9cLIJZZnSYg7YX jZBJQ4HqSS9yNO1UjJQLCa9oPurCVF9ZoXjFbbadWkflBNQzd8Y/DXyWXUebfLlLmMMz4 Ng/BaU4QOQ2corm9m3IkFo0GlMHtLsMl6P3eRK4UEM+GDlvkDegbbZEHvTOnnPkJhu+jD DBvt5WO+nkcIUTC8aw59e0chYsAF14MLK2r0HRJQ/LRvs7JxfB7Ilb4cHsuxQEX+vww== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795442097; 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=LeB2PFydwjoaUU8UcX5SLGzPighZSaVDNf4Y9A8cSvd70PFDTRhCK1YVUv3aIHOetRr5 ybP4l0KAarEjzeiHEmAguPoPoXds4KYu5gSlFopMkIduXJQISXVhi/I0U+GB6WoQWgSjR y/2Wv7iCBxNRWuyGevGhsGT5tPzsSr1UbhxfBA4x1qI4ypCG02mBGNRORA6zkGqHiBvbM E2qHsUCMvigi7xAbnsbWV86lr8sSNe6qJ3850mQLf01uFnR9RXjo788qBgm/odn0tNEd7 ZH2LoK9ZlBdkEZraskcUvZGplBosyqtKJLkSqbd2NfiFsoROX2jPAoe1AtajOc929bQ== 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=Cxa8ViT5; 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 5577A606A32C; Mon, 23 Nov 2026 13:54:57 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5577A606A32C 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=1795442089; bh=7l6ujBlvopYz8h/a09FCsFReMdf0JytvichTI5tBd2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cxa8ViT5O9yCaOTgvmCxfyWpTNyX/y3v0h4qqQpyWlzIzAROiPIDBd9wlSbEiLen1 8CdrDeZK9WdS4n9PNWiv4ptcvZcs5ROZBBtych2fwaNEcCRm2xoeyacTwVVMmdXhQy OQhbP/W3+hkcJM7fOLhM4WBzk58JKzsKaVsrkXG/GLmKjxBOi84ibINOJiYd7Z6oli ortHu901hIfGra6ShbYyHloPre4ZeoAp1b6kPzqxPlFbn/yFr4eSzzJ0gxmWzpPAx2 y/Oe+L0I+4OmjaUGEg71d4FrskpxbEMSqzS1CZ3m7ZeNVlJqeUb2FvF9pb0/5aW81U noXoKkH97TWIQ== X-Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id 97D3D602BA; Mon, 23 Nov 2026 14:54:48 +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: <20261123135442.3940372-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