* [PATCH nf v2 1/2] netfilter: nf_tables: only disable tables on a dormant transition
[not found] <20261117161520.1031-1-1564938642@qq.com>
@ 2026-11-17 16:14 ` Ma Xinmeng
2026-11-17 16:14 ` [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table Ma Xinmeng
1 sibling, 0 replies; 3+ messages in thread
From: Ma Xinmeng @ 2026-11-17 16:14 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal; +Cc: netfilter-devel, netdev, Phil Sutter
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>
---
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 8b94b5e7d..b184c739c 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.56.0.windows.4.niugit
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table
[not found] <20261117161520.1031-1-1564938642@qq.com>
2026-11-17 16:14 ` [PATCH nf v2 1/2] netfilter: nf_tables: only disable tables on a dormant transition Ma Xinmeng
@ 2026-11-17 16:14 ` Ma Xinmeng
2026-11-17 16:37 ` Florian Westphal
1 sibling, 1 reply; 3+ messages in thread
From: Ma Xinmeng @ 2026-11-17 16:14 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal; +Cc: netfilter-devel, netdev, Phil Sutter
Add a regression test for the nftables table-adoption path. The test
creates a dormant PERSIST OWNER table, lets the owning nft process exit
so the table becomes an orphan, adds a basechain while the table is still
dormant, and re-owns the orphan.
On the buggy tree this calls nf_tables_table_disable() and unregisters a
hook that was never registered, which triggers WARN_ONCE("hook not
found") and taints the kernel. The test checks the taint state so it
fails on the unfixed kernel and passes once the commit path only
disables a table on a real awake-to-dormant transition.
Signed-off-by: Ma Xinmeng <1564938642@qq.com>
---
.../testing/selftests/net/netfilter/Makefile | 1 +
.../net/netfilter/nft_table_dormant_adopt.sh | 57 +++++++++++++++++++
2 files changed, 58 insertions(+)
create mode 100755 tools/testing/selftests/net/netfilter/nft_table_dormant_adopt.sh
diff --git a/tools/testing/selftests/net/netfilter/Makefile b/tools/testing/selftests/net/netfilter/Makefile
index df3c20c90..3ca562a0a 100644
--- a/tools/testing/selftests/net/netfilter/Makefile
+++ b/tools/testing/selftests/net/netfilter/Makefile
@@ -37,6 +37,7 @@ TEST_PROGS := \
nft_offload.sh \
nft_queue.sh \
nft_synproxy.sh \
+ nft_table_dormant_adopt.sh \
nft_tproxy_tcp.sh \
nft_tproxy_udp.sh \
nft_zones_many.sh \
diff --git a/tools/testing/selftests/net/netfilter/nft_table_dormant_adopt.sh b/tools/testing/selftests/net/netfilter/nft_table_dormant_adopt.sh
new file mode 100755
index 000000000..b1e1bb4fe
--- /dev/null
+++ b/tools/testing/selftests/net/netfilter/nft_table_dormant_adopt.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Re-owning an already dormant PERSIST table used to call
+# nf_tables_table_disable() from nf_tables_commit(), which unregistered a
+# basechain hook that was never registered and triggered
+# WARN_ONCE("hook not found") in __nf_unregister_net_hook().
+#
+# The WARN taints the kernel, so this test checks the taint state instead
+# of parsing dmesg.
+
+source "$(dirname "$0")/lib.sh"
+
+checktool "nft --version" "run nft"
+
+if [ "$(id -u)" -ne 0 ]; then
+ echo "SKIP: root is required to create an owner table"
+ exit $ksft_skip
+fi
+
+read t < /proc/sys/kernel/tainted
+if [ "$t" -ne 0 ]; then
+ echo "SKIP: kernel is already tainted"
+ exit $ksft_skip
+fi
+
+cleanup()
+{
+ nft delete table ip nft_dormant_rt 2>/dev/null || true
+}
+trap cleanup EXIT
+
+nft delete table ip nft_dormant_rt 2>/dev/null || true
+
+# The nft process exits after this command, leaving a dormant PERSIST
+# orphan table behind.
+if ! nft add table ip nft_dormant_rt '{ flags dormant,persist,owner; }'; then
+ echo "SKIP: nft does not support table owner/persist flags"
+ exit $ksft_skip
+fi
+
+# A basechain added while the table is dormant does not register its hook.
+nft add chain ip nft_dormant_rt c '{ type filter hook output priority 0; }' || exit 1
+
+# Re-own the orphan with DORMANT still set. On the buggy tree this calls
+# nf_tables_table_disable() and unregisters the never-registered hook.
+nft add table ip nft_dormant_rt '{ flags dormant,persist,owner; }' || exit 1
+
+read t < /proc/sys/kernel/tainted
+if [ "$t" -ne 0 ]; then
+ echo "FAIL: re-owning an already dormant table tainted the kernel"
+ dmesg | tail -n 20
+ exit 1
+fi
+
+echo "PASS"
+exit 0
--
2.56.0.windows.4.niugit
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table
2026-11-17 16:14 ` [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table Ma Xinmeng
@ 2026-11-17 16:37 ` Florian Westphal
0 siblings, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2026-11-17 16:37 UTC (permalink / raw)
To: Ma Xinmeng; +Cc: Pablo Neira Ayuso, netfilter-devel, netdev, Phil Sutter
Ma Xinmeng <1564938642@qq.com> wrote:
> Add a regression test for the nftables table-adoption path. The test
> creates a dormant PERSIST OWNER table, lets the owning nft process exit
> so the table becomes an orphan, adds a basechain while the table is still
> dormant, and re-owns the orphan.
>
> On the buggy tree this calls nf_tables_table_disable() and unregisters a
> hook that was never registered, which triggers WARN_ONCE("hook not
> found") and taints the kernel. The test checks the taint state so it
> fails on the unfixed kernel and passes once the commit path only
> disables a table on a real awake-to-dormant transition.
Would you mind reworking this so we can place it in the nftables.git
shell tests?
tests/shell/testcases/transactions/ would be a good place, I think.
The test would be a bit simpler since nftables run-tests.sh already
does 'tainted kernel' checks, so it only needs the 'add table', 'add
chain', 'add table' sequence.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 16:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261117161520.1031-1-1564938642@qq.com>
2026-11-17 16:14 ` [PATCH nf v2 1/2] netfilter: nf_tables: only disable tables on a dormant transition Ma Xinmeng
2026-11-17 16:14 ` [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table Ma Xinmeng
2026-11-17 16:37 ` Florian Westphal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox