* [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
@ 2026-11-29 0:07 ` Pablo Neira Ayuso
2026-11-29 0:14 ` netdev-bot+sinfo
2026-11-29 0:07 ` [PATCH net 02/14] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
` (12 subsequent siblings)
13 siblings, 1 reply; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
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
^ permalink raw reply related [flat|nested] 28+ messages in thread* Re: [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation
2026-11-29 0:07 ` [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
@ 2026-11-29 0:14 ` netdev-bot+sinfo
2026-11-29 0:16 ` Pablo Neira Ayuso
0 siblings, 1 reply; 28+ messages in thread
From: netdev-bot+sinfo @ 2026-11-29 0:14 UTC (permalink / raw)
To: Pablo Neira Ayuso
Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
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.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
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] 28+ messages in thread
* Re: [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation
2026-11-29 0:14 ` netdev-bot+sinfo
@ 2026-11-29 0:16 ` Pablo Neira Ayuso
0 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:16 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, horms, fw,
ja
Hi,
On Sun, Nov 29, 2026 at 12:14:24AM +0000, netdev-bot+sinfo@kernel.org wrote:
> 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.
>
> - Whether the issue was actually triggered, or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
This is PR containing netfilter fixes.
These are mostly LLM finding, unless stated otherwise as described in
the cover letter.
> 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] 28+ messages in thread
* [PATCH net 02/14] netfilter: xt_IDLETIMER: restrict to init_net
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
@ 2026-11-29 0:07 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 03/14] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
` (11 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Zhiling Zou <zhilinz@nebusec.ai>
IDLETIMER keeps its timer registry, reference counts, and sysfs files in
module-global state, while Xtables invokes checkentry and destroy for
rules in individual network namespaces. A matching label from another
namespace can therefore reuse and control an existing timer.
The sysfs interface is global and cannot represent per-namespace labels
with the current target design. Reject IDLETIMER rules outside init_net
so that global state stays in the namespace it was built for.
Fixes: 0902b469bd25 ("netfilter: xtables: idletimer target implementation")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Signed-off-by: Zhiling Zou <zhilinz@nebusec.ai>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_IDLETIMER.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/net/netfilter/xt_IDLETIMER.c b/net/netfilter/xt_IDLETIMER.c
index 71b78b5da698..2449c091cdf6 100644
--- a/net/netfilter/xt_IDLETIMER.c
+++ b/net/netfilter/xt_IDLETIMER.c
@@ -28,6 +28,7 @@
#include <linux/kobject.h>
#include <linux/workqueue.h>
#include <linux/sysfs.h>
+#include <net/net_namespace.h>
struct idletimer_tg {
struct list_head entry;
@@ -308,6 +309,9 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
struct idletimer_tg_info *info = par->targinfo;
int ret;
+ if (!net_eq(par->net, &init_net))
+ return -EOPNOTSUPP;
+
ret = idletimer_tg_helper(info);
if(ret < 0)
return -EINVAL;
@@ -341,6 +345,9 @@ static int idletimer_tg_checkentry_v1(const struct xt_tgchk_param *par)
struct idletimer_tg_info_v1 *info = par->targinfo;
int ret;
+ if (!net_eq(par->net, &init_net))
+ return -EOPNOTSUPP;
+
if (info->send_nl_msg)
return -EOPNOTSUPP;
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 03/14] netfilter: synproxy: prevent unbounded recursion in transmit path
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation 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 ` 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
` (10 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Fernando Fernandez Mancera <fmancera@suse.de>
Packets generated at synproxy_send_tcp() and synproxy_send_tcp_ipv6()
are handled by ip_local_out() and ip6_local_out) which traverse
LOCAL_OUT and POST_ROUTING. As SYNPROXY hooks are registered on
POST_ROUTING, a payload mangling rule at OUTPUT with priority raw can
rewrite the generated ACK to SYN|ACK before conntrack sees it.
This leaves the conntrack state in SYN_RECV state and synproxy sends two
more ACKs repeating the cycle until the IRQ stack guard page is hit:
BUG: IRQ stack guard page was hit
Oops: stack guard page: 0000 [#1] SMP NOPTI
synproxy_send_tcp
ipv4_synproxy_hook
nf_hook_slow
ip_output
ipv4_synproxy_hook
...
Fix this by applying the per-CPU xmit recursion limit. Note that this
cannot be triggered with iptables as it is not possible to modify the
TCP flags from raw priority.
Fixes: ad49d86e07a4 ("netfilter: nf_tables: Add synproxy support")
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_synproxy_core.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index 401ce5a13f3f..9dd681596c70 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -21,6 +21,7 @@
#include <net/netfilter/nf_conntrack_synproxy.h>
#include <net/netfilter/nf_conntrack_zones.h>
#include <net/netfilter/nf_synproxy.h>
+#include <net/netfilter/nf_recursion.h>
static DEFINE_MUTEX(synproxy_mutex);
@@ -439,7 +440,16 @@ synproxy_send_tcp(struct net *net,
nf_conntrack_get(nfct);
}
+ local_bh_disable();
+ if (nf_dev_xmit_recursion()) {
+ local_bh_enable();
+ goto free_nskb;
+ }
+
+ nf_dev_xmit_recursion_inc();
ip_local_out(net, nskb->sk, nskb);
+ nf_dev_xmit_recursion_dec();
+ local_bh_enable();
return;
free_nskb:
@@ -858,7 +868,16 @@ synproxy_send_tcp_ipv6(struct net *net,
nf_conntrack_get(nfct);
}
+ local_bh_disable();
+ if (nf_dev_xmit_recursion()) {
+ local_bh_enable();
+ goto free_nskb;
+ }
+
+ nf_dev_xmit_recursion_inc();
ip6_local_out(net, nskb->sk, nskb);
+ nf_dev_xmit_recursion_dec();
+ local_bh_enable();
return;
free_nskb:
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 04/14] netfilter: conntrack: wait for RCU readers before freeing the hash
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (2 preceding siblings ...)
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 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 05/14] netfilter: conntrack: attach generated TCP resets as ESTABLISHED Pablo Neira Ayuso
` (9 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Chengfeng Ye <nicoyip.dev@gmail.com>
nf_ct_get_tuple_skb() calls into conntrack under rcu_read_lock() without
holding a module reference. CAKE can use this hook to look up a packet
without an attached conntrack, even during nf_conntrack module teardown.
nf_conntrack_cleanup_end() clears nf_ct_hook but frees nf_conntrack_hash
without waiting for existing readers. The grace period in per-net cleanup
runs while the hook is still published, so a later reader can race as
follows:
CPU 0 (packet path) CPU 1 (module teardown)
rcu_read_lock()
ct_hook = rcu_dereference(nf_ct_hook)
RCU_INIT_POINTER(nf_ct_hook, NULL)
kvfree(nf_conntrack_hash)
ct_hook->get_tuple_skb()
nf_conntrack_find_get()
access freed hash bucket
rcu_read_unlock()
The same missing grace period affects initialization failure after
nf_conntrack_init_end() publishes the hook. During module teardown,
KASAN reported:
BUG: KASAN: vmalloc-out-of-bounds in __nf_conntrack_find_get.isra.0
Read of size 8 at addr ffffc900012e2ae0 by task poc/90
Call Trace:
__nf_conntrack_find_get.isra.0+0xf87/0x10c0 [nf_conntrack]
nf_conntrack_get_tuple_skb+0x255/0x400 [nf_conntrack]
nf_ct_get_tuple_skb+0x75/0xb0
cake_hash+0xfdb/0x1e10
cake_enqueue+0x5cd/0x36e0
dev_qdisc_enqueue+0x40/0x170
__dev_queue_xmit+0x1e90/0x3110
Wait for an RCU grace period after clearing nf_ct_hook, before releasing
the hash table and the remaining conntrack resources.
Fixes: b60a60405fb9 ("netfilter: Add nf_ct_get_tuple_skb global lookup function")
Cc: stable@vger.kernel.org
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 931b76aacd93..0cb5320883bd 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2454,6 +2454,7 @@ void nf_conntrack_cleanup_start(void)
void nf_conntrack_cleanup_end(void)
{
RCU_INIT_POINTER(nf_ct_hook, NULL);
+ synchronize_rcu();
cancel_delayed_work_sync(&conntrack_gc_work.dwork);
kvfree(nf_conntrack_hash);
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 05/14] netfilter: conntrack: attach generated TCP resets as ESTABLISHED
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (3 preceding siblings ...)
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 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 06/14] netfilter: nf_conntrack: limit expectation master chain depth Pablo Neira Ayuso
` (8 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: xujiahao <xujiahao@cmss.chinamobile.com>
nf_conntrack_attach() marks every packet it attaches as related to the
conntrack entry of the packet which caused it: IP_CT_RELATED_REPLY when
that packet was in the original direction, IP_CT_RELATED otherwise.
That is right for the ICMP errors built by icmp.c and icmpv6.c, but not
for the TCP resets built by nf_send_reset(): a reset is a packet of the
connection itself and carries the state of the connection, just like the
equivalent reset the TCP stack emits.
A locally generated reset therefore currently leaves through the
LOCAL_OUT nat hook as IP_CT_RELATED_REPLY. As no nat mapping is
initialized for it, nf_nat_inet_fn() evaluates the nat OUTPUT chain, so a
DNAT target reachable from that chain rewrites the reset and warns:
WARNING: net/netfilter/xt_nat.c:154 at xt_dnat_target_v2+0x97/0xc0
Pass the protocol of the generated packet to nf_ct_attach() and mark TCP
resets as ESTABLISHED/ESTABLISHED_REPLY. They then take the default
branch of nf_nat_inet_fn(), which only applies the mapping already
installed on the connection. ICMP errors keep IP_CT_RELATED/_REPLY.
Passing u8 l4proto rather than a boolean keeps the call sites readable,
as nf_ct_attach(new, skb, IPPROTO_TCP) says which packet is built.
Suggested-by: Florian Westphal <fw@strlen.de>
Reported-by: syzbot+2e819f6641708bb6ab9d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2e819f6641708bb6ab9d
Signed-off-by: xujiahao <xujiahao@cmss.chinamobile.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/linux/netfilter.h | 8 +++++---
net/ipv4/icmp.c | 2 +-
net/ipv4/netfilter/nf_reject_ipv4.c | 2 +-
net/ipv6/icmp.c | 2 +-
net/ipv6/netfilter/nf_reject_ipv6.c | 2 +-
net/netfilter/core.c | 4 ++--
net/netfilter/nf_conntrack_core.c | 27 +++++++++++++++++++++------
7 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index e99afc1414cd..c9771578f18d 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -454,13 +454,14 @@ nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
#include <linux/netfilter/nf_conntrack_zones_common.h>
-void nf_ct_attach(struct sk_buff *, const struct sk_buff *);
+void nf_ct_attach(struct sk_buff *, const struct sk_buff *, u8 l4proto);
void nf_ct_set_closing(struct nf_conntrack *nfct);
struct nf_conntrack_tuple;
bool nf_ct_get_tuple_skb(struct nf_conntrack_tuple *dst_tuple,
const struct sk_buff *skb);
#else
-static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
+static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb,
+ u8 l4proto) {}
static inline void nf_ct_set_closing(struct nf_conntrack *nfct) {}
struct nf_conntrack_tuple;
static inline bool nf_ct_get_tuple_skb(struct nf_conntrack_tuple *dst_tuple,
@@ -478,7 +479,8 @@ struct nf_ct_hook {
void (*destroy)(struct nf_conntrack *);
bool (*get_tuple_skb)(struct nf_conntrack_tuple *,
const struct sk_buff *);
- void (*attach)(struct sk_buff *nskb, const struct sk_buff *skb);
+ void (*attach)(struct sk_buff *nskb, const struct sk_buff *skb,
+ u8 l4proto);
void (*set_closing)(struct nf_conntrack *nfct);
int (*confirm)(struct sk_buff *skb);
u32 (*get_id)(const struct nf_conntrack *nfct);
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 90c0e22c29be..e01e3294132f 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -375,7 +375,7 @@ static int icmp_glue_bits(void *from, char *to, int offset, int len, int odd,
if (icmp_param->data.icmph.type <= NR_ICMP_TYPES &&
icmp_pointers[array_index_nospec(icmp_param->data.icmph.type,
NR_ICMP_TYPES + 1)].error)
- nf_ct_attach(skb, icmp_param->skb);
+ nf_ct_attach(skb, icmp_param->skb, IPPROTO_ICMP);
return 0;
}
diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
index 4082fa184af8..47baf3b8e41d 100644
--- a/net/ipv4/netfilter/nf_reject_ipv4.c
+++ b/net/ipv4/netfilter/nf_reject_ipv4.c
@@ -309,7 +309,7 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,
if (nskb->len > dst4_mtu(skb_dst(nskb)))
goto free_nskb;
- nf_ct_attach(nskb, oldskb);
+ nf_ct_attach(nskb, oldskb, IPPROTO_TCP);
nf_ct_set_closing(skb_nfct(oldskb));
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index d8203ebad882..8494a5b98a49 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -327,7 +327,7 @@ static int icmpv6_getfrag(void *from, char *to, int offset, int len, int odd, st
to, len);
skb->csum = csum_block_add(skb->csum, csum, odd);
if (!(msg->type & ICMPV6_INFOMSG_MASK))
- nf_ct_attach(skb, org_skb);
+ nf_ct_attach(skb, org_skb, IPPROTO_ICMP);
return 0;
}
diff --git a/net/ipv6/netfilter/nf_reject_ipv6.c b/net/ipv6/netfilter/nf_reject_ipv6.c
index 7c9464184517..98350cde587f 100644
--- a/net/ipv6/netfilter/nf_reject_ipv6.c
+++ b/net/ipv6/netfilter/nf_reject_ipv6.c
@@ -378,7 +378,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,
nf_reject_ip6hdr_put(nskb, oldskb, IPPROTO_TCP, ip6_dst_hoplimit(dst));
nf_reject_ip6_tcphdr_put(nskb, oldskb, otcph, otcplen);
- nf_ct_attach(nskb, oldskb);
+ nf_ct_attach(nskb, oldskb, IPPROTO_TCP);
nf_ct_set_closing(skb_nfct(oldskb));
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 44c856c1e621..a6ac172379af 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -702,7 +702,7 @@ EXPORT_SYMBOL_GPL(nf_nat_hook);
* tracking in use: without this, connection may not be in hash table, and hence
* manufactured ICMP or RST packets will not be associated with it.
*/
-void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb)
+void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb, u8 l4proto)
{
const struct nf_ct_hook *ct_hook;
@@ -710,7 +710,7 @@ void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb)
rcu_read_lock();
ct_hook = rcu_dereference(nf_ct_hook);
if (ct_hook)
- ct_hook->attach(new, skb);
+ ct_hook->attach(new, skb, l4proto);
rcu_read_unlock();
}
}
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 0cb5320883bd..7f113e221330 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2178,17 +2178,32 @@ EXPORT_SYMBOL_GPL(nf_ct_port_nlattr_tuple_size);
#endif
/* Used by ipt_REJECT and ip6t_REJECT. */
-static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb)
+static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb,
+ u8 l4proto)
{
struct nf_conn *ct;
enum ip_conntrack_info ctinfo;
- /* This ICMP is in reverse direction to the packet which caused it */
ct = nf_ct_get(skb, &ctinfo);
- if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
- ctinfo = IP_CT_RELATED_REPLY;
- else
- ctinfo = IP_CT_RELATED;
+ if (l4proto == IPPROTO_TCP) {
+ /*
+ * A reset we generate for an existing TCP connection belongs
+ * to that connection, it is not an error related to it, so it
+ * carries the state of the connection. Attaching it as
+ * related would let it take a fresh NAT mapping on its way
+ * out, i.e. rewrite the reset.
+ */
+ if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
+ ctinfo = IP_CT_ESTABLISHED_REPLY;
+ else
+ ctinfo = IP_CT_ESTABLISHED;
+ } else {
+ /* Errors are in reverse direction to the packet that caused them. */
+ if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
+ ctinfo = IP_CT_RELATED_REPLY;
+ else
+ ctinfo = IP_CT_RELATED;
+ }
/* Attach to new skbuff, and increment count */
nf_ct_set(nskb, ct, ctinfo);
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 06/14] netfilter: nf_conntrack: limit expectation master chain depth
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (4 preceding siblings ...)
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 ` 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
` (7 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Florian Westphal <fw@strlen.de>
A conntrack can point to a master conntrack, which itself may point to
another master, and so on. There is currently no bound on how deep this
chain can grow.
Force a max depth in nf_ct_expect_alloc(): walk the master chain and
reject allocation if it would exceed 8 levels of nesting.
Also add ctnetlink_find_get_master and use it so that ctnetlink create
paths return -EMLINK instead of falling through to nf_ct_expect_alloc()
and returning a misleading -ENOMEM.
This prevents unbounded ct->master->master->... chains.
This also restricts the number of call forward/redirects that h323 and sip
helpers will follow.
Reported-by: Daehyeon Ko <4ncienth@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_conntrack_helper.h | 15 +++++++++
net/netfilter/nf_conntrack_expect.c | 15 +++++++--
net/netfilter/nf_conntrack_netlink.c | 36 +++++++++++++++------
3 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h
index 335b8c43694f..53a8eda848dc 100644
--- a/include/net/netfilter/nf_conntrack_helper.h
+++ b/include/net/netfilter/nf_conntrack_helper.h
@@ -29,6 +29,8 @@ enum nf_ct_helper_flags {
#define NF_CT_HELPER_NAME_LEN 16
+#define NF_CT_MAX_EXPECT_CHAIN_LEN 8
+
/* Must be kept in sync with the classes defined by helpers */
#define NF_CT_MAX_EXPECT_CLASSES 4
@@ -159,6 +161,19 @@ static inline void nf_ct_help_put(const struct nf_conn *ct)
kfree_rcu(helper, rcu);
}
+static inline bool nf_ct_master_acceptable(const struct nf_conn *m)
+{
+ unsigned int depth = 0;
+
+ while (m->master) {
+ if (++depth >= NF_CT_MAX_EXPECT_CHAIN_LEN)
+ return false;
+ m = m->master;
+ }
+
+ return true;
+}
+
int nf_conntrack_helper_init(void);
void nf_conntrack_helper_fini(void);
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 06242c86e1dc..62e434cd57c9 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -299,13 +299,22 @@ void nf_ct_unexpect_related(struct nf_conntrack_expect *exp)
}
EXPORT_SYMBOL_GPL(nf_ct_unexpect_related);
-/* We don't increase the master conntrack refcount for non-fulfilled
- * conntracks. During the conntrack destruction, the expectations are
- * always killed before the conntrack itself */
+/**
+ * nf_ct_expect_alloc - allocate a new conntrack expectation
+ * @me: The conntrack to be used as master.
+ *
+ * The master conntrack refcount is not incremented; expectations
+ * are always killed before the master conntrack is destroyed.
+ *
+ * Return: a new expectation on success or NULL on failure.
+ */
struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me)
{
struct nf_conntrack_expect *new;
+ if (!nf_ct_master_acceptable(me))
+ return NULL;
+
new = kmem_cache_zalloc(nf_ct_expect_cachep, GFP_ATOMIC);
if (!new)
return NULL;
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 1f8d94a05240..30428d520e43 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -2231,6 +2231,26 @@ ctnetlink_change_conntrack(struct nf_conn *ct,
return 0;
}
+static struct nf_conn *
+ctnetlink_find_get_master(struct net *net, const struct nf_conntrack_zone *zone,
+ const struct nf_conntrack_tuple *tuple)
+{
+ struct nf_conntrack_tuple_hash *master_h;
+ struct nf_conn *master_ct;
+
+ master_h = nf_conntrack_find_get(net, zone, tuple);
+ if (!master_h)
+ return ERR_PTR(-ENOENT);
+
+ master_ct = nf_ct_tuplehash_to_ctrack(master_h);
+ if (!nf_ct_master_acceptable(master_ct)) {
+ nf_ct_put(master_ct);
+ return ERR_PTR(-EMLINK);
+ }
+
+ return master_ct;
+}
+
static struct nf_conn *
ctnetlink_create_conntrack(struct net *net,
const struct nf_conntrack_zone *zone,
@@ -2356,7 +2376,6 @@ ctnetlink_create_conntrack(struct net *net,
/* setup master conntrack: this is a confirmed expectation */
if (cda[CTA_TUPLE_MASTER]) {
struct nf_conntrack_tuple master;
- struct nf_conntrack_tuple_hash *master_h;
struct nf_conn *master_ct;
err = ctnetlink_parse_tuple(cda, &master, CTA_TUPLE_MASTER,
@@ -2364,12 +2383,11 @@ ctnetlink_create_conntrack(struct net *net,
if (err < 0)
goto err2;
- master_h = nf_conntrack_find_get(net, zone, &master);
- if (master_h == NULL) {
- err = -ENOENT;
+ master_ct = ctnetlink_find_get_master(net, zone, &master);
+ if (IS_ERR(master_ct)) {
+ err = PTR_ERR(master_ct);
goto err2;
}
- master_ct = nf_ct_tuplehash_to_ctrack(master_h);
__set_bit(IPS_EXPECTED_BIT, &ct->status);
ct->master = master_ct;
}
@@ -3613,7 +3631,6 @@ ctnetlink_create_expect(struct net *net,
u_int8_t u3, u32 portid, int report)
{
struct nf_conntrack_tuple tuple, mask, master_tuple;
- struct nf_conntrack_tuple_hash *h = NULL;
struct nf_conntrack_expect *exp;
struct nf_conn *ct;
int err;
@@ -3633,10 +3650,9 @@ ctnetlink_create_expect(struct net *net,
return err;
/* Look for master conntrack of this expectation */
- h = nf_conntrack_find_get(net, zone, &master_tuple);
- if (!h)
- return -ENOENT;
- ct = nf_ct_tuplehash_to_ctrack(h);
+ ct = ctnetlink_find_get_master(net, zone, &master_tuple);
+ if (IS_ERR(ct))
+ return PTR_ERR(ct);
rcu_read_lock();
exp = ctnetlink_alloc_expect(cda, ct, NULL, &tuple, &mask);
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 07/14] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (5 preceding siblings ...)
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 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 08/14] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
` (6 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Yiran Qiu <eritque-arcus@ikuyo.dev>
ct_seq_show() takes a reference on a conntrack it found by a lockless
walk of the hash table, but never checks that the conntrack is
confirmed. nf_conntrack is SLAB_TYPESAFE_BY_RCU, so between
ct_get_next() and refcount_inc_not_zero() the entry can be freed and
its slot reused by init_conntrack() for a new, unconfirmed conntrack.
The increment then succeeds and the dump prints a conntrack that is not
in any table. nf_ct_key_equal(), gc_worker_skip_ct() and early_drop()
reject unconfirmed entries for this reason.
Since commit 2ad9d7747c10 ("netfilter: conntrack: free extension area
immediately") this is also a use-after-free. An unconfirmed conntrack
can still grow its extension area, for example when an nft ct helper
object attaches a helper, and nf_ct_ext_add() then frees the old
ct->ext through krealloc(). seq_print_acct() and ct_show_delta_time()
read ct->ext without a lock, so the dump can read the freed buffer and
print what it finds there as counters or a time delta.
Skip entries that are not confirmed.
Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix
and this changelog were also drafted with LLM assistance. Reproduced
on a KASAN build of mainline (v7.4-rc3+) that carried timing counters
in ct_seq_show() (two ktime_get() per entry) but no added delay: an
unprivileged user in its own user and network namespace churns UDP
flows through an nft ct helper object while reading
/proc/net/nf_conntrack, and KASAN reported a slab-use-after-free in
ct_seq_show() after 9 and 41 minutes in two runs. The same build with
this patch ran the reproducer for 60 minutes with no report. With only
this patch applied to a KASAN build, the conntrack_resize.sh selftest,
which compares /proc/net/nf_conntrack with ctnetlink dumps, passed in
three runs.
Fixes: ea781f197d6a ("netfilter: nf_conntrack: use SLAB_DESTROY_BY_RCU and get rid of call_rcu()")
Cc: stable@vger.kernel.org
Signed-off-by: Yiran Qiu <eritque-arcus@ikuyo.dev>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_standalone.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index d88a10230862..299691d7ac1e 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -314,6 +314,9 @@ static int ct_seq_show(struct seq_file *s, void *v)
/* load ->status after refcount increase */
smp_acquire__after_ctrl_dep();
+ if (!nf_ct_is_confirmed(ct))
+ goto release;
+
if (nf_ct_should_gc(ct)) {
struct ct_iter_state *st = s->private;
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 08/14] netfilter: bridge: detach conntrack template on invalid IP frames
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (6 preceding siblings ...)
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 ` 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
` (5 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Luxiao Xu <rakukuip@gmail.com>
A bridge rule such as nftables `ct zone set` can attach a conntrack
template with IP_CT_NEW to an skb before nf_ct_bridge_pre() runs. When
a frame has an ETH_P_IP or ETH_P_IPV6 protocol, nf_ct_bridge_pre()
performs header pull, length trimming, and nf_ct_br_ip_check() /
nf_ct_br_ipv6_check() validation before invoking defragmentation and
nf_conntrack_in().
If any of those six checks fails, nf_ct_bridge_pre() returns NF_ACCEPT
immediately without passing the skb to nf_conntrack_in(), which would
normally clear skb->_nfct and drop the template reference on parse
failure. Because nft_ct_get_eval() evaluates NFT_CT_STATE from ct and
ctinfo before rejecting template objects, the retained template causes
malformed, truncated, or wrong-version IP frames to match `ct state new`
instead of `ct state invalid`.
Jump to a shared error path that calls nf_reset_ct(skb) before returning
NF_ACCEPT on all IPv4 and IPv6 header/length rejection paths so the
template reference is released and the frame is treated as invalid,
even on kernels without downstream template filtering in ct readers.
Fixes: 3c171f496ef5 ("netfilter: bridge: add connection tracking system")
Cc: stable@vger.kernel.org
Reported-by: VEGA <vega@nebusec.ai>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/3cf187b612fd78f8835fa9dad870326ce380f82f.1785479514.git.zhilinz@nebusec.ai
Signed-off-by: Luxiao Xu <rakukuip@gmail.com>
Signed-off-by: Ren Wei <weir@nebusec.ai>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/bridge/netfilter/nf_conntrack_bridge.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c
index 8c83dc05114b..11d6183fb11d 100644
--- a/net/bridge/netfilter/nf_conntrack_bridge.c
+++ b/net/bridge/netfilter/nf_conntrack_bridge.c
@@ -257,28 +257,28 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
switch (skb->protocol) {
case htons(ETH_P_IP):
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
- return NF_ACCEPT;
+ goto invalid;
len = skb_ip_totlen(skb);
if (pskb_trim_rcsum(skb, len))
- return NF_ACCEPT;
+ goto invalid;
if (nf_ct_br_ip_check(skb))
- return NF_ACCEPT;
+ goto invalid;
bridge_state.pf = NFPROTO_IPV4;
ret = nf_ct_br_defrag4(skb, &bridge_state);
break;
case htons(ETH_P_IPV6):
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
- return NF_ACCEPT;
+ goto invalid;
len = sizeof(struct ipv6hdr) + skb_ipv6_payload_len(skb);
if (pskb_trim_rcsum(skb, len))
- return NF_ACCEPT;
+ goto invalid;
if (nf_ct_br_ipv6_check(skb))
- return NF_ACCEPT;
+ goto invalid;
bridge_state.pf = NFPROTO_IPV6;
ret = nf_ct_br_defrag6(skb, &bridge_state);
@@ -293,6 +293,10 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
return ret;
return nf_conntrack_in(skb, &bridge_state);
+
+invalid:
+ nf_reset_ct(skb);
+ return NF_ACCEPT;
}
static unsigned int nf_ct_bridge_in(void *priv, struct sk_buff *skb,
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 09/14] netfilter: synproxy: fix double tsoff application in server ACK TSecr
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (7 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Florian Westphal <fw@strlen.de>
When SYNPROXY is active with timestamp options enabled, the handshake ACK
sent to the backend carries a TSecr that is off by synproxy->tsoff.
The code swaps tsval and tsecr before calling synproxy_send_server_ack().
The ACK is built with the correct TSecr (the server's TSval), but it
re-enters ipv4_synproxy_hook() on its way out, where
synproxy_tstamp_adjust() adds tsoff to TSecr a second time.
Since commit 3ba075278c11 ("tcp: be less liberal in TSEcr received while in
SYN_RECV state") Linux TCP performs stricter validation and such backends
will drops the ACK. This will delay connection establishment until the
server SYN-ACK retransmit, which may take a few seconds.
Replace the swap() by explicit initialisation of tsval/tsecr for both
the server and client ACKs. Build the server ACK with TSecr
pre-compensated (server TSval - tsoff), so that the adjustment on
re-entry yields the server's actual TSval.
Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target")
Reported-and-tested-by: Dominik Shaim Ulrich <info@openservis.cz>
Closes: https://lore.kernel.org/netfilter-devel/CAFvzkdAXBNAWcHFNo6akAo63Wd8B_jvhkt=AEmuLR9fgPBEfGg@mail.gmail.com/
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_synproxy_core.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index 9dd681596c70..559db2c972f8 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -661,6 +661,7 @@ ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
const struct ip_ct_tcp *state;
struct tcphdr *th, _th;
unsigned int thoff;
+ u32 tsval, tsecr;
ct = nf_ct_get(skb, &ctinfo);
if (!ct)
@@ -742,13 +743,18 @@ ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
NF_SYNPROXY_OPT_WSCALE |
NF_SYNPROXY_OPT_SACK_PERM);
- swap(opts.tsval, opts.tsecr);
+ tsval = opts.tsval;
+ tsecr = opts.tsecr;
+
+ opts.tsval = tsecr;
+ opts.tsecr = tsval - synproxy->tsoff;
synproxy_send_server_ack(net, state, skb, th, &opts);
nf_ct_seqadj_init(ct, ctinfo, synproxy->isn - ntohl(th->seq));
nf_conntrack_event_cache(IPCT_SEQADJ, ct);
- swap(opts.tsval, opts.tsecr);
+ opts.tsecr = tsecr;
+ opts.tsval = tsval;
synproxy_send_client_ack(net, skb, th, &opts);
consume_skb(skb);
@@ -1093,6 +1099,7 @@ ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
struct synproxy_options opts = {};
const struct ip_ct_tcp *state;
struct tcphdr *th, _th;
+ u32 tsval, tsecr;
__be16 frag_off;
u8 nexthdr;
int thoff;
@@ -1181,13 +1188,18 @@ ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
NF_SYNPROXY_OPT_WSCALE |
NF_SYNPROXY_OPT_SACK_PERM);
- swap(opts.tsval, opts.tsecr);
+ tsval = opts.tsval;
+ tsecr = opts.tsecr;
+
+ opts.tsval = tsecr;
+ opts.tsecr = tsval - synproxy->tsoff;
synproxy_send_server_ack_ipv6(net, state, skb, th, &opts);
nf_ct_seqadj_init(ct, ctinfo, synproxy->isn - ntohl(th->seq));
nf_conntrack_event_cache(IPCT_SEQADJ, ct);
- swap(opts.tsval, opts.tsecr);
+ opts.tsecr = tsecr;
+ opts.tsval = tsval;
synproxy_send_client_ack_ipv6(net, skb, th, &opts);
consume_skb(skb);
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 10/14] netfilter: nf_tables: only disable tables on a dormant transition
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (8 preceding siblings ...)
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 ` 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
` (3 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Ma Xinmeng <1564938642@qq.com>
nf_tables_commit() calls nf_tables_table_disable() for every NEWTABLE
transaction that has NFT_TABLE_F_DORMANT set and __NFT_TABLE_F_UPDATE.
Since table adoption introduced __NFT_TABLE_F_WAS_ORPHAN, UPDATE no
longer implies a dormant state change: re-owning an already dormant
PERSIST orphan sets UPDATE because of the adoption, even though the
table never left the dormant state. The commit then clears DORMANT,
walks the basechains, and unregisters a hook that was never registered,
which triggers WARN_ONCE("hook not found") in
__nf_unregister_net_hook().
Use __NFT_TABLE_F_WAS_AWAKEN, which records an awake-to-dormant
transition, instead of the current DORMANT flag. This skips the disable
for an already dormant adopted table while preserving the genuine
awake-to-dormant path.
Fixes: 31bf508be656 ("netfilter: nf_tables: Implement table adoption support")
Signed-off-by: Ma Xinmeng <1564938642@qq.com>
Reviewed-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 8b94b5e7dbdb..b184c739cb67 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -11078,7 +11078,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
nft_trans_destroy(trans);
break;
}
- if (table->flags & NFT_TABLE_F_DORMANT)
+ if (table->flags & __NFT_TABLE_F_WAS_AWAKEN)
nf_tables_table_disable(net, table);
table->flags &= ~__NFT_TABLE_F_UPDATE;
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 11/14] netfilter: nf_tables: add NFT_HOOK_UNREGISTERED and use it
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (9 preceding siblings ...)
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 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 12/14] netfilter: nf_tables: unbind flowtable on hook release Pablo Neira Ayuso
` (2 subsequent siblings)
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
Commit f9a43007d3f7 ("netfilter: nf_tables: double hook unregistration
in netns path") fixes a race in the netns exit path with netdev device
event handler. The netns pre_exit handler unregisters the hooks, then
exit release them. In between this two calls, the netdev event might
show up and try to unregister the hooks again. This patch revisit this
fix by adding a new NFT_HOOK_UNREGISTERED flag which allows us to skip
the hook from the netdevice and flowtable event handlers.
This patch is a prerequisit for another follow up fix for the flowtable
hardware offload which allows to unregister the flow_block once the
entries in hardware have been removed.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_tables.h | 3 +-
net/netfilter/nf_tables_api.c | 53 +++++++++++++++----------------
net/netfilter/nft_chain_filter.c | 6 ++--
3 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 9d597482363d..5edff5d7dacd 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -1209,7 +1209,8 @@ struct nft_stats {
struct u64_stats_sync syncp;
};
-#define NFT_HOOK_REMOVE (1 << 0)
+#define NFT_HOOK_REMOVE (1 << 0)
+#define NFT_HOOK_UNREGISTERED (1 << 1)
struct nft_hook {
struct list_head list;
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index b184c739cb67..c19cf6d8cd0b 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -329,6 +329,7 @@ static int nft_netdev_register_hooks(struct net *net,
j++;
}
+ hook->flags &= ~NFT_HOOK_UNREGISTERED;
}
return 0;
@@ -340,6 +341,7 @@ static int nft_netdev_register_hooks(struct net *net,
nf_unregister_net_hook(net, ops);
}
+ hook->flags |= NFT_HOOK_UNREGISTERED;
}
return err;
}
@@ -406,19 +408,17 @@ static void nft_netdev_unregister_trans_hook(struct net *net,
static void nft_netdev_unregister_hooks(struct net *net,
const struct nft_table *table,
- struct list_head *hook_list,
- bool release_netdev)
+ struct list_head *hook_list)
{
- struct nft_hook *hook, *next;
+ struct nft_hook *hook;
struct nf_hook_ops *ops;
- list_for_each_entry_safe(hook, next, hook_list, list) {
+ list_for_each_entry(hook, hook_list, list) {
if (!(table->flags & NFT_TABLE_F_DORMANT)) {
list_for_each_entry(ops, &hook->ops_list, list)
nf_unregister_net_hook(net, ops);
}
- if (release_netdev)
- nft_netdev_hook_unlink_free_rcu(hook);
+ hook->flags |= NFT_HOOK_UNREGISTERED;
}
}
@@ -447,8 +447,7 @@ static int nf_tables_register_hook(struct net *net,
static void __nf_tables_unregister_hook(struct net *net,
const struct nft_table *table,
- struct nft_chain *chain,
- bool release_netdev)
+ struct nft_chain *chain)
{
struct nft_base_chain *basechain;
const struct nf_hook_ops *ops;
@@ -460,8 +459,7 @@ static void __nf_tables_unregister_hook(struct net *net,
/* must also be called for dormant tables */
if (nft_base_chain_netdev(table->family, basechain->ops.hooknum)) {
- nft_netdev_unregister_hooks(net, table, &basechain->hook_list,
- release_netdev);
+ nft_netdev_unregister_hooks(net, table, &basechain->hook_list);
return;
}
@@ -478,7 +476,7 @@ static void nf_tables_unregister_hook(struct net *net,
const struct nft_table *table,
struct nft_chain *chain)
{
- return __nf_tables_unregister_hook(net, table, chain, false);
+ return __nf_tables_unregister_hook(net, table, chain);
}
static bool nft_trans_collapse_set_elem_allowed(const struct nft_trans_elem *a, const struct nft_trans_elem *b)
@@ -9038,8 +9036,7 @@ static void nft_unregister_flowtable_ops(struct net *net,
static void __nft_unregister_flowtable_net_hooks(struct net *net,
struct nft_flowtable *flowtable,
- struct list_head *hook_list,
- bool release_netdev)
+ struct list_head *hook_list)
{
struct nft_hook *hook, *next;
struct nf_hook_ops *ops;
@@ -9047,8 +9044,8 @@ static void __nft_unregister_flowtable_net_hooks(struct net *net,
list_for_each_entry_safe(hook, next, hook_list, list) {
list_for_each_entry(ops, &hook->ops_list, list)
nft_unregister_flowtable_ops(net, flowtable, ops);
- if (release_netdev)
- nft_netdev_hook_unlink_free_rcu(hook);
+
+ hook->flags |= NFT_HOOK_UNREGISTERED;
}
}
@@ -9056,7 +9053,7 @@ static void nft_unregister_flowtable_net_hooks(struct net *net,
struct nft_flowtable *flowtable,
struct list_head *hook_list)
{
- __nft_unregister_flowtable_net_hooks(net, flowtable, hook_list, false);
+ __nft_unregister_flowtable_net_hooks(net, flowtable, hook_list);
}
static int nft_register_flowtable_ops(struct net *net,
@@ -9833,8 +9830,10 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,
continue;
/* flow_offload_netdev_event() cleans up entries for us. */
- nft_unregister_flowtable_ops(dev_net(dev),
- flowtable, ops);
+ if (!(hook->flags & NFT_HOOK_UNREGISTERED)) {
+ nft_unregister_flowtable_ops(dev_net(dev),
+ flowtable, ops);
+ }
list_del_rcu(&ops->list);
kfree_rcu(ops, rcu);
break;
@@ -11291,10 +11290,13 @@ static void nf_tables_abort_release(struct nft_trans *trans)
nf_tables_table_destroy(trans->table);
break;
case NFT_MSG_NEWCHAIN:
- if (nft_trans_chain_update(trans))
+ if (nft_trans_chain_update(trans)) {
nft_hooks_destroy(&nft_trans_chain_hooks(trans));
- else
+ free_percpu(nft_trans_chain_stats(trans));
+ kfree(nft_trans_chain_name(trans));
+ } else {
nf_tables_chain_destroy(nft_trans_chain(trans));
+ }
break;
case NFT_MSG_NEWRULE:
nf_tables_rule_destroy(&ctx, nft_trans_rule(trans));
@@ -11383,11 +11385,7 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
case NFT_MSG_NEWCHAIN:
if (nft_trans_chain_update(trans)) {
nft_netdev_unregister_hooks(net, table,
- &nft_trans_chain_hooks(trans),
- true);
- free_percpu(nft_trans_chain_stats(trans));
- kfree(nft_trans_chain_name(trans));
- nft_trans_destroy(trans);
+ &nft_trans_chain_hooks(trans));
} else {
if (nft_trans_chain_bound(trans)) {
nft_trans_destroy(trans);
@@ -12048,11 +12046,10 @@ static void __nft_release_hook(struct net *net, struct nft_table *table)
struct nft_chain *chain;
list_for_each_entry(chain, &table->chains, list)
- __nf_tables_unregister_hook(net, table, chain, true);
+ __nf_tables_unregister_hook(net, table, chain);
list_for_each_entry(flowtable, &table->flowtables, list)
__nft_unregister_flowtable_net_hooks(net, flowtable,
- &flowtable->hook_list,
- true);
+ &flowtable->hook_list);
}
static void __nft_release_hooks(struct net *net)
diff --git a/net/netfilter/nft_chain_filter.c b/net/netfilter/nft_chain_filter.c
index e04e689f2228..ffbf5dad3139 100644
--- a/net/netfilter/nft_chain_filter.c
+++ b/net/netfilter/nft_chain_filter.c
@@ -337,7 +337,8 @@ static int nft_netdev_event(unsigned long event, struct net_device *dev,
if (!ops || (changename && match))
continue;
- if (!(table->flags & NFT_TABLE_F_DORMANT))
+ if (!(table->flags & NFT_TABLE_F_DORMANT) &&
+ !(hook->flags & NFT_HOOK_UNREGISTERED))
nf_unregister_net_hook(dev_net(dev), ops);
list_del_rcu(&ops->list);
@@ -356,7 +357,8 @@ static int nft_netdev_event(unsigned long event, struct net_device *dev,
ops->dev = dev;
- if (!(table->flags & NFT_TABLE_F_DORMANT) &&
+ if ((!(table->flags & NFT_TABLE_F_DORMANT) &&
+ !(hook->flags & NFT_HOOK_UNREGISTERED)) &&
nf_register_net_hook(dev_net(dev), ops)) {
kfree(ops);
return 1;
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 12/14] netfilter: nf_tables: unbind flowtable on hook release
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (10 preceding siblings ...)
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 ` 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
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
Commit 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable
binding") breaks hardware offload by unbinding the flow_block too early,
this results in leaving entries in the hardware. Any pending offload
work will be ignored because there is no flow_block anymore in place.
This patch restores the strategy followed by commit 5acab91458ce
("netfilter: nf_tables: unbind callbacks from flowtable destroy path")
by unregistering the hook first, then unbind the flow_block from the
error and destroy paths, right before the hook is released.
Fixes: 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 65 +++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 18 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index c19cf6d8cd0b..0189375e4063 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -380,6 +380,22 @@ static void nft_netdev_hook_unlink_free_rcu(struct nft_hook *hook)
nft_netdev_hook_free_rcu(hook);
}
+static void nft_flowtable_hook_unlink_free_rcu(struct nft_flowtable *flowtable,
+ struct nft_hook *hook)
+{
+ struct nf_hook_ops *ops;
+
+ /* This unbind command needs to come this late, otherwise offload
+ * worker finds no flow_block and entries are not cleaned up from
+ * hardware.
+ */
+ list_for_each_entry(ops, &hook->ops_list, list) {
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
+ }
+ nft_netdev_hook_unlink_free_rcu(hook);
+}
+
static void nft_trans_hook_destroy(struct nft_trans_hook *trans_hook)
{
list_del(&trans_hook->list);
@@ -9026,12 +9042,9 @@ nft_flowtable_type_get(struct net *net, u8 family)
/* Only called from error and netdev event paths. */
static void nft_unregister_flowtable_ops(struct net *net,
- struct nft_flowtable *flowtable,
struct nf_hook_ops *ops)
{
nf_unregister_net_hook(net, ops);
- flowtable->data.type->setup(&flowtable->data, ops->dev,
- FLOW_BLOCK_UNBIND);
}
static void __nft_unregister_flowtable_net_hooks(struct net *net,
@@ -9043,7 +9056,7 @@ static void __nft_unregister_flowtable_net_hooks(struct net *net,
list_for_each_entry_safe(hook, next, hook_list, list) {
list_for_each_entry(ops, &hook->ops_list, list)
- nft_unregister_flowtable_ops(net, flowtable, ops);
+ nft_unregister_flowtable_ops(net, ops);
hook->flags |= NFT_HOOK_UNREGISTERED;
}
@@ -9114,7 +9127,9 @@ static int nft_register_flowtable_net_hooks(struct net *net,
if (i-- <= 0)
break;
- nft_unregister_flowtable_ops(net, flowtable, ops);
+ nft_unregister_flowtable_ops(net, ops);
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
}
nft_netdev_hook_unlink_free_rcu(hook);
}
@@ -9141,9 +9156,9 @@ static void nft_flowtable_unregister_trans_hook(struct net *net,
list_for_each_entry_safe(trans_hook, next, hook_list, list) {
hook = trans_hook->hook;
list_for_each_entry(ops, &hook->ops_list, list)
- nft_unregister_flowtable_ops(net, flowtable, ops);
+ nft_unregister_flowtable_ops(net, ops);
- nft_netdev_hook_unlink_free_rcu(hook);
+ nft_flowtable_hook_unlink_free_rcu(flowtable, trans_hook->hook);
nft_trans_hook_destroy(trans_hook);
}
}
@@ -9229,9 +9244,11 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
err_flowtable_update_hook:
list_for_each_entry_safe(hook, next, &flowtable_hook.list, list) {
if (unregister) {
- list_for_each_entry(ops, &hook->ops_list, list)
- nft_unregister_flowtable_ops(ctx->net,
- flowtable, ops);
+ list_for_each_entry(ops, &hook->ops_list, list) {
+ nft_unregister_flowtable_ops(ctx->net, ops);
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
+ }
}
nft_netdev_hook_unlink_free_rcu(hook);
}
@@ -9752,10 +9769,19 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx,
nfnetlink_set_err(ctx->net, ctx->portid, NFNLGRP_NFTABLES, -ENOBUFS);
}
+static void nft_flowtable_hooks_destroy(struct nft_flowtable *flowtable,
+ struct list_head *hook_list)
+{
+ struct nft_hook *hook, *next;
+
+ list_for_each_entry_safe(hook, next, hook_list, list)
+ nft_flowtable_hook_unlink_free_rcu(flowtable, hook);
+}
+
static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable)
{
flowtable->data.type->free(&flowtable->data);
- nft_hooks_destroy(&flowtable->hook_list);
+ nft_flowtable_hooks_destroy(flowtable, &flowtable->hook_list);
kfree(flowtable->name);
module_put(flowtable->data.type->owner);
kfree(flowtable);
@@ -9830,10 +9856,11 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,
continue;
/* flow_offload_netdev_event() cleans up entries for us. */
- if (!(hook->flags & NFT_HOOK_UNREGISTERED)) {
- nft_unregister_flowtable_ops(dev_net(dev),
- flowtable, ops);
- }
+ if (!(hook->flags & NFT_HOOK_UNREGISTERED))
+ nft_unregister_flowtable_ops(dev_net(dev), ops);
+
+ flowtable->data.type->setup(&flowtable->data, ops->dev,
+ FLOW_BLOCK_UNBIND);
list_del_rcu(&ops->list);
kfree_rcu(ops, rcu);
break;
@@ -11311,10 +11338,12 @@ static void nf_tables_abort_release(struct nft_trans *trans)
nft_obj_destroy(&ctx, nft_trans_obj(trans));
break;
case NFT_MSG_NEWFLOWTABLE:
- if (nft_trans_flowtable_update(trans))
- nft_hooks_destroy(&nft_trans_flowtable_hooks(trans));
- else
+ if (nft_trans_flowtable_update(trans)) {
+ nft_flowtable_hooks_destroy(nft_trans_flowtable(trans),
+ &nft_trans_flowtable_hooks(trans));
+ } else {
nf_tables_flowtable_destroy(nft_trans_flowtable(trans));
+ }
break;
}
kfree(trans);
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 13/14] netfilter: nf_tables: flush destroy work from flowtable netdev event handler
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (11 preceding siblings ...)
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 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 14/14] netfilter: ipv6: stop the conntrack fragment search at AH Pablo Neira Ayuso
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
Sashiko reports that the following race is possible while dismantling
the flowtable with hardware offload:
CPU0 CPU1 (kworker)
nf_tables_commit()
list_del_rcu(&flowtable->list)
nft_unregister_flowtable_net_hooks()
nf_tables_commit_release()
schedule_work(&destroy_work)
mutex_unlock(&commit_mutex)
nf_tables_trans_destroy_work()
synchronize_rcu()
...
unregister_netdevice()
nf_tables_flowtable_event()
/* flowtable not in
* table->flowtables, ops->dev
* stays on flowtable->hook_list
*/
free_netdev(dev)
nf_tables_flowtable_destroy()
nft_flowtable_hooks_destroy()
...
flowtable->data.type->setup(
..., ops->dev,
FLOW_BLOCK_UNBIND)
<-- use-after-free
A netdevice event could happen in between the commit and commit_release.
After commit, the flowtable has been removed from the table list,
therefore, it is not reachable by the flowtable netdevice handler so the
hook cannot be unregistered and a stale reference to the netdevice
remains in place, leading to possible UaF from the commit_release path
when accessing the netdevice.
Fix this by flushing the pending destroy work before handling netdevice
events.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 0189375e4063..9ea8789f5664 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -9929,6 +9929,8 @@ static int nf_tables_flowtable_event(struct notifier_block *this,
nft_net = nft_pernet(net);
mutex_lock(&nft_net->commit_mutex);
+ nf_tables_trans_destroy_flush_work(net);
+
if (event == NETDEV_CHANGENAME) {
if (__nf_tables_flowtable_event(NETDEV_REGISTER, dev, true)) {
ret = NOTIFY_BAD;
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH net 14/14] netfilter: ipv6: stop the conntrack fragment search at AH
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
` (12 preceding siblings ...)
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 ` Pablo Neira Ayuso
13 siblings, 0 replies; 28+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-29 0:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, horms, fw, ja
From: Ryosuke Iwahashi <ryosuke@ikotaslabs.com>
find_prev_fhdr() looks beyond an IPv6 Authentication Header (AH) for a
Fragment header. Reassembly there can change data covered by AH before
IPv6 input processes AH.
Stop the search at AH. Conntrack still reassembles fragments when the
Fragment header precedes AH.
Fixes: 6aafeef03b9d ("netfilter: push reasm skb through instead of original frag skbs")
Signed-off-by: Ryosuke Iwahashi <ryosuke@ikotaslabs.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/ipv6/netfilter/nf_conntrack_reasm.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index f25ff2a12a82..893b250b99f9 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -410,9 +410,9 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
struct ipv6_opt_hdr hdr;
int hdrlen;
- if (!ipv6_ext_hdr(nexthdr)) {
+ /* Leave headers beyond AH for the authenticated input path. */
+ if (!ipv6_ext_hdr(nexthdr) || nexthdr == NEXTHDR_AUTH)
return -1;
- }
if (nexthdr == NEXTHDR_NONE) {
pr_debug("next header is none\n");
return -1;
@@ -423,10 +423,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
}
if (skb_copy_bits(skb, start, &hdr, sizeof(hdr)))
return -1;
- if (nexthdr == NEXTHDR_AUTH)
- hdrlen = ipv6_authlen(&hdr);
- else
- hdrlen = ipv6_optlen(&hdr);
+ hdrlen = ipv6_optlen(&hdr);
prevhdr = nexthdr;
prev_nhoff = start;
--
2.47.3
^ permalink raw reply related [flat|nested] 28+ messages in thread