Subject: CVE-2023-52677: riscv: Check if the code to patch lies in the exit section

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

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

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

riscv: Check if the code to patch lies in the exit section

Otherwise we fall through to vmalloc_to_page() which panics since the
address does not lie in the vmalloc region.

The Linux kernel CVE team has assigned CVE-2023-52677 to this issue.

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

	Issue introduced in 5.7 with commit 043cb41a85de and fixed in 5.15.148 with commit 938f70d14618
	Issue introduced in 5.7 with commit 043cb41a85de and fixed in 6.1.75 with commit 890cfe5337e0
	Issue introduced in 5.7 with commit 043cb41a85de and fixed in 6.6.14 with commit 8db56df4a954
	Issue introduced in 5.7 with commit 043cb41a85de and fixed in 6.7.2 with commit 1d7a03052846
	Issue introduced in 5.7 with commit 043cb41a85de and fixed in 6.8 with commit 420370f3ae3d

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-2023-52677
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:
	arch/riscv/include/asm/sections.h
	arch/riscv/kernel/patch.c
	arch/riscv/kernel/vmlinux-xip.lds.S
	arch/riscv/kernel/vmlinux.lds.S

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/938f70d14618ec72e10d6fcf8a546134136d7c13
	https://git.kernel.org/stable/c/890cfe5337e0aaf03ece1429db04d23c88da72e7
	https://git.kernel.org/stable/c/8db56df4a954b774bdc68917046a685a9fa2e4bc
	https://git.kernel.org/stable/c/1d7a03052846f34d624d0ab41a879adf5e85c85f
	https://git.kernel.org/stable/c/420370f3ae3d3b883813fd3051a38805160b2b9f