Subject: CVE-2024-35987: riscv: Fix loading 64-bit NOMMU kernels past the start of RAM

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

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

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

riscv: Fix loading 64-bit NOMMU kernels past the start of RAM

commit 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear
mapping") added logic to allow using RAM below the kernel load address.
However, this does not work for NOMMU, where PAGE_OFFSET is fixed to the
kernel load address. Since that range of memory corresponds to PFNs
below ARCH_PFN_OFFSET, mm initialization runs off the beginning of
mem_map and corrupts adjacent kernel memory. Fix this by restoring the
previous behavior for NOMMU kernels.

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

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

	Issue introduced in 6.4 with commit 3335068f8721 and fixed in 6.6.30 with commit b008e327fa57
	Issue introduced in 6.4 with commit 3335068f8721 and fixed in 6.8.9 with commit ea6628e4e235
	Issue introduced in 6.4 with commit 3335068f8721 and fixed in 6.9 with commit aea702dde7e9

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-35987
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/page.h
	arch/riscv/mm/init.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/b008e327fa570aca210f98c817757649bae56694
	https://git.kernel.org/stable/c/ea6628e4e2353978af7e3b4ad4fdaab6149acf3d
	https://git.kernel.org/stable/c/aea702dde7e9876fb00571a2602f25130847bf0f