]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
net: fix out-of-bounds access in ops_init
authorThadeu Lima de Souza Cascardo <cascardo@igalia.com>
Thu, 2 May 2024 13:20:06 +0000 (10:20 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 May 2024 09:56:21 +0000 (11:56 +0200)
commit2d60ff5874aefd006717ca5e22ac1e25eac29c42
tree1f8cd88f0b1f0134addeb8dd65b37007ad339527
parentce740545c0c9a144e489a85363d13a9c03dd08e9
net: fix out-of-bounds access in ops_init

commit a26ff37e624d12e28077e5b24d2b264f62764ad6 upstream.

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: 073862ba5d24 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/core/net_namespace.c