]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 8 Apr 2024 21:20:41 +0000 (23:20 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Apr 2024 10:59:54 +0000 (12:59 +0200)
commit 0d459e2ffb541841714839e8228b845458ed3b27 upstream.

The commit mutex should not be released during the critical section
between nft_gc_seq_begin() and nft_gc_seq_end(), otherwise, async GC
worker could collect expired objects and get the released commit lock
within the same GC sequence.

nf_tables_module_autoload() temporarily releases the mutex to load
module dependencies, then it goes back to replay the transaction again.
Move it at the end of the abort phase after nft_gc_seq_end() is called.

Cc: stable@vger.kernel.org
Fixes: 720344340fb9 ("netfilter: nf_tables: GC transaction race with abort path")
Reported-by: Kuan-Ting Chen <hexrabbit@devco.re>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nf_tables_api.c

index 6c5de620da9f1d8988a0549a2ed2e53945e7e8e4..ef271628975a9c75e1b43dc53cc45de74c14ac7d 100644 (file)
@@ -8964,11 +8964,6 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
                nf_tables_abort_release(trans);
        }
 
-       if (action == NFNL_ABORT_AUTOLOAD)
-               nf_tables_module_autoload(net);
-       else
-               nf_tables_module_autoload_cleanup(net);
-
        return err;
 }
 
@@ -8985,6 +8980,14 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb,
 
        WARN_ON_ONCE(!list_empty(&nft_net->commit_list));
 
+       /* module autoload needs to happen after GC sequence update because it
+        * temporarily releases and grabs mutex again.
+        */
+       if (action == NFNL_ABORT_AUTOLOAD)
+               nf_tables_module_autoload(net);
+       else
+               nf_tables_module_autoload_cleanup(net);
+
        mutex_unlock(&nft_net->commit_mutex);
 
        return ret;