diff mbox series

[net,1/6] netfilter: nf_tables: release batch on table validation from abort path

Message ID 20240404104334.1627-2-pablo@netfilter.org
State Accepted
Headers show
Series [net,1/6] netfilter: nf_tables: release batch on table validation from abort path | expand

Commit Message

Pablo Neira Ayuso April 4, 2024, 10:43 a.m. UTC
Unlike early commit path stage which triggers a call to abort, an
explicit release of the batch is required on abort, otherwise mutex is
released and commit_list remains in place.

Add WARN_ON_ONCE to ensure commit_list is empty from the abort path
before releasing the mutex.

After this patch, commit_list is always assumed to be empty before
grabbing the mutex, therefore

  03c1f1ef1584 ("netfilter: Cleanup nft_net->module_list from nf_tables_exit_net()")

only needs to release the pending modules for registration.

Cc: stable@vger.kernel.org
Fixes: c0391b6ab810 ("netfilter: nf_tables: missing validation from the abort path")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org April 4, 2024, 4:50 p.m. UTC | #1
Hello:

This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <pablo@netfilter.org>:

On Thu,  4 Apr 2024 12:43:29 +0200 you wrote:
> Unlike early commit path stage which triggers a call to abort, an
> explicit release of the batch is required on abort, otherwise mutex is
> released and commit_list remains in place.
> 
> Add WARN_ON_ONCE to ensure commit_list is empty from the abort path
> before releasing the mutex.
> 
> [...]

Here is the summary with links:
  - [net,1/6] netfilter: nf_tables: release batch on table validation from abort path
    https://git.kernel.org/netdev/net/c/a45e6889575c
  - [net,2/6] netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path
    https://git.kernel.org/netdev/net/c/0d459e2ffb54
  - [net,3/6] netfilter: nf_tables: flush pending destroy work before exit_net release
    https://git.kernel.org/netdev/net/c/24cea9677025
  - [net,4/6] netfilter: nf_tables: reject new basechain after table flag update
    https://git.kernel.org/netdev/net/c/994209ddf4f4
  - [net,5/6] netfilter: nf_tables: Fix potential data-race in __nft_flowtable_type_get()
    https://git.kernel.org/netdev/net/c/24225011d81b
  - [net,6/6] netfilter: nf_tables: discard table flag update with pending basechain deletion
    https://git.kernel.org/netdev/net/c/1bc83a019bbe

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index fd86f2720c9e..ffcd3213c335 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -10455,10 +10455,11 @@  static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
 	struct nft_trans *trans, *next;
 	LIST_HEAD(set_update_list);
 	struct nft_trans_elem *te;
+	int err = 0;
 
 	if (action == NFNL_ABORT_VALIDATE &&
 	    nf_tables_validate(net) < 0)
-		return -EAGAIN;
+		err = -EAGAIN;
 
 	list_for_each_entry_safe_reverse(trans, next, &nft_net->commit_list,
 					 list) {
@@ -10655,7 +10656,7 @@  static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
 	else
 		nf_tables_module_autoload_cleanup(net);
 
-	return 0;
+	return err;
 }
 
 static int nf_tables_abort(struct net *net, struct sk_buff *skb,
@@ -10668,6 +10669,9 @@  static int nf_tables_abort(struct net *net, struct sk_buff *skb,
 	gc_seq = nft_gc_seq_begin(nft_net);
 	ret = __nf_tables_abort(net, action);
 	nft_gc_seq_end(nft_net, gc_seq);
+
+	WARN_ON_ONCE(!list_empty(&nft_net->commit_list));
+
 	mutex_unlock(&nft_net->commit_mutex);
 
 	return ret;
@@ -11473,9 +11477,10 @@  static void __net_exit nf_tables_exit_net(struct net *net)
 
 	gc_seq = nft_gc_seq_begin(nft_net);
 
-	if (!list_empty(&nft_net->commit_list) ||
-	    !list_empty(&nft_net->module_list))
-		__nf_tables_abort(net, NFNL_ABORT_NONE);
+	WARN_ON_ONCE(!list_empty(&nft_net->commit_list));
+
+	if (!list_empty(&nft_net->module_list))
+		nf_tables_module_autoload_cleanup(net);
 
 	__nft_release_tables(net);