Skip to content

Commit 60543ca

Browse files
committed
netfilter: nf_tables: Fix potential data-race in __nft_flowtable_type_get()
jira LE-3201 cve CVE-2024-35898 Rebuild_History Non-Buildable kernel-rt-4.18.0-553.27.1.rt7.368.el8_10 commit-author Ziyang Xuan <[email protected]> commit 2422501 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]> (cherry picked from commit 2422501) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 04db0a5 commit 60543ca

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
@@ -6819,11 +6819,12 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,
68196819
return err;
68206820
}
68216821

6822+
/* call under rcu_read_lock */
68226823
static const struct nf_flowtable_type *__nft_flowtable_type_get(u8 family)
68236824
{
68246825
const struct nf_flowtable_type *type;
68256826

6826-
list_for_each_entry(type, &nf_tables_flowtables, list) {
6827+
list_for_each_entry_rcu(type, &nf_tables_flowtables, list) {
68276828
if (family == type->family)
68286829
return type;
68296830
}
@@ -6835,9 +6836,13 @@ nft_flowtable_type_get(struct net *net, u8 family)
68356836
{
68366837
const struct nf_flowtable_type *type;
68376838

6839+
rcu_read_lock();
68386840
type = __nft_flowtable_type_get(family);
6839-
if (type != NULL && try_module_get(type->owner))
6841+
if (type != NULL && try_module_get(type->owner)) {
6842+
rcu_read_unlock();
68406843
return type;
6844+
}
6845+
rcu_read_unlock();
68416846

68426847
lockdep_nfnl_nft_mutex_not_held();
68436848
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)