All of lore.kernel.org
 help / color / mirror / Atom feed
* [nf PATCH] netfilter: nf_tables: Fix for deleting base chains with payload
@ 2023-06-16 15:56 Phil Sutter
  2023-06-18 14:59 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Sutter @ 2023-06-16 15:56 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

When deleting a base chain, iptables-nft simply submits the whole chain
to the kernel, including the NFTA_CHAIN_HOOK attribute. The new code
added by fixed commit then turned this into a chain update, destroying
the hook but not the chain itself.

Detect the situation by checking if the chain's hook list becomes empty
after removing all submitted hooks from it. A base chain without hooks
is pointless, so revert back to deleting the chain.

Note the 'goto err_chain_del_hook', error path takes care of undoing the
hook_list modification and releasing the unused chain_hook.

Fixes: 7d937b107108f ("netfilter: nf_tables: support for deleting devices in an existing netdev chain")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 net/netfilter/nf_tables_api.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 477c39358da7d..9666c8e891fa7 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2699,6 +2699,11 @@ static int nft_delchain_hook(struct nft_ctx *ctx, struct nft_chain *chain,
 		list_move(&hook->list, &chain_del_list);
 	}
 
+	if (list_empty(&basechain->hook_list)) {
+		err = nft_delchain(ctx);
+		goto err_chain_del_hook;
+	}
+
 	trans = nft_trans_alloc(ctx, NFT_MSG_DELCHAIN,
 				sizeof(struct nft_trans_chain));
 	if (!trans) {
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-20 14:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-16 15:56 [nf PATCH] netfilter: nf_tables: Fix for deleting base chains with payload Phil Sutter
2023-06-18 14:59 ` Pablo Neira Ayuso
2023-06-19  8:55   ` Pablo Neira Ayuso
2023-06-19  8:58     ` Pablo Neira Ayuso
2023-06-20 14:15       ` Phil Sutter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.