Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.190.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073946; b=OhnVY67Qr5Yinz9TGYK2Ll8Vpk0pxm1+rzDQfiCsNe9hEYHZ4CDHqSD7jyhhMwjs401Y Zat06zr3M0Un7MgaASsVJ6tcz1FP1z+BdZWdQQi37AS4h2BHk/QVJdfgQDJOLAS3y8azY L3pMbfuY/z9vmEubvmSNEvzCqR3fUTh0ld8s369rG1/pDRMGC/YTxqzs4LeRfyMnWSHKy +LzkPkVRtzns7Mdt0cV5mlrlc+tmsU+mNAqNh5XhxiYQuHc/+kWAo3t9SDdksqN2gTPC0 aaWXUf8hZxvr3NjHlr46n5bZhnkDusvgS6krqjVMijqyuKw371UqopcEdlMA/mY4pkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073946; h=DMARC-Filter:DKIM-Signature:Received:From:To: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=xMwbWGR+GCHM5A/ZdaWOVplW4ZIFa3sWlbA3VHdTr86lp0BJHu99w2k7kkVO09C8kN2S AxLO+DnVvWo9i56Jnoob2553UE8X1cpqTw5miGsNXDn1zNimCbOX1diOPy/2cPR1Q3zMB 6WIf0uNOUYahF3OfO6yJc5vd68IVvhHnEEMI3IIbbcT5rcC/b7EU6qndNOMpNSXJGBwva EtqytWH/F8ArQKEHi1XFgOS9hKK1Pmk7mIFTpUIJfsNZ3l8TTsQLwod1ELcsLceCTxAe9 7pFDOq7YXK6WE1kWTYm5kqVqoMeTZmtoGOThkl3Y7dDmdRWrp5K3l8vkPOhcES7YKYg== 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=n4udJs1u; arc=none smtp.remote-ip=217.70.190.124 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 EC0D2606A320 for ; Mon, 30 Nov 2026 21:25:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EC0D2606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org 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=n4udJs1u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1796073944; bh=LM2AcrnUy14scTk7llhQZMHvzDMRSdn4op+LrUBfz2Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=n4udJs1u1oXlsD8y3YT0bMv0lVgmP9EOfCfb8a3PRedecLI2EV9+euh5Gtujg8Ij1 bgl2rqFJyZ88Do+X8mBoQub3Cgsg3inRYsVcNlduLD5dlcVi4BelYmuJUiGSQax8ab 7Dtl/yaI6q88PvTWplJ/2mSYWnKaXteq2u7rQoNtjvpyiDEtG82XJydarfSDO8pDWo 2LEXrsbt8+vDneHN7cwcALnh+A0rQK8j/rEhQWxT51IHlxG4R/erUQJQ4+uo1U04YV E50lU4SjQIhBA6PlwsRKx1zQ9p1hd3jrtVVGxZa8HJVxDW/HnM+L9zmX/5q5+9KiqB I7mc3KzLW5URg== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id 2ABC06008C for ; Mon, 30 Nov 2026 22:25:44 +0100 (CET) From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Subject: [PATCH net 01/10] netfilter: conntrack: prevent helper extension relocation Date: Mon, 30 Nov 2026 22:25:30 +0100 Message-ID: <20261130212539.992130-2-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130212539.992130-1-pablo@netfilter.org> References: <20261130212539.992130-1-pablo@netfilter.org> X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jaeyeong Lee 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 Signed-off-by: Pablo Neira Ayuso --- 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