Skip to contentSkip to conversation

netfilter: nf_tables: only disable tables on a dormant transition

PATCH Superseded Ma Xinmeng 3 participants 4 messages Nov 17 – Nov 18 1 message not in the archive

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ma Xinmeng

author
#1 lore raw

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.

Fixes 31bf508be656 ("netfilter: nf_tables: Implement table adoption support")
---
 net/netfilter/nf_tables_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
index 8b94b5e7d..b184c739c 100644
@@ -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
Reviewed-by on v2 1/2
#2 lore raw
Quoted 10 lines · On 2026/11/18 at 1:14 Ma Xinmeng wrote:

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().

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")

The patch looks good to me.

Thanks,
Xuanqiang

author
#3 lore raw

PATCH v2 2/2 selftests: netfilter: test re-owning an already dormant table

In reply to a message not in the archive

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.

---
 .../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
index df3c20c90..3ca562a0a 100644
@@ -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
maintainer
#4 lore raw

Re: [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 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.