* [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered
@ 2026-11-17 8:54 Ma Xinmeng
2026-11-17 9:03 ` netdev-bot+sinfo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ma Xinmeng @ 2026-11-17 8:54 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal; +Cc: netfilter-devel, netdev, Phil Sutter
A basechain created while its table is dormant is accepted without
registering its hook. Re-owning a PERSIST orphan table with DORMANT set
then makes nf_tables_table_disable() clear DORMANT before
nft_table_disable() walks the chains, so __nf_tables_unregister_hook()
no longer sees the dormant state and calls nf_unregister_net_hook() for a
hook that was never registered. This triggers WARN_ONCE("hook not found")
in __nf_unregister_net_hook().
Track whether a basechain's hook was actually registered and skip the
unregister for chains whose hook was never registered. This preserves the
existing "add a basechain to a dormant table" API.
Signed-off-by: Ma Xinmeng <1564938642@qq.com>
---
include/net/netfilter/nf_tables.h | 1 +
net/netfilter/nf_tables_api.c | 29 +++++++++++++++++++++++------
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 9d5974823..fcd24502b 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -1243,6 +1243,7 @@ struct nft_base_chain {
const struct nft_chain_type *type;
u8 policy;
u8 flags;
+ bool registered;
struct nft_stats __percpu *stats;
struct nft_chain chain;
struct flow_block flow_block;
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 8b94b5e7d..25b4075c9 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -428,21 +428,30 @@ static int nf_tables_register_hook(struct net *net,
{
struct nft_base_chain *basechain;
const struct nf_hook_ops *ops;
+ int err;
if (table->flags & NFT_TABLE_F_DORMANT ||
!nft_is_base_chain(chain))
return 0;
basechain = nft_base_chain(chain);
+ if (basechain->registered)
+ return 0;
+
ops = &basechain->ops;
if (basechain->type->ops_register)
- return basechain->type->ops_register(net, ops);
+ err = basechain->type->ops_register(net, ops);
+ else if (nft_base_chain_netdev(table->family, basechain->ops.hooknum))
+ err = nft_netdev_register_hooks(net, &basechain->hook_list);
+ else
+ err = nf_register_net_hook(net, &basechain->ops);
- if (nft_base_chain_netdev(table->family, basechain->ops.hooknum))
- return nft_netdev_register_hooks(net, &basechain->hook_list);
+ if (err < 0)
+ return err;
- return nf_register_net_hook(net, &basechain->ops);
+ basechain->registered = true;
+ return 0;
}
static void __nf_tables_unregister_hook(struct net *net,
@@ -456,22 +465,30 @@ static void __nf_tables_unregister_hook(struct net *net,
if (!nft_is_base_chain(chain))
return;
basechain = nft_base_chain(chain);
+ if (!basechain->registered)
+ return;
+
ops = &basechain->ops;
/* 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);
+ basechain->registered = false;
return;
}
if (table->flags & NFT_TABLE_F_DORMANT)
return;
- if (basechain->type->ops_unregister)
- return basechain->type->ops_unregister(net, ops);
+ if (basechain->type->ops_unregister) {
+ basechain->type->ops_unregister(net, ops);
+ basechain->registered = false;
+ return;
+ }
nf_unregister_net_hook(net, &basechain->ops);
+ basechain->registered = false;
}
static void nf_tables_unregister_hook(struct net *net,
--
2.56.0.windows.4.niugit
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered
2026-11-17 8:54 [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered Ma Xinmeng
@ 2026-11-17 9:03 ` netdev-bot+sinfo
2026-11-17 9:21 ` Ma Xinmeng
2026-11-17 10:21 ` Xuanqiang Luo
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-17 9:03 UTC (permalink / raw)
To: Ma Xinmeng
Cc: Pablo Neira Ayuso, Florian Westphal, netfilter-devel, netdev,
Phil Sutter
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] 4+ messages in thread
* Re: [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered
2026-11-17 8:54 [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered Ma Xinmeng
2026-11-17 9:03 ` netdev-bot+sinfo
@ 2026-11-17 9:21 ` Ma Xinmeng
2026-11-17 10:21 ` Xuanqiang Luo
2 siblings, 0 replies; 4+ messages in thread
From: Ma Xinmeng @ 2026-11-17 9:21 UTC (permalink / raw)
To: pablo, fw; +Cc: netfilter-devel, netdev, phil
Hi,
This issue was found by FuzzAnything's AI-assisted kernel fuzzer while
fuzzing nftables netlink messages in a user and network namespace. I
reduced the sequence to a standalone raw-netlink C PoC and checked the
mechanism against the kernel source.
I triggered the WARN at runtime on Linux 7.3.0-rc4, 7.3.1, 7.4-rc1,
7.4-rc2, and 7.4-rc3. The baseline stack from 7.4.0-rc3-c027test #4
(the signature is the same on the other versions) is:
hook not found, pf 2 num 3
WARNING: net/netfilter/core.c:522 at __nf_unregister_net_hook+0x71/0x1b0, CPU#0: repro_c027470f/1087
CPU: 0 UID: 0 PID: 1087 Comm: repro_c027470f Not tainted 7.4.0-rc3-c027test #4
Call Trace:
nft_table_disable+0x78/0xa0
nf_tables_commit+0x1c03/0x1ec0
nfnetlink_rcv_batch+0x939/0xaf0
nfnetlink_rcv+0x190/0x1b0
The sequence uses only valid nftables netlink messages: create a table
with DORMANT|PERSIST|OWNER, close the owning socket (PERSIST clears OWNER
but keeps the dormant table), add an IPv4 basechain while the table is
dormant (its hook is not registered), then re-own the orphan with
DORMANT|PERSIST|OWNER. On commit, nf_tables_table_disable() clears
DORMANT before walking the basechains. __nf_tables_unregister_hook()
then bypasses its dormant guard and calls nf_unregister_net_hook() for a
hook that was never registered. This is WARN-only; with
panic_on_warn=1 it becomes a local DoS.
After applying the candidate patch to 7.4-rc3, the same PoC returns 0
and dmesg has no WARN. The A/B test also passed on 7.3.1 and 7.4-rc2.
Thanks,
Ma Xinmeng
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered
2026-11-17 8:54 [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered Ma Xinmeng
2026-11-17 9:03 ` netdev-bot+sinfo
2026-11-17 9:21 ` Ma Xinmeng
@ 2026-11-17 10:21 ` Xuanqiang Luo
2 siblings, 0 replies; 4+ messages in thread
From: Xuanqiang Luo @ 2026-11-17 10:21 UTC (permalink / raw)
To: Ma Xinmeng
Cc: netfilter-devel, netdev, Phil Sutter, Pablo Neira Ayuso,
Florian Westphal
On 2026/11/17 at 17:54 Ma Xinmeng wrote:
> A basechain created while its table is dormant is accepted without
> registering its hook. Re-owning a PERSIST orphan table with DORMANT set
> then makes nf_tables_table_disable() clear DORMANT before
> nft_table_disable() walks the chains, so __nf_tables_unregister_hook()
> no longer sees the dormant state and calls nf_unregister_net_hook() for a
> hook that was never registered. This triggers WARN_ONCE("hook not found")
> in __nf_unregister_net_hook().
>
> Track whether a basechain's hook was actually registered and skip the
> unregister for chains whose hook was never registered. This preserves the
> existing "add a basechain to a dormant table" API.
>
> Signed-off-by: Ma Xinmeng <1564938642@qq.com>
> ---
> include/net/netfilter/nf_tables.h | 1 +
> net/netfilter/nf_tables_api.c | 29 +++++++++++++++++++++++------
> 2 files changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
> index 9d5974823..fcd24502b 100644
> --- a/include/net/netfilter/nf_tables.h
> +++ b/include/net/netfilter/nf_tables.h
> @@ -1243,6 +1243,7 @@ struct nft_base_chain {
> const struct nft_chain_type *type;
> u8 policy;
> u8 flags;
> + bool registered;
> struct nft_stats __percpu *stats;
> struct nft_chain chain;
> struct flow_block flow_block;
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index 8b94b5e7d..25b4075c9 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -428,21 +428,30 @@ static int nf_tables_register_hook(struct net *net,
> {
> struct nft_base_chain *basechain;
> const struct nf_hook_ops *ops;
> + int err;
>
> if (table->flags & NFT_TABLE_F_DORMANT ||
> !nft_is_base_chain(chain))
> return 0;
>
> basechain = nft_base_chain(chain);
> + if (basechain->registered)
> + return 0;
> +
> ops = &basechain->ops;
>
> if (basechain->type->ops_register)
> - return basechain->type->ops_register(net, ops);
> + err = basechain->type->ops_register(net, ops);
> + else if (nft_base_chain_netdev(table->family, basechain->ops.hooknum))
> + err = nft_netdev_register_hooks(net, &basechain->hook_list);
> + else
> + err = nf_register_net_hook(net, &basechain->ops);
>
> - if (nft_base_chain_netdev(table->family, basechain->ops.hooknum))
> - return nft_netdev_register_hooks(net, &basechain->hook_list);
> + if (err < 0)
> + return err;
>
> - return nf_register_net_hook(net, &basechain->ops);
> + basechain->registered = true;
> + return 0;
> }
>
> static void __nf_tables_unregister_hook(struct net *net,
> @@ -456,22 +465,30 @@ static void __nf_tables_unregister_hook(struct net *net,
> if (!nft_is_base_chain(chain))
> return;
> basechain = nft_base_chain(chain);
> + if (!basechain->registered)
> + return;
> +
> ops = &basechain->ops;
>
> /* 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);
> + basechain->registered = false;
> return;
> }
>
> if (table->flags & NFT_TABLE_F_DORMANT)
> return;
>
> - if (basechain->type->ops_unregister)
> - return basechain->type->ops_unregister(net, ops);
> + if (basechain->type->ops_unregister) {
> + basechain->type->ops_unregister(net, ops);
> + basechain->registered = false;
> + return;
> + }
>
> nf_unregister_net_hook(net, &basechain->ops);
> + basechain->registered = false;
> }
>
> static void nf_tables_unregister_hook(struct net *net,
Thanks for the report, the trigger is clear.
I do not think we need a new field for this.
A dormant table never has any basechain hook registered. The real
problem is that nf_tables_commit() calls nf_tables_table_disable() for
a table that was already dormant.
Since table adoption added __NFT_TABLE_F_WAS_ORPHAN, having
__NFT_TABLE_F_UPDATE set no longer implies a dormant state change.
Could we instead check __NFT_TABLE_F_WAS_AWAKEN, which records an
awake-to-dormant transition? This also covers adoption combined with
such a transition.
Untested, but something like:
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ nf_tables_commit()
case NFT_MSG_NEWTABLE:
...
- if (table->flags & NFT_TABLE_F_DORMANT)
+ if (table->flags & __NFT_TABLE_F_WAS_AWAKEN)
nf_tables_table_disable(net,
table);
Also:
- Please add
Fixes: 31bf508be656 ("netfilter: nf_tables: Implement table adoption
support")
- netfilter fixes go through the nf tree: use [PATCH nf].
- A selftest in tools/testing/selftests/net/netfilter/ would be nice.
Thanks,
Xuanqiang
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-17 10:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 8:54 [PATCH net] netfilter: nf_tables: don't unregister hooks that were never registered Ma Xinmeng
2026-11-17 9:03 ` netdev-bot+sinfo
2026-11-17 9:21 ` Ma Xinmeng
2026-11-17 10:21 ` Xuanqiang Luo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox