Commit df0a30d7 authored by Luo Gengkun's avatar Luo Gengkun Committed by openeuler-sync-bot
Browse files

netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path

mainline inclusion
from mainline-v6.9-rc3
commit 0d459e2ffb541841714839e8228b845458ed3b27
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9JFG3
CVE: CVE-2024-26925

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0d459e2ffb541841714839e8228b845458ed3b27



--------------------------------

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: 72034434 ("netfilter: nf_tables: GC transaction race with abort path")
Reported-by: default avatarKuan-Ting Chen <hexrabbit@devco.re>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>

Conflicts:
		net/netfilter/nf_tables_api.c

Signed-off-by: default avatarLuo Gengkun <luogengkun2@huawei.com>
(cherry picked from commit 027b4085)
parent 5bde6558
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -8591,11 +8591,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 0;
}

@@ -8610,6 +8605,14 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb,
	struct nftables_pernet *nft_net = net_generic(net, nf_tables_net_id);
	int ret = __nf_tables_abort(net, action);

	/* 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;