Skip to content

Commit 2422501

Browse files
Ziyang Xuanummakynes
authored andcommitted
netfilter: nf_tables: Fix potential data-race in __nft_flowtable_type_get()
nft_unregister_flowtable_type() within nf_flow_inet_module_exit() can concurrent with __nft_flowtable_type_get() within nf_tables_newflowtable(). And thhere is not any protection when iterate over nf_tables_flowtables list in __nft_flowtable_type_get(). Therefore, there is pertential data-race of nf_tables_flowtables list entry. Use list_for_each_entry_rcu() to iterate over nf_tables_flowtables list in __nft_flowtable_type_get(), and use rcu_read_lock() in the caller nft_flowtable_type_get() to protect the entire type query process. Fixes: 3b49e2e ("netfilter: nf_tables: add flow table netlink frontend") Signed-off-by: Ziyang Xuan <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 994209d commit 2422501

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8296,11 +8296,12 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,
82968296
return err;
82978297
}
82988298

8299+
/* call under rcu_read_lock */
82998300
static const struct nf_flowtable_type *__nft_flowtable_type_get(u8 family)
83008301
{
83018302
const struct nf_flowtable_type *type;
83028303

8303-
list_for_each_entry(type, &nf_tables_flowtables, list) {
8304+
list_for_each_entry_rcu(type, &nf_tables_flowtables, list) {
83048305
if (family == type->family)
83058306
return type;
83068307
}
@@ -8312,9 +8313,13 @@ nft_flowtable_type_get(struct net *net, u8 family)
83128313
{
83138314
const struct nf_flowtable_type *type;
83148315

8316+
rcu_read_lock();
83158317
type = __nft_flowtable_type_get(family);
8316-
if (type != NULL && try_module_get(type->owner))
8318+
if (type != NULL && try_module_get(type->owner)) {
8319+
rcu_read_unlock();
83178320
return type;
8321+
}
8322+
rcu_read_unlock();
83188323

83198324
lockdep_nfnl_nft_mutex_not_held();
83208325
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)