* [PATCH v3] netfilter: nft_ct: reject shared conntrack extension updates
@ 2026-12-04 7:19 zhuorao yang
2026-12-04 7:32 ` netdev-bot+sinfo
2026-12-05 7:32 ` [PATCH v3] " netdev-bot+sashiko
0 siblings, 2 replies; 7+ messages in thread
From: zhuorao yang @ 2026-12-04 7:19 UTC (permalink / raw)
To: pablo, fw, davem, edumazet, kuba, pabeni, willemb
Cc: netfilter-devel, coreteam, netdev
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] netfilter: nft_ct: reject shared conntrack extension updates
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 ` [PATCH v4] " zhuorao yang
2026-12-05 7:32 ` [PATCH v3] " netdev-bot+sashiko
1 sibling, 1 reply; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 7:32 UTC (permalink / raw)
To: zhuorao yang
Cc: pablo, fw, davem, edumazet, kuba, pabeni, willemb,
netfilter-devel, coreteam, netdev
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4] netfilter: nft_ct: reject shared conntrack extension updates
2026-12-04 7:32 ` netdev-bot+sinfo
@ 2026-12-04 7:33 ` zhuorao yang
2026-12-04 7:36 ` netdev-bot+sinfo
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: zhuorao yang @ 2026-12-04 7:33 UTC (permalink / raw)
To: pablo, fw, davem, edumazet, kuba, pabeni, willemb
Cc: netfilter-devel, coreteam, netdev
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4] netfilter: nft_ct: reject shared conntrack extension updates
2026-12-04 7:33 ` [PATCH v4] " zhuorao yang
@ 2026-12-04 7:36 ` netdev-bot+sinfo
2026-12-04 11:12 ` Florian Westphal
2026-12-05 8:21 ` netdev-bot+sashiko
2 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 7:36 UTC (permalink / raw)
To: zhuorao yang
Cc: pablo, fw, davem, edumazet, kuba, pabeni, willemb,
netfilter-devel, coreteam, netdev
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4] netfilter: nft_ct: reject shared conntrack extension updates
2026-12-04 7:33 ` [PATCH v4] " zhuorao yang
2026-12-04 7:36 ` netdev-bot+sinfo
@ 2026-12-04 11:12 ` Florian Westphal
2026-12-05 8:21 ` netdev-bot+sashiko
2 siblings, 0 replies; 7+ messages in thread
From: Florian Westphal @ 2026-12-04 11:12 UTC (permalink / raw)
To: zhuorao yang
Cc: pablo, davem, edumazet, kuba, pabeni, willemb, netfilter-devel,
coreteam, netdev
zhuorao yang <alex000young@gmail.com> wrote:
> 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.
Nak. Playing whack-a-mole with stunts like this is getting us nowhere.
There are dozen of similar bugs like this all over conntrack.
It'll take time to rewrite the core assumptions cleanly. Changes in
dozen different places is not the way to go.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] netfilter: nft_ct: reject shared conntrack extension updates
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-05 7:32 ` netdev-bot+sashiko
1 sibling, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 7:32 UTC (permalink / raw)
To: alex000young
Cc: pablo, fw, davem, edumazet, kuba, pabeni, willemb,
netfilter-devel, coreteam, netdev
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 3 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] nf_ct_is_unconfirmed_shared() treats any unconfirmed conntrack
with refcount > 1 as 'shared', and the four new call sites then return…
- [High] The commit message describes the bug class as concurrent clones
calling nf_ct_ext_add() on the same unconfirmed ct, where krealloc()…
- [Medium] The commit message says 'Cloned skbs can otherwise reach
nft_ct extension paths concurrently' and adds a Fixes: tag, presenting…
- [Medium] nf_ct_is_unconfirmed_shared() reads IPS_CONFIRMED_BIT again,
even though every caller has just checked nf_ct_is_confirmed():…
- [Medium] nf_ct_is_unconfirmed_shared() reads
'refcount_read(&ct->ct_general.use) > 1' on an unconfirmed ct as proof…
- [Low] The new public helper nf_ct_is_unconfirmed_shared() in
include/net/netfilter/nf_conntrack.h repeats the predicate already…
--
netfilter: nft_ct: reject shared conntrack extension updates
This commit adds nf_ct_is_unconfirmed_shared(). The helper treats an
unconfirmed conntrack with a refcount above one as shared. It is called
from nft_ct_set_eval(), nft_ct_timeout_obj_eval(), nft_ct_helper_obj_eval()
and nft_ct_expect_obj_eval(), which drop the packet before nf_ct_ext_add()
can krealloc() ct->ext.
> Cloned skbs can otherwise reach nft_ct extension paths concurrently and
> call nf_ct_ext_add() on the same ct->ext.
[Severity: Medium]
Is there a known path where this happens concurrently without a test
harness? The attached report says:
"The exact shared-skbs network path has not yet been shown without the
test harness."
The in-tree clone sites seem to process their clones one after another on
the same CPU:
ip_mr_forward()
skb2 = skb_clone(skb, GFP_ATOMIC)
ipmr_queue_fwd_xmit(net, mrt, true_vifi, skb2, psend)
NF_HOOK(NF_INET_FORWARD, ...)
deliver_clone()
skb = skb_clone(skb, GFP_ATOMIC)
__br_forward(fwd, skb, local_orig)
The known asynchronous cases look like they are already handled:
- nf_ct_drop_unconfirmed() in nfnetlink_queue drops shared unconfirmed
conntracks.
- nf_ct_bridge_in() and br_nf_local_in() detach or reset an unconfirmed
ct before passing frames up. That covers the macvlan on top of a bridge
case.
This patch has a Fixes: tag and changes when packets get dropped. Could
the commit message name the concurrent path, or say that the race has not
been confirmed?
> diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
> index c39425e54d87d..e6c47178af5bc 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) &&
[Severity: Medium]
Every caller has already checked nf_ct_is_confirmed() before calling this
helper. If clones really can run concurrently, can another CPU confirm the
ct between the two reads?
CPU0 CPU1
nft_ct_helper_obj_eval()
nf_ct_is_confirmed(ct) -> false
__nf_conntrack_confirm()
__nf_conntrack_insert_prepare(ct)
__nf_conntrack_hash_insert(...)
set_bit(IPS_CONFIRMED_BIT, ...)
nf_ct_is_unconfirmed_shared(ct)
!nf_ct_is_confirmed(ct) -> false
nf_ct_helper_ext_add(ct, GFP_ATOMIC)
nf_ct_ext_add()
WARN_ON(nf_ct_is_confirmed(ct))
krealloc(ct->ext, ...)
In that window the helper returns false at the moment the ct is being
shared. nf_ct_ext_add() only warns, then reallocates ct->ext on a ct that
is now in the hash table. The same pattern exists in the expect, timeout
and event mask callers.
The callers have already seen the ct as unconfirmed. Would testing only
the refcount here close this window?
> + refcount_read(&ct->ct_general.use) > 1;
[Severity: High]
Can a refcount above one tell concurrent clones apart from clones that
are handled one after another? ip_mr_forward() clones the skb for each
output vif. It runs each clone through the forward and postrouting hooks
synchronously, while the original skb still holds its _nfct reference:
net/ipv4/ipmr.c:ip_mr_forward() {
...
struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
if (skb2)
ipmr_queue_fwd_xmit(net, mrt, true_vifi, skb2,
psend);
...
}
Bridge flooding works the same way through deliver_clone() ->
__br_forward() -> NF_BR_FORWARD, plus the inet forward hooks when
br_netfilter is used. The comments in nf_ct_drop_unconfirmed() and
__nf_conntrack_confirm() say these clones are expected.
Before this patch, the first clone added the extension and was confirmed
in NF_INET_POST_ROUTING. Later clones skipped the add because
nf_ct_is_confirmed() returned true.
With this patch, a ct helper set, ct timeout set, ct expectation set or ct
event set rule in forward or postrouting sees refcount 2 and drops the
first clone. A dropped clone never confirms the ct, so every later clone
is dropped too. Only the original skb can pass, and only once the
refcount is back to 1.
In the local multicast branch above, and in bridge flooding with
local_rcv, every forwarded copy is dropped. Local delivery then confirms
the ct without the configured helper, timeout or event policy.
For NFT_CT_EVENTMASK, the packet used to be accepted even when
nf_ct_ecache_ext_add() failed. It is now dropped.
Is this regression intended? The commit message does not mention it.
[Severity: Medium]
Can this also return true for a ct that only one skb owns? nf_conn
objects are SLAB_TYPESAFE_BY_RCU. Hash walkers can briefly take a
reference on an object that was just recycled into a new unconfirmed
conntrack, as init_conntrack() notes:
/* Other CPU might have obtained a pointer to this object before it was
* released. Because refcount is 0, refcount_inc_not_zero() will fail.
*
* After refcount_set(1) it will succeed; ...
Walkers that do this include nf_ct_gc_expired() (reached from
____nf_conntrack_find()), __nf_conntrack_find_get(), early_drop_list()
and gc_worker().
While one of them holds its reference, a first packet that was never
cloned reads refcount 2 here, and the four nft_ct callers drop it.
early_drop_list() runs when the table is under pressure, which is also
when new conntracks are being created quickly.
Is a lifetime refcount a reliable test for exclusive ownership here?
> +}
[Severity: Low]
This isn't a bug, but the same predicate is already open-coded in
nf_ct_drop_unconfirmed() in net/netfilter/nfnetlink_queue.c:
if (!ct || nf_ct_is_confirmed(ct))
return false;
...
return refcount_read(&ct->ct_general.use) > 1;
br_nf_local_in() tests the same condition as:
refcount_read(&nfct->use) != 1
Neither of these is converted to the new helper. The tree now has three
copies of the check with three different policies:
- nfqueue drops the packet.
- br_netfilter warns, resets the ct and accepts.
- nft_ct drops the packet.
Should the existing users switch to the new helper? Is there a reason
nft_ct follows the nfqueue policy and not the br_netfilter one?
> diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
> index 5a8db55920364..5dad764fb5763 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
[Severity: High]
If clones can run concurrently on different CPUs, as the commit message
says, does guarding these four nft_ct call sites close the race?
nf_ct_ext_add() has no lock and no sharing check. Other packet path
writers still reallocate ct->ext on an unconfirmed ct:
nft_masq / masquerade target
nf_nat_masquerade_ipv4()
nf_ct_nat_ext_add()
nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC)
nft_nat
nf_nat_setup_info()
/* Non-atomic: we own this at the moment. */
nfct_seqadj_ext_add()
act_ct
tcf_ct_act()
__nf_ct_try_assign_helper()
nft_ct also accesses ct->ext before the new check is reached. Just above
this hunk, nft_ct_set_eval() does:
struct nf_conntrack_ecache *e = nf_ct_ecache_find(ct);
...
if (e) {
if (e->ctmask != ctmask)
e->ctmask = ctmask;
break;
}
The same is true for nf_ct_timeout_find() in nft_ct_timeout_obj_eval(),
nfct_help() in nft_ct_expect_obj_eval(), and the extension reads in
nft_ct_get_eval().
Suppose clone A is masqueraded on CPU0 while clone B runs a ct event set
rule on CPU1:
CPU0 CPU1
nft_ct_set_eval()
e = nf_ct_ecache_find(ct)
nf_nat_masquerade_ipv4()
nf_ct_nat_ext_add()
krealloc(ct->ext, ...)
e->ctmask = ctmask
Would that write go into the freed ct->ext? Two concurrent masquerades
would also hit the same krealloc() double free seen in the report.
Would enforcing exclusivity in one place cover all of these? That could
be nf_ct_ext_add() itself, or the point where clones are created or
diverge, as nf_ct_bridge_in(), br_nf_local_in() and
nf_ct_drop_unconfirmed() already do.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204071902.36828-1-alex000young%40gmail.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4] netfilter: nft_ct: reject shared conntrack extension updates
2026-12-04 7:33 ` [PATCH v4] " zhuorao yang
2026-12-04 7:36 ` netdev-bot+sinfo
2026-12-04 11:12 ` Florian Westphal
@ 2026-12-05 8:21 ` netdev-bot+sashiko
2 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 8:21 UTC (permalink / raw)
To: alex000young
Cc: pablo, fw, davem, edumazet, kuba, pabeni, willemb,
netfilter-devel, coreteam, netdev
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The fix is incomplete: the use-after-free it targets can still
be reached.
- [High] netfilter: nf_ct_is_unconfirmed_shared() fails open on
concurrent confirm
- [Medium] The new check makes normal same-CPU clone fan-out drop
packets.
- [Medium] nf_ct_is_unconfirmed_shared() reads ct_general.use, a general
lifetime refcount, as if it counted skbs that might be using ct->ext…
- [Low] netfilter: nf_ct_is_unconfirmed_shared() duplicates existing
nf_ct_shared()
--
netfilter: nft_ct: reject shared conntrack extension updates
This patch adds nf_ct_is_unconfirmed_shared(). It reports an unconfirmed
conntrack whose ct_general.use refcount is above one. The nft_ct
eventmask, timeout, helper and expect paths now use it to drop the packet
before calling nf_ct_ext_add(). The goal is to stop two cloned skbs on
different CPUs from racing on the krealloc() of ct->ext.
> diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
> index c39425e54d87d..e6c47178af5bc 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;
> +}
[Severity: Low]
include/net/netfilter/nf_conntrack.h already provides nf_ct_shared(),
which returns refcount_read(&ct->ct_general.use) > 1. It is used by
net/openvswitch/conntrack.c and net/sched/act_ct.c. Could the new
helper call nf_ct_shared() instead of open-coding the same refcount
test?
The !nf_ct_is_confirmed() part of the predicate may turn out not to be
needed (see the concurrent confirm question on this helper). If so, the
nft_ct callers could just use nf_ct_shared() directly, and this new
helper could go away.
[Severity: High]
Each caller has already tested nf_ct_is_confirmed(ct) near the top of
the function. So the !nf_ct_is_confirmed() half of this helper only
changes the result when the ct gets confirmed in between. In that case
it makes the guard return false and lets the extension add go ahead.
That seems to be the opposite of what is wanted.
Consider two clones sharing an unconfirmed ct in
nft_ct_helper_obj_eval():
CPU 0 CPU 1
nf_ct_is_confirmed(ct) false
__nf_conntrack_confirm()
__nf_conntrack_insert_prepare()
refcount_inc(&ct->ct_general.use)
__nf_conntrack_hash_insert()
set_bit(IPS_CONFIRMED_BIT, ...)
nfct_help(ct)
nf_conntrack_event_cache()
nf_ct_is_unconfirmed_shared(ct)
returns false
nf_ct_helper_ext_add()
nf_ct_ext_add()
WARN_ON(nf_ct_is_confirmed(ct))
krealloc(ct->ext, alloc, gfp)
The WARN_ON() in nf_ct_ext_add() does not return, so the krealloc()
still runs. It frees the old ct->ext while CPU 1 may still be reading
it. So may any lockless lookup that has already found the ct in
nf_conntrack_hash. nf_ct_helper_ext_add() then also does a non-atomic
__set_bit(IPS_HELPER_BIT, &ct->status) on a status word that other
CPUs now update.
The window is wider than it looks. In the helper path it spans the
nf_ct_l3num() switch and the IPS_HELPER_BIT test. The timeout path
has nf_ct_timeout_find() in between, and the expect path has
nfct_help(). Even in nft_ct_set_eval() the two checks are separate
loads of ct->status.
Is the confirmed test needed in this helper at all? Every caller has
already done it. Any sibling skb that could confirm the ct already
holds its own reference, so the refcount would already show it. Would
it be enough to drop on the refcount alone? Or should a confirmed ct
also count as shared, so a concurrent confirm cannot let the check
pass?
[Severity: Medium]
ct_general.use is the general lifetime refcount of the conntrack. It does
not count the skbs that might be touching ct->ext at the same time. Can
this report a ct as shared when only one context owns it?
One case is nf_conntrack_attach(). It is reached through nf_ct_attach()
from nf_send_reset(), nf_send_unreach() and the ICMP error paths:
net/netfilter/nf_conntrack_core.c:nf_conntrack_attach() {
...
/* Attach to new skbuff, and increment count */
nf_ct_set(nskb, ct, ctinfo);
nf_conntrack_get(skb_nfct(nskb));
}
Two examples: a new connection hits an nft reject in the input chain
before the LOCAL_IN confirm, or ip_forward() sends a TTL-exceeded error
before the FORWARD hook. In both, the RST or ICMP skb goes through
LOCAL_OUT and POSTROUTING on the same CPU. The original skb still holds
its reference, so the refcount is at least 2.
Would a ct helper set or ct event set rule in an output or postrouting
chain now drop these reject and error replies?
Another case is SLAB_TYPESAFE_BY_RCU reuse. The comment in
init_conntrack() says another CPU holding a stale pointer can succeed
with refcount_inc_not_zero() once the count is set to 1:
* released. Because refcount is 0, refcount_inc_not_zero() will fail.
*
* After refcount_set(1) it will succeed; ensure that zeroing of
...
smp_wmb();
/* Now it is going to be associated with an sk_buff, set refcount to 1. */
refcount_set(&ct->ct_general.use, 1);
While a lookup, gc or iterate walker briefly holds such a reference, a
ct with a single owner reads as refcount 2. Could the first packet of
that new connection be dropped at random here, with no concurrent
krealloc() involved?
[ ... ]
> diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
> index 5a8db55920364..5dad764fb5763 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
[Severity: High]
Does this fully close the race described in the commit message? The
free happens in nf_ct_ext_add(), and its only guard is the confirmed
check:
net/netfilter/nf_conntrack_extend.c:nf_ct_ext_add() {
...
/* Conntrack must not be confirmed to avoid races on reallocation. */
WARN_ON(nf_ct_is_confirmed(ct));
...
new = krealloc(ct->ext, alloc, gfp);
...
}
Other callers still reach that krealloc() on a shared unconfirmed ct
without the new check:
nft_masq_eval()->nf_nat_masquerade_ipv4()->nf_ct_nat_ext_add()
the OVS NAT path in nf_nat_ovs.c and the PPTP NAT helper in
nf_nat_pptp.c, both through nf_ct_nat_ext_add()
nf_nat_setup_info()->nfct_seqadj_ext_add(), which still sits under
the "Non-atomic: we own this at the moment." comment
Some of the nft_ct paths also read ct->ext before the new check. In this
function, the eventmask case does:
struct nf_conntrack_ecache *e = nf_ct_ecache_find(ct);
...
if (e) {
if (e->ctmask != ctmask)
e->ctmask = ctmask;
break;
}
Suppose one clone runs masquerade on CPU A and reallocates ct->ext. At
the same time, a sibling clone on CPU B is in this block. Can the
e->ctmask write land in freed memory?
nf_ct_timeout_find() in nft_ct_timeout_obj_eval() and nfct_help() in
nft_ct_expect_obj_eval() have the same ordering. In the timeout case, an
existing extension skips the new check entirely, and its contents are
used afterwards.
Upstream already notes that such clones can run in parallel, in the
nf_ct_drop_unconfirmed() comment in nfnetlink_queue.c:
* This can't be solved with serialization here because one clone
* could have been queued for local delivery or could be transmitted
* in parallel on another CPU.
Would it be more robust to make nf_ct_ext_add() itself refuse to grow
ct->ext for a shared unconfirmed ct, next to the WARN_ON? Every caller
already handles a NULL return there. The other option would be to stop
the sharing itself. Either seems better than per-caller checks in
nft_ct.
[ ... ]
> @@ -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);
[Severity: Medium]
Will this drop packets during normal clone fan-out that runs one clone
after another on a single CPU?
With nf_conntrack_bridge, the ct is created in nf_ct_bridge_pre() and is
only confirmed at NF_BR_POST_ROUTING. When flooding, deliver_clone()
clones before the hook runs:
net/bridge/br_forward.c:deliver_clone() {
...
skb = skb_clone(skb, GFP_ATOMIC);
...
}
__br_forward() then runs the hook on the clone:
NF_HOOK(NFPROTO_BRIDGE, br_hook,
net, NULL, skb, indev, skb->dev,
br_forward_finish);
So every flooded clone sees refcount >= 2 on the unconfirmed ct. When
local_rcv is set, for example for broadcast, br_flood_finish() also
clones for the last port:
if (local_rcv)
deliver_clone(fwd, skb, local_orig);
else
__br_forward(fwd, skb, local_orig);
ip_mc_output() does something similar for locally generated multicast
and broadcast. It sends a clone through NF_INET_POST_ROUTING while the
original still holds a ct reference.
Before this patch, the first clone added the helper extension and set
IPS_HELPER_BIT, and later clones returned early at the test_bit() above.
nft_ct_helper_obj_init() accepts NFPROTO_BRIDGE, NFPROTO_NETDEV and
NFPROTO_INET. Would ct helper set, ct timeout set or ct event set rules
in a bridge forward or postrouting chain, or in an inet postrouting
chain, now drop the first packets of flooded, broadcast or multicast
flows such as DHCP, mDNS or SSDP?
This also makes these paths stricter than an allocation failure. Before,
a NULL from nf_ct_helper_ext_add() here just meant no helper, and
nft_ct_set_eval() ignored the result of nf_ct_ecache_ext_add(). Both now
drop the packet when the ct is shared.
The commit message only describes the race fix. Could it mention this
change in behaviour?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204073358.67941-1-alex000young%40gmail.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-05 8:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v4] " zhuorao yang
2026-12-04 7:36 ` netdev-bot+sinfo
2026-12-04 11:12 ` Florian Westphal
2026-12-05 8:21 ` netdev-bot+sashiko
2026-12-05 7:32 ` [PATCH v3] " netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox