Skip to content

Commit 4ca946b

Browse files
Ziyang Xuangregkh
Ziyang Xuan
authored andcommitted
netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get()
[ Upstream commit d78d867 ] nft_unregister_obj() can concurrent with __nft_obj_type_get(), and there is not any protection when iterate over nf_tables_objects list in __nft_obj_type_get(). Therefore, there is potential data-race of nf_tables_objects list entry. Use list_for_each_entry_rcu() to iterate over nf_tables_objects list in __nft_obj_type_get(), and use rcu_read_lock() in the caller nft_obj_type_get() to protect the entire type query process. Fixes: e500924 ("netfilter: nf_tables: add stateful objects") Signed-off-by: Ziyang Xuan <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 01f1a67 commit 4ca946b

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
@@ -7607,7 +7607,7 @@ static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family)
76077607
{
76087608
const struct nft_object_type *type;
76097609

7610-
list_for_each_entry(type, &nf_tables_objects, list) {
7610+
list_for_each_entry_rcu(type, &nf_tables_objects, list) {
76117611
if (type->family != NFPROTO_UNSPEC &&
76127612
type->family != family)
76137613
continue;
@@ -7623,9 +7623,13 @@ nft_obj_type_get(struct net *net, u32 objtype, u8 family)
76237623
{
76247624
const struct nft_object_type *type;
76257625

7626+
rcu_read_lock();
76267627
type = __nft_obj_type_get(objtype, family);
7627-
if (type != NULL && try_module_get(type->owner))
7628+
if (type != NULL && try_module_get(type->owner)) {
7629+
rcu_read_unlock();
76287630
return type;
7631+
}
7632+
rcu_read_unlock();
76297633

76307634
lockdep_nfnl_nft_mutex_not_held();
76317635
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)