🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24801

[PATCH net 01/10] netfilter: conntrack: prevent helper extension relocation

#24801
From: Pablo Neira Ayuso
Date: Mon, 30 Nov 2026 21:51
101 lines
11934 bytes
From: Jaeyeong Lee <iostreampy@proton.me>

nf_ct_ext_add() may relocate an unconfirmed conntrack's extension blob
when the current allocation is too small. struct nf_conn_help embeds the
hlist head for the master's expectations. The first expectation's
lnode.pprev therefore points into that extension blob.

An nftables CT expectation object can link an expectation before a later
NAT expression adds extensions to the same unconfirmed conntrack. If an
addition relocates the blob, the copied hlist head still points to the
expectation, but the expectation's pprev continues to point into the
freed old blob. Removing the expectation later executes hlist_del_rcu()
and writes through this stale pointer.

Reserve enough storage for every extension whenever the helper extension
is added. Account for the alignment padding that may be required between
extensions so the reservation is independent of their addition order.
No expectation can be linked before its master has a helper extension,
so subsequent additions fit in the existing allocation and cannot
invalidate expectation list pointers. Conntracks without helpers are
unaffected.

Fixes: 857b46027d6f ("netfilter: nft_ct: add ct expectations support")
Cc: stable@vger.kernel.org
Signed-off-by: Jaeyeong Lee <iostreampy@proton.me>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_extend.c | 31 +++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/net/netfilter/nf_conntrack_extend.c b/net/netfilter/nf_conntrack_extend.c
index 0da105e1ded9..e5e04e0ec40a 100644
--- a/net/netfilter/nf_conntrack_extend.c
+++ b/net/netfilter/nf_conntrack_extend.c
@@ -54,35 +54,38 @@ static const u8 nf_ct_ext_type_len[NF_CT_EXT_NUM] = {
 #endif
 };
 
+#define NF_CT_EXT_TYPE_SIZE(type) \
+	ALIGN(sizeof(type), __alignof__(struct nf_ct_ext))
+
 static __always_inline unsigned int total_extension_size(void)
 {
 	/* remember to add new extensions below */
 	BUILD_BUG_ON(NF_CT_EXT_NUM > 10);
 
 	return sizeof(struct nf_ct_ext) +
-	       sizeof(struct nf_conn_help)
+	       NF_CT_EXT_TYPE_SIZE(struct nf_conn_help)
 #if IS_ENABLED(CONFIG_NF_NAT)
-		+ sizeof(struct nf_conn_nat)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_nat)
 #endif
-		+ sizeof(struct nf_conn_seqadj)
-		+ sizeof(struct nf_conn_acct)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_seqadj)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_acct)
 #ifdef CONFIG_NF_CONNTRACK_EVENTS
-		+ sizeof(struct nf_conntrack_ecache)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conntrack_ecache)
 #endif
 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
-		+ sizeof(struct nf_conn_tstamp)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_tstamp)
 #endif
 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
-		+ sizeof(struct nf_conn_timeout)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_timeout)
 #endif
 #ifdef CONFIG_NF_CONNTRACK_LABELS
-		+ sizeof(struct nf_conn_labels)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_labels)
 #endif
 #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
-		+ sizeof(struct nf_conn_synproxy)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_synproxy)
 #endif
 #if IS_ENABLED(CONFIG_NET_ACT_CT)
-		+ sizeof(struct nf_conn_act_ct_ext)
+		+ NF_CT_EXT_TYPE_SIZE(struct nf_conn_act_ct_ext)
 #endif
 	;
 }
@@ -112,6 +115,14 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
 	newlen = newoff + nf_ct_ext_type_len[id];
 
 	alloc = max(newlen, NF_CT_EXT_PREALLOC);
+	/*
+	 * nf_conn_help contains the expectation list head.  Once an
+	 * expectation is linked, its lnode.pprev points into this allocation,
+	 * so later extension additions must not be allowed to relocate it.
+	 */
+	if (id == NF_CT_EXT_HELPER)
+		alloc = max(alloc, total_extension_size());
+
 	new = krealloc(ct->ext, alloc, gfp);
 	if (!new)
 		return NULL;
