From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
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
Subject: [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation
Date: Sun, 29 Nov 2026 01:07:11 +0100 [thread overview]
Message-ID: <20261129000724.797425-2-pablo@netfilter.org> (raw)
In-Reply-To: <20261129000724.797425-1-pablo@netfilter.org>
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
next prev parent reply other threads:[~2026-11-29 0:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
2026-11-29 0:07 ` Pablo Neira Ayuso [this message]
2026-11-29 0:14 ` [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation netdev-bot+sinfo
2026-11-29 0:16 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 02/14] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 03/14] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 04/14] netfilter: conntrack: wait for RCU readers before freeing the hash Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 05/14] netfilter: conntrack: attach generated TCP resets as ESTABLISHED Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 06/14] netfilter: nf_conntrack: limit expectation master chain depth Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 07/14] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 08/14] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 09/14] netfilter: synproxy: fix double tsoff application in server ACK TSecr Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 10/14] netfilter: nf_tables: only disable tables on a dormant transition Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 11/14] netfilter: nf_tables: add NFT_HOOK_UNREGISTERED and use it Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 12/14] netfilter: nf_tables: unbind flowtable on hook release Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 13/14] netfilter: nf_tables: flush destroy work from flowtable netdev event handler Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 14/14] netfilter: ipv6: stop the conntrack fragment search at AH Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129000724.797425-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox