Skip to content

Commit 9f3e145

Browse files
committed
net: fix out-of-bounds access in ops_init
jira LE-3201 cve CVE-2024-36883 Rebuild_History Non-Buildable kernel-rt-4.18.0-553.22.1.rt7.363.el8_10 commit-author Thadeu Lima de Souza Cascardo <cascardo@igalia.com> commit a26ff37 net_alloc_generic is called by net_alloc, which is called without any locking. It reads max_gen_ptrs, which is changed under pernet_ops_rwsem. It is read twice, first to allocate an array, then to set s.len, which is later used to limit the bounds of the array access. It is possible that the array is allocated and another thread is registering a new pernet ops, increments max_gen_ptrs, which is then used to set s.len with a larger than allocated length for the variable array. Fix it by reading max_gen_ptrs only once in net_alloc_generic. If max_gen_ptrs is later incremented, it will be caught in net_assign_generic. Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com> Fixes: 073862b ("netns: fix net_alloc_generic()") Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240502132006.3430840-1-cascardo@igalia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> (cherry picked from commit a26ff37) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent e9d1be1 commit 9f3e145

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

net/core/net_namespace.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ u64 __net_gen_cookie(struct net *net)
7878

7979
static struct net_generic *net_alloc_generic(void)
8080
{
81+
unsigned int gen_ptrs = READ_ONCE(max_gen_ptrs);
82+
unsigned int generic_size;
8183
struct net_generic *ng;
82-
unsigned int generic_size = offsetof(struct net_generic, ptr[max_gen_ptrs]);
84+
85+
generic_size = offsetof(struct net_generic, ptr[gen_ptrs]);
8386

8487
ng = kzalloc(generic_size, GFP_KERNEL);
8588
if (ng)
86-
ng->s.len = max_gen_ptrs;
89+
ng->s.len = gen_ptrs;
8790

8891
return ng;
8992
}
@@ -1197,7 +1200,11 @@ static int register_pernet_operations(struct list_head *list,
11971200
if (error < 0)
11981201
return error;
11991202
*ops->id = error;
1200-
max_gen_ptrs = max(max_gen_ptrs, *ops->id + 1);
1203+
/* This does not require READ_ONCE as writers already hold
1204+
* pernet_ops_rwsem. But WRITE_ONCE is needed to protect
1205+
* net_alloc_generic.
1206+
*/
1207+
WRITE_ONCE(max_gen_ptrs, max(max_gen_ptrs, *ops->id + 1));
12011208
}
12021209
error = __register_pernet_operations(list, ops);
12031210
if (error) {

0 commit comments

Comments
 (0)