-- 
2.47.3
Technical Details
Message-ID: <20261130215141.1009148-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-374477-linux-kernel-netdev=dewy.ru
References: <20261130215141.1009148-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-374477-linux-kernel-netdev=dewy.ru
From: pablo@netfilter.org (Pablo Neira Ayuso)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 01/10] netfilter: conntrack: prevent helper extension relocation
Date: Mon, 30 Nov 2026 22:51:32 +0100
Organization: Usenet Network
Message-ID: <20261130215141.1009148-2-pablo@netfilter.org>
References: <20261130215141.1009148-1-pablo@netfilter.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1547300"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qDmLvfEcOOOQ58RdDZUbSEWyjxs= sha256:AYBFa3BCN61unvBWRk2TYzRQd8Xbu0urMScaXFgXpr0=
	sha1:fgCxZCz++8gugjer7PZa2bpsxBY= sha256:T+nhaCEAcy1zkMeURa5V4IWQJmowXJM9wp6AfPtNpCY=
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 C8DAF126015; Tue,  1 Dec 2026 00:52:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31
	tests=[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]
	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 3bdo_xDWIPCZ;
	Tue,  1 Dec 2026 00:52:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374477-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 BD76A12600E; Tue,  1 Dec 2026 00:51:59 +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 73A5D289B7; Mon, 30 Nov 2026 21:51:54 +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=1796075511;
	b=WAtixysC4cjDE5RD2SI80Jjtx0iKkKK6xPlFdaoC3swMgCnhXsPGYl+96hR+QwQK3E7q
	 lyHeNcTBax1Ie+rhAOa/ALk/4YZmeae+IuuKzh+YlxxdAV0jaqJSi8gAPyQZ4Wjxeu5Jc
	 3f6K3QnGg2amIPc5uwzihYidrIuDUgevYf7emcJAvwu4JgxpXJIovdMqm+lBkMk/RpWdT
	 yjA4WgUwFu1Nu59Lfx527k7CbKCbRyGghE18hSP4El7hvQtYwU6FMCTGrzvHZqJ6TbmMM
	 QQBabzkvvki6pagaqLgiLua4ZzaoNWlI0CzJBcONENzSVpj0z2bdiygI9BXtRBSVqjQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796075511;
	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=LM2AcrnUy14scTk7llhQZMHvzDMRSdn4op+LrUBfz2Q=;
	b=BLFA2Wx3ZFunLsqQg300iyTdcFyEBKQ4si0ChryXJnD0Y9zYU4kN1IzTr4uQ4imKOA7U
	 vjJ1D+DvVYYmNASOyivForgChgbLspbYTMR8ZsKS3gQTAnht9TiAZbxAAxbGcA97kN4IS
	 J/DMbjjYk8VZJFkzqJfZnFi4iP5P5W6ZDj7+n2/hw/jZUhtE0lRXfU9nmaPV7vUhJWIZ0
	 +Sgisnx/lF4us4awYpkakwL6yFpu9rG4V1RZdOeTkwrsJ+I8tDVUwjamUnISd8aYAB21t
	 mIKAFcZ330oofaSncSuwyaLVzgcqLo24ffiyBUMoN6XCqb+Mvh3lT3sQp5DyPxFcjxQ==
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=vkq048T1;
	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 1046E606A33D;
	Mon, 30 Nov 2026 21:51:51 +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=vkq048T1
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=1796075510;
	b=ebk3SCJMRzjswcKc0PYbmX0tnMgKoidlnGHZydw13Dq6gFv54aJ4QPDQBe/07hp08SBt
	 WFSrU2vBWaO3iRYu6rC8FyE5pzIoBDhTWF5KzwFIRWeQmbp7CqXHjKVfOAN+0XrxVvpGy
	 4gBzMQGO16rSLdNUxC4twOCQB1QOnzJdMTEv5zzjtwUsdqJvJps3lIGqO/68L/efUlAxg
	 DvJssDuVC+h/25DVZtR1O4N+33bx2SdPFpjH7TBQtQ5wtvfrYoITO7Fj9VMBabfIbj3hH
	 V2dcVvZgoMKHAu/nHm8zQqUREQapuyqTfLHZqjO03qTaXLbngVE/FeLeuhnnkQVLmyw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796075510;
	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=LM2AcrnUy14scTk7llhQZMHvzDMRSdn4op+LrUBfz2Q=;
	b=Aq7/3VNjhI4stpbRn7mhYDbFAkkxRwu3gqcWXRjm/ARPS/td5BwVuZeIMWd+e60knVVi
	 as2xF5N1ZC5ZuolRPITTHT0T12haNIbYrvUeo0C68zg69MjWCoEm9MfwFjh0r2TUMtSEg
	 PK1h9jafpFoB/fwz0eox8LTuoEk7VoOWJt7pri/sPI8T5qi3l/Kv6sdd92tvs4GYIpfnY
	 Z468r5ZKtYC684rI7XE91BC+JZLTlOXclZt9x8kouzie8KJ7k3bUGkUVE9GgxU4q7JUO9
	 xJWRHYAVw4vpgDVmoMX7sFrKwu+hoO1nUp3z2GV0oJgnPXtMMZukDA3znKnyCJpvKUA==
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=vkq048T1;
	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 B7C53606A32C;
	Mon, 30 Nov 2026 21:51:49 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7C53606A32C
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=1796075507;
	bh=LM2AcrnUy14scTk7llhQZMHvzDMRSdn4op+LrUBfz2Q=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=vkq048T1vhq9XKFp52938Dw2ml5e5SGNNfyHDhjiqE3+PD4ZjEHYkMVp7piKyYRXt
	 JWrhO/271Sx8KLDtEBIJ7+hZa3KX9S5+ni2u9zguSiJT9nXvuvhP9inCYCCMtXgETQ
	 lQ/Qj2nUxY3X/fDbDRd+jcJ5wV4MLPqwJrCWgX9kp6uPvDqbAtMaAd913w7J2zNJdb
	 LvkiWB5s6McMSNMmgE2JNKEoZfSwLuGr11+KrekCFC/2GXrxkcrhHZiMN98aiF7/z6
	 K1urxihI255Z/kurhpzEp4tDpObYFQKJuG1nRYzS0MoAGeU8/Cb8REdDuIwSpw5OW+
	 IiAYVsfAszNQw==
X-Received: from localhost.localdomain (mail-agni [217.70.190.124])
	by mail.netfilter.org (Postfix) with ESMTPSA id 128916005F;
	Mon, 30 Nov 2026 22:51:47 +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: <20261130215141.1009148-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