From: Ma Xinmeng <1564938642@qq.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>, Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,
Phil Sutter <phil@nwl.cc>
Subject: [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table
Date: Wed, 18 Nov 2026 00:14:58 +0800 [thread overview]
Message-ID: <tencent_65062E982D816637E41FE6F24B678214DF09@qq.com> (raw)
In-Reply-To: <20261117161520.1031-1-1564938642@qq.com>
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
prev parent reply other threads:[~2026-11-17 16:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_65062E982D816637E41FE6F24B678214DF09@qq.com \
--to=1564938642@qq.com \
--cc=fw@strlen.de \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox