Skip to content

Commit 0394da8

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

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
@@ -7045,7 +7045,7 @@ static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family)
70457045
{
70467046
const struct nft_object_type *type;
70477047

7048-
list_for_each_entry(type, &nf_tables_objects, list) {
7048+
list_for_each_entry_rcu(type, &nf_tables_objects, list) {
70497049
if (type->family != NFPROTO_UNSPEC &&
70507050
type->family != family)
70517051
continue;
@@ -7061,9 +7061,13 @@ nft_obj_type_get(struct net *net, u32 objtype, u8 family)
70617061
{
70627062
const struct nft_object_type *type;
70637063

7064+
rcu_read_lock();
70647065
type = __nft_obj_type_get(objtype, family);
7065-
if (type != NULL && try_module_get(type->owner))
7066+
if (type != NULL && try_module_get(type->owner)) {
7067+
rcu_read_unlock();
70667068
return type;
7069+
}
7070+
rcu_read_unlock();
70677071

70687072
lockdep_nfnl_nft_mutex_not_held();
70697073
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)