Subject: CVE-2024-36883: net: fix out-of-bounds access in ops_init

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

net: fix out-of-bounds access in ops_init

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.

The Linux kernel CVE team has assigned CVE-2024-36883 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 4.19.314 with commit 3cdc34d76c4f
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 5.4.276 with commit 7b0e64583eab
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 5.10.217 with commit 0c3248bc708a
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 5.15.159 with commit 9518b79bfd2f
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 6.1.91 with commit 2d60ff5874ae
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 6.6.31 with commit b6dbfd5bcc26
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 6.8.10 with commit f4f94587e1bf
	Issue introduced in 3.3 with commit 073862ba5d24 and fixed in 6.9 with commit a26ff37e624d
	Issue introduced in 3.0.19 with commit 561331eae0a0
	Issue introduced in 3.2.3 with commit a2c82f7bee1f

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-36883
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	net/core/net_namespace.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/3cdc34d76c4f777579e28ad373979d36c030cfd3
	https://git.kernel.org/stable/c/7b0e64583eab8c1d896b47e5dd0bf2e7d86ec41f
	https://git.kernel.org/stable/c/0c3248bc708a7797be573214065cf908ff1f54c7
	https://git.kernel.org/stable/c/9518b79bfd2fbf99fa9b7e8e36bcb1825e7ba030
	https://git.kernel.org/stable/c/2d60ff5874aefd006717ca5e22ac1e25eac29c42
	https://git.kernel.org/stable/c/b6dbfd5bcc267a95a0bf1bf96af46243f96ec6cd
	https://git.kernel.org/stable/c/f4f94587e1bf87cb40ec33955a9d90148dd026ab
	https://git.kernel.org/stable/c/a26ff37e624d12e28077e5b24d2b264f62764ad6