mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 08:43:19 -04:00
riscv: Permit spurious faults in kernel mode
Right now, pmap_enter() does not issue an sfence.vma after overwriting an invalid PTE, so the kernel can trigger a page fault when accessing a freshly created mapping. In this case, pmap_fault() can handle the exception, but we may panic before that. Move the check; this is consistent with arm64 and serves to ensure that we don't call vm_fault() etc. from a context where that's not permitted. Also fix a related bug: don't enable interrupts if they were disabled in the context where the exception occurred. Reviewed by: br Tested by: br MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47688
This commit is contained in:
parent
e02029e6f4
commit
c226f19351
1 changed files with 7 additions and 6 deletions
|
|
@ -227,11 +227,6 @@ page_fault_handler(struct trapframe *frame, int usermode)
|
|||
pcb = td->td_pcb;
|
||||
stval = frame->tf_stval;
|
||||
|
||||
if (td->td_critnest != 0 || td->td_intr_nesting_level != 0 ||
|
||||
WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL,
|
||||
"Kernel page fault") != 0)
|
||||
goto fatal;
|
||||
|
||||
if (usermode) {
|
||||
if (!VIRT_IS_VALID(stval)) {
|
||||
call_trapsignal(td, SIGSEGV, SEGV_MAPERR, (void *)stval,
|
||||
|
|
@ -244,7 +239,8 @@ page_fault_handler(struct trapframe *frame, int usermode)
|
|||
* Enable interrupts for the duration of the page fault. For
|
||||
* user faults this was done already in do_trap_user().
|
||||
*/
|
||||
intr_enable();
|
||||
if ((frame->tf_sstatus & SSTATUS_SIE) != 0)
|
||||
intr_enable();
|
||||
|
||||
if (stval >= VM_MIN_KERNEL_ADDRESS) {
|
||||
map = kernel_map;
|
||||
|
|
@ -268,6 +264,11 @@ page_fault_handler(struct trapframe *frame, int usermode)
|
|||
if (VIRT_IS_VALID(va) && pmap_fault(map->pmap, va, ftype))
|
||||
goto done;
|
||||
|
||||
if (td->td_critnest != 0 || td->td_intr_nesting_level != 0 ||
|
||||
WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL,
|
||||
"Kernel page fault") != 0)
|
||||
goto fatal;
|
||||
|
||||
error = vm_fault_trap(map, va, ftype, VM_FAULT_NORMAL, &sig, &ucode);
|
||||
if (error != KERN_SUCCESS) {
|
||||
if (usermode) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue