Skip to content

Commit 914d017

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

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
@@ -7227,7 +7227,7 @@ static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family)
72277227
{
72287228
const struct nft_object_type *type;
72297229

7230-
list_for_each_entry(type, &nf_tables_objects, list) {
7230+
list_for_each_entry_rcu(type, &nf_tables_objects, list) {
72317231
if (type->family != NFPROTO_UNSPEC &&
72327232
type->family != family)
72337233
continue;
@@ -7243,9 +7243,13 @@ nft_obj_type_get(struct net *net, u32 objtype, u8 family)
72437243
{
72447244
const struct nft_object_type *type;
72457245

7246+
rcu_read_lock();
72467247
type = __nft_obj_type_get(objtype, family);
7247-
if (type != NULL && try_module_get(type->owner))
7248+
if (type != NULL && try_module_get(type->owner)) {
7249+
rcu_read_unlock();
72487250
return type;
7251+
}
7252+
rcu_read_unlock();
72497253

72507254
lockdep_nfnl_nft_mutex_not_held();
72517255
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)