From 3e92055f8323729fdfa72e4ac463ed677424606c Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Wed, 7 Jun 2017 14:17:58 -0700 Subject: [PATCH] Forbid S-mode execution from user memory https://github.com/riscv/riscv-isa-manual/commit/285c81746fe664060b62ae0584865dbfa9f42e1a --- riscv/mmu.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/riscv/mmu.cc b/riscv/mmu.cc index 76a6ab1..54b5b1d 100644 --- a/riscv/mmu.cc +++ b/riscv/mmu.cc @@ -163,7 +163,7 @@ reg_t mmu_t::walk(reg_t addr, access_type type, reg_t mode) if (vm.levels == 0) return addr & ((reg_t(2) << (proc->xlen-1))-1); // zero-extend from xlen - bool supervisor = mode == PRV_S; + bool s_mode = mode == PRV_S; bool sum = get_field(proc->state.mstatus, MSTATUS_SUM); bool mxr = get_field(proc->state.mstatus, MSTATUS_MXR); @@ -189,7 +189,7 @@ reg_t mmu_t::walk(reg_t addr, access_type type, reg_t mode) if (PTE_TABLE(pte)) { // next level of page table base = ppn << PGSHIFT; - } else if ((pte & PTE_U) ? supervisor && !sum : !supervisor) { + } else if ((pte & PTE_U) ? s_mode && (type == FETCH || !sum) : !s_mode) { break; } else if (!(pte & PTE_V) || (!(pte & PTE_R) && (pte & PTE_W))) { break; -- 2.30.2