Skip to content

Commit 59c0769

Browse files
Ziyang Xuanvegard
Ziyang Xuan
authored andcommitted
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
[ Upstream 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]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 939109c) Signed-off-by: Vegard Nossum <[email protected]>
1 parent cf9d940 commit 59c0769

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
@@ -1820,7 +1820,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
18201820
{
18211821
const struct nft_expr_type *type, *candidate = NULL;
18221822

1823-
list_for_each_entry(type, &nf_tables_expressions, list) {
1823+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
18241824
if (!nla_strcmp(nla, type->name)) {
18251825
if (!type->family && !candidate)
18261826
candidate = type;
@@ -1839,9 +1839,13 @@ static const struct nft_expr_type *nft_expr_type_get(u8 family,
18391839
if (nla == NULL)
18401840
return ERR_PTR(-EINVAL);
18411841

1842+
rcu_read_lock();
18421843
type = __nft_expr_type_get(family, nla);
1843-
if (type != NULL && try_module_get(type->owner))
1844+
if (type != NULL && try_module_get(type->owner)) {
1845+
rcu_read_unlock();
18441846
return type;
1847+
}
1848+
rcu_read_unlock();
18451849

18461850
#ifdef CONFIG_MODULES
18471851
if (type == NULL) {

0 commit comments

Comments
 (0)