Subject: CVE-2024-47703: bpf, lsm: Add check for BPF LSM return value

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

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

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

bpf, lsm: Add check for BPF LSM return value

A bpf prog returning a positive number attached to file_alloc_security
hook makes kernel panic.

This happens because file system can not filter out the positive number
returned by the LSM prog using IS_ERR, and misinterprets this positive
number as a file pointer.

Given that hook file_alloc_security never returned positive number
before the introduction of BPF LSM, and other BPF LSM hooks may
encounter similar issues, this patch adds LSM return value check
in verifier, to ensure no unexpected value is returned.

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

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

	Issue introduced in 5.7 with commit 520b7aa00d8c and fixed in 6.10.13 with commit 1050727d83e7
	Issue introduced in 5.7 with commit 520b7aa00d8c and fixed in 6.11.2 with commit 27ca3e20fe80
	Issue introduced in 5.7 with commit 520b7aa00d8c and fixed in 6.12-rc1 with commit 5d99e198be27

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-47703
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:
	include/linux/bpf.h
	include/linux/bpf_lsm.h
	kernel/bpf/bpf_lsm.c
	kernel/bpf/btf.c
	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/1050727d83e70449991c29dd1cf29fe936a63da3
	https://git.kernel.org/stable/c/27ca3e20fe80be85a92b10064dfeb56cb2564b1c
	https://git.kernel.org/stable/c/5d99e198be279045e6ecefe220f5c52f8ce9bfd5