Skip to content

Commit f969eb8

Browse files
Ziyang Xuanummakynes
authored andcommitted
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
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]>
1 parent 19fa4f2 commit f969eb8

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
@@ -3060,7 +3060,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
30603060
{
30613061
const struct nft_expr_type *type, *candidate = NULL;
30623062

3063-
list_for_each_entry(type, &nf_tables_expressions, list) {
3063+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
30643064
if (!nla_strcmp(nla, type->name)) {
30653065
if (!type->family && !candidate)
30663066
candidate = type;
@@ -3092,9 +3092,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
30923092
if (nla == NULL)
30933093
return ERR_PTR(-EINVAL);
30943094

3095+
rcu_read_lock();
30953096
type = __nft_expr_type_get(family, nla);
3096-
if (type != NULL && try_module_get(type->owner))
3097+
if (type != NULL && try_module_get(type->owner)) {
3098+
rcu_read_unlock();
30973099
return type;
3100+
}
3101+
rcu_read_unlock();
30983102

30993103
lockdep_nfnl_nft_mutex_not_held();
31003104
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)