Skip to content

Commit 65676da

Browse files
committed
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
jira LE-1907 cve CVE-2024-27020 Rebuild_History Non-Buildable kernel-5.14.0-427.33.1.el9_4 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: Jonathan Maple <jmaple@ciq.com>
1 parent 7bc4f3e commit 65676da

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
@@ -2811,7 +2811,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
28112811
{
28122812
const struct nft_expr_type *type, *candidate = NULL;
28132813

2814-
list_for_each_entry(type, &nf_tables_expressions, list) {
2814+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
28152815
if (!nla_strcmp(nla, type->name)) {
28162816
if (!type->family && !candidate)
28172817
candidate = type;
@@ -2843,9 +2843,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
28432843
if (nla == NULL)
28442844
return ERR_PTR(-EINVAL);
28452845

2846+
rcu_read_lock();
28462847
type = __nft_expr_type_get(family, nla);
2847-
if (type != NULL && try_module_get(type->owner))
2848+
if (type != NULL && try_module_get(type->owner)) {
2849+
rcu_read_unlock();
28482850
return type;
2851+
}
2852+
rcu_read_unlock();
28492853

28502854
lockdep_nfnl_nft_mutex_not_held();
28512855
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)