HomeFreeBSD

riscv: handle page faults in the unmappable region

Description

riscv: handle page faults in the unmappable region

When handling a kernel page fault, check explicitly that stval resides
in either the user or kernel address spaces, and make the page fault
fatal if not. Otherwise, a properly crafted address may appear to
pmap_fault() as a valid and present page in the kernel map, causing the
page fault to be retried continuously. This is mainly due to the fact
that the upper bits of virtual addresses are not validated by most of
the pmap code.

Faults of this nature should only occur due to some kind of bug in the
kernel, but it is best to handle them gracefully when they do.

Handle user page faults in the same way, sending a SIGSEGV immediately
when a malformed address is encountered.

Add an assertion to pmap_l1(), which should help catch other bugs of
this kind that make it this far.

Reviewed by: jrtc27, markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31208

(cherry picked from commit 4a9f2f8b07c2d1a1c12f4aabdccd36f56b20cfda)

Details

Provenance
mhorneAuthored on Oct 7 2021, 9:05 PM
Reviewer
jrtc27
Differential Revision
D31208: riscv: handle page faults in the unmappable region
Parents
rG3c01f7415067: libpmc: add some AMD pmu counter aliases
Branches
Unknown
Tags
Unknown