Skip to content

Commit d9a8f26

Browse files
committed
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
jira VULN-4905 cve CVE-2024-27020 commit-author Ziyang Xuan <[email protected]> commit f969eb8 nft_unregister_expr() can concurrent with __nft_expr_type_get(), and there is not any protection when iterate over nf_tables_expressions list in __nft_expr_type_get(). Therefore, there is potential data-race of nf_tables_expressions list entry. Use list_for_each_entry_rcu() to iterate over nf_tables_expressions list in __nft_expr_type_get(), and use rcu_read_lock() in the caller nft_expr_type_get() to protect the entire type query process. Fixes: ef1f7df ("netfilter: nf_tables: expression ops overloading") Signed-off-by: Ziyang Xuan <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> (cherry picked from commit f969eb8) Signed-off-by: Greg Rose <[email protected]>
1 parent 8710d34 commit d9a8f26

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
24622462
{
24632463
const struct nft_expr_type *type, *candidate = NULL;
24642464

2465-
list_for_each_entry(type, &nf_tables_expressions, list) {
2465+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
24662466
if (!nla_strcmp(nla, type->name)) {
24672467
if (!type->family && !candidate)
24682468
candidate = type;
@@ -2494,9 +2494,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
24942494
if (nla == NULL)
24952495
return ERR_PTR(-EINVAL);
24962496

2497+
rcu_read_lock();
24972498
type = __nft_expr_type_get(family, nla);
2498-
if (type != NULL && try_module_get(type->owner))
2499+
if (type != NULL && try_module_get(type->owner)) {
2500+
rcu_read_unlock();
24992501
return type;
2502+
}
2503+
rcu_read_unlock();
25002504

25012505
lockdep_nfnl_nft_mutex_not_held();
25022506
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)