Skip to content

Commit 939109c

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 <william.xuanziyang@huawei.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 97f097a commit 939109c

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
@@ -2083,7 +2083,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family,
20832083
{
20842084
const struct nft_expr_type *type, *candidate = NULL;
20852085

2086-
list_for_each_entry(type, &nf_tables_expressions, list) {
2086+
list_for_each_entry_rcu(type, &nf_tables_expressions, list) {
20872087
if (!nla_strcmp(nla, type->name)) {
20882088
if (!type->family && !candidate)
20892089
candidate = type;
@@ -2103,9 +2103,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
21032103
if (nla == NULL)
21042104
return ERR_PTR(-EINVAL);
21052105

2106+
rcu_read_lock();
21062107
type = __nft_expr_type_get(family, nla);
2107-
if (type != NULL && try_module_get(type->owner))
2108+
if (type != NULL && try_module_get(type->owner)) {
2109+
rcu_read_unlock();
21082110
return type;
2111+
}
2112+
rcu_read_unlock();
21092113

21102114
lockdep_nfnl_nft_mutex_not_held();
21112115
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)