Skip to content

Commit b38a133

Browse files
Ziyang Xuangregkh
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]>
1 parent 2450a69 commit b38a133

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
@@ -2239,7 +2239,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
22392239
{
22402240
const struct nft_expr_type *type, *candidate = NULL;
22412241

2242-
list_for_each_entry(type, &nf_tables_expressions, list) {
2242+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
22432243
if (!nla_strcmp(nla, type->name)) {
22442244
if (!type->family && !candidate)
22452245
candidate = type;
@@ -2271,9 +2271,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
22712271
if (nla == NULL)
22722272
return ERR_PTR(-EINVAL);
22732273

2274+
rcu_read_lock();
22742275
type = __nft_expr_type_get(family, nla);
2275-
if (type != NULL && try_module_get(type->owner))
2276+
if (type != NULL && try_module_get(type->owner)) {
2277+
rcu_read_unlock();
22762278
return type;
2279+
}
2280+
rcu_read_unlock();
22772281

22782282
lockdep_nfnl_nft_mutex_not_held();
22792283
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)