Netdev List
 help / color / mirror / Atom feed
From: zhuorao yang <alex000young@gmail.com>
To: pablo@netfilter.org, fw@strlen.de, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	willemb@google.com
Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	netdev@vger.kernel.org
Subject: [PATCH v4] netfilter: nft_ct: reject shared conntrack extension updates
Date: Fri,  4 Dec 2026 15:33:58 +0800	[thread overview]
Message-ID: <20261204073358.67941-1-alex000young@gmail.com> (raw)
In-Reply-To: <179636957458.3305.6694386152606528641@kernel.org>

An unconfirmed conntrack is mutable and assumes exclusive skb ownership.
Cloned skbs can otherwise reach nft_ct extension paths concurrently and
call nf_ct_ext_add() on the same ct->ext. Since nf_ct_ext_add() uses
krealloc(), this can free and replace one allocation while another CPU
still uses it.

Reject packets that reference a shared unconfirmed conntrack before any
nft_ct extension allocation is attempted. This covers helper, expect,
timeout, and event-cache extensions without adding a lock to the generic
helper API.

Fixes: 1a64edf54f55 ("netfilter: nft_ct: add helper set support")
Signed-off-by: zhuorao yang <alex000young@gmail.com>
---

Vulnerability report

Affected versions: Linux 7.4.0-rc5 at
  fe6ff8d5d675c01793b9f051d16055dd4aa75244; the helper-set path dates to
  v4.12.
Trigger conditions: CONFIG_NFT_CT and CAP_NET_ADMIN in the target
  network namespace. Two skbs must share the same unconfirmed conntrack
  and execute nft_ct_helper_obj_eval() concurrently on different CPUs.
  Existing accounting, timestamp, event-cache, or label extensions make
  the helper extension enlarge and relocate ct->ext.
Reproducer status: A QEMU KASAN harness forced two CPUs to enter
  nf_ct_helper_ext_add() on the same unconfirmed conntrack with a
  104-byte extension allocation. The unpatched kernel produced a double-
  free in krealloc_node_align_noprof. With the fix, 1000 synchronized
  two-CPU iterations completed without KASAN. The exact shared-skbs
  network path has not yet been shown without the test harness.
Reproducer material is intentionally withheld from this initial private report.

 include/net/netfilter/nf_conntrack.h | 10 ++++++++++
 net/netfilter/nft_ct.c               | 21 ++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index c39425e54d87..e6c47178af5b 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -271,6 +271,16 @@ static inline int nf_ct_is_confirmed(const struct nf_conn *ct)
 	return test_bit(IPS_CONFIRMED_BIT, &ct->status);
 }
 
+/*
+ * Unconfirmed conntracks are mutable and assume exclusive skb ownership.
+ * Cloned skbs can otherwise race on extension reallocation.
+ */
+static inline bool nf_ct_is_unconfirmed_shared(const struct nf_conn *ct)
+{
+	return !nf_ct_is_confirmed(ct) &&
+	       refcount_read(&ct->ct_general.use) > 1;
+}
+
 static inline int nf_ct_is_dying(const struct nf_conn *ct)
 {
 	return test_bit(IPS_DYING_BIT, &ct->status);
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index 5a8db5592036..5dad764fb576 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -323,8 +323,13 @@ static void nft_ct_set_eval(const struct nft_expr *expr,
 			break;
 		}
 
-		if (ctmask && !nf_ct_is_confirmed(ct))
+		if (ctmask && !nf_ct_is_confirmed(ct)) {
+			if (nf_ct_is_unconfirmed_shared(ct)) {
+				regs->verdict.code = NF_DROP;
+				break;
+			}
 			nf_ct_ecache_ext_add(ct, ctmask, 0, GFP_ATOMIC);
+		}
 		break;
 	}
 #endif
@@ -891,6 +896,10 @@ static void nft_ct_timeout_obj_eval(struct nft_object *obj,
 
 	timeout = nf_ct_timeout_find(ct);
 	if (!timeout) {
+		if (nf_ct_is_unconfirmed_shared(ct)) {
+			regs->verdict.code = NF_DROP;
+			return;
+		}
 		timeout = nf_ct_timeout_ext_add(ct, priv->timeout, GFP_ATOMIC);
 		if (!timeout) {
 			regs->verdict.code = NF_DROP;
@@ -1143,6 +1152,11 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj,
 	if (test_bit(IPS_HELPER_BIT, &ct->status))
 		return;
 
+	if (nf_ct_is_unconfirmed_shared(ct)) {
+		regs->verdict.code = NF_DROP;
+		return;
+	}
+
 	help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);
 	if (help && refcount_inc_not_zero(&to_assign->ct_refcnt)) {
 		rcu_assign_pointer(help->helper, to_assign);
@@ -1429,6 +1443,11 @@ static void nft_ct_expect_obj_eval(struct nft_object *obj,
 		return;
 	}
 
+	if (nf_ct_is_unconfirmed_shared(ct)) {
+		regs->verdict.code = NF_DROP;
+		return;
+	}
+
 	help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);
 	if (!help) {
 		regs->verdict.code = NF_DROP;
-- 
2.56.0


      reply	other threads:[~2026-12-04  7:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  7:19 [PATCH v3] netfilter: nft_ct: reject shared conntrack extension updates zhuorao yang
2026-12-04  7:32 ` netdev-bot+sinfo
2026-12-04  7:33   ` zhuorao yang [this message]

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=20261204073358.67941-1-alex000young@gmail.com \
    --to=alex000young@gmail.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=willemb@google.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