Skip to content

Commit a9e34de

Browse files
CIQ Kernel Automationroxanan1996
authored andcommitted
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
jira VULN-4970 cve CVE-2024-27020 commit-author Ziyang Xuan <william.xuanziyang@huawei.com> 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 <william.xuanziyang@huawei.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> (cherry picked from commit f969eb8) Signed-off-by: CIQ Kernel Automation <ciq_kernel_automation@ciq.com>
1 parent 66f0b1c commit a9e34de

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

net/netfilter/nf_tables_api.c

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

2810-
list_for_each_entry(type, &nf_tables_expressions, list) {
2810+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
28112811
if (!nla_strcmp(nla, type->name)) {
28122812
if (!type->family && !candidate)
28132813
candidate = type;
@@ -2839,9 +2839,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
28392839
if (nla == NULL)
28402840
return ERR_PTR(-EINVAL);
28412841

2842+
rcu_read_lock();
28422843
type = __nft_expr_type_get(family, nla);
2843-
if (type != NULL && try_module_get(type->owner))
2844+
if (type != NULL && try_module_get(type->owner)) {
2845+
rcu_read_unlock();
28442846
return type;
2847+
}
2848+
rcu_read_unlock();
28452849

28462850
lockdep_nfnl_nft_mutex_not_held();
28472851
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)