Skip to content

Commit 48fda4b

Browse files
Ziyang Xuansmb49
authored andcommitted
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
BugLink: https://bugs.launchpad.net/bugs/2067959 [ 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]> Signed-off-by: Portia Stephens <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent ca4cee7 commit 48fda4b

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
@@ -2821,7 +2821,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
28212821
{
28222822
const struct nft_expr_type *type, *candidate = NULL;
28232823

2824-
list_for_each_entry(type, &nf_tables_expressions, list) {
2824+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
28252825
if (!nla_strcmp(nla, type->name)) {
28262826
if (!type->family && !candidate)
28272827
candidate = type;
@@ -2853,9 +2853,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
28532853
if (nla == NULL)
28542854
return ERR_PTR(-EINVAL);
28552855

2856+
rcu_read_lock();
28562857
type = __nft_expr_type_get(family, nla);
2857-
if (type != NULL && try_module_get(type->owner))
2858+
if (type != NULL && try_module_get(type->owner)) {
2859+
rcu_read_unlock();
28582860
return type;
2861+
}
2862+
rcu_read_unlock();
28592863

28602864
lockdep_nfnl_nft_mutex_not_held();
28612865
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)