Subject: CVE-2024-35905: bpf: Protect against int overflow for stack access size

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

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

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

bpf: Protect against int overflow for stack access size

This patch re-introduces protection against the size of access to stack
memory being negative; the access size can appear negative as a result
of overflowing its signed int representation. This should not actually
happen, as there are other protections along the way, but we should
protect against it anyway. One code path was missing such protections
(fixed in the previous patch in the series), causing out-of-bounds array
accesses in check_stack_range_initialized(). This patch causes the
verification of a program with such a non-sensical access size to fail.

This check used to exist in a more indirect way, but was inadvertendly
removed in a833a17aeac7.

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

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

	Issue introduced in 5.10.209 with commit afea95d319cc and fixed in 5.10.215 with commit 9970e059af47
	Issue introduced in 5.15.148 with commit 02962684258e and fixed in 5.15.154 with commit 37dc1718dc0c
	Issue introduced in 6.1.75 with commit b1d4d54d32ce and fixed in 6.1.85 with commit 98cdac206b11
	Issue introduced in 6.6.14 with commit 08b91babccbb and fixed in 6.6.26 with commit 3f0784b2f1eb
	Issue introduced in 6.8 with commit a833a17aeac7 and fixed in 6.8.5 with commit 203a68151e8e
	Issue introduced in 6.8 with commit a833a17aeac7 and fixed in 6.9 with commit ecc6a2101840
	Issue introduced in 6.7.2 with commit 1858b8a33193

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-35905
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:
	kernel/bpf/verifier.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/9970e059af471478455f9534e8c3db82f8c5496d
	https://git.kernel.org/stable/c/37dc1718dc0c4392dbfcb9adec22a776e745dd69
	https://git.kernel.org/stable/c/98cdac206b112bec63852e94802791e316acc2c1
	https://git.kernel.org/stable/c/3f0784b2f1eb9147973d8c43ba085c5fdf44ff69
	https://git.kernel.org/stable/c/203a68151e8eeb331d4a64ab78303f3a15faf103
	https://git.kernel.org/stable/c/ecc6a2101840177e57c925c102d2d29f260d37c8