netfilter: nf_tables: only disable tables on a dormant transition
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/2 netfilter: nf_tables: only disable tables on a dormant transition
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.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -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;
Signature · 1 line
2.56.0.windows.4.niugit
Quoted 10 lines · On 2026/11/18 at 1:14 Ma Xinmeng wrote:
nf_tables_commit()callsnf_tables_table_disable()for every NEWTABLE transaction that hasNFT_TABLE_F_DORMANTset 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 triggersWARN_ONCE("hook not found")in__nf_unregister_net_hook().
Quoted 7 lines
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 <[email protected]>
The patch looks good to me.
Thanks,
Xuanqiang
PATCH v2 2/2 selftests: netfilter: test re-owning an already dormant table
In reply to a message not in the archiveAdd 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.
--- .../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
tools/testing/selftests/net/netfilter/Makefile +1 -0
@@ -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 \
tools/testing/selftests/net/netfilter/nft_table_dormant_adopt.sh new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.56.0.windows.4.niugit
Florian Westphal
maintainerRe: [PATCH nf v2 2/2] selftests: netfilter: test re-owning an already dormant table
Quoted 10 lines · Ma Xinmeng
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 triggersWARN_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.