Skip to content

Commit 9b7c0f3

Browse files
committed
netfilter: nf_tables: Fix potential data-race in __nft_flowtable_type_get()
jira LE-1907 cve CVE-2024-35898 Rebuild_History Non-Buildable kernel-5.14.0-427.33.1.el9_4 commit-author Ziyang Xuan <william.xuanziyang@huawei.com> 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 <william.xuanziyang@huawei.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> (cherry picked from commit 2422501) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 875b368 commit 9b7c0f3

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
@@ -7912,11 +7912,12 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,
79127912
return err;
79137913
}
79147914

7915+
/* call under rcu_read_lock */
79157916
static const struct nf_flowtable_type *__nft_flowtable_type_get(u8 family)
79167917
{
79177918
const struct nf_flowtable_type *type;
79187919

7919-
list_for_each_entry(type, &nf_tables_flowtables, list) {
7920+
list_for_each_entry_rcu(type, &nf_tables_flowtables, list) {
79207921
if (family == type->family)
79217922
return type;
79227923
}
@@ -7928,9 +7929,13 @@ nft_flowtable_type_get(struct net *net, u8 family)
79287929
{
79297930
const struct nf_flowtable_type *type;
79307931

7932+
rcu_read_lock();
79317933
type = __nft_flowtable_type_get(family);
7932-
if (type != NULL && try_module_get(type->owner))
7934+
if (type != NULL && try_module_get(type->owner)) {
7935+
rcu_read_unlock();
79337936
return type;
7937+
}
7938+
rcu_read_unlock();
79347939

79357940
lockdep_nfnl_nft_mutex_not_held();
79367941
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)