aboutsummaryrefslogtreecommitdiff
path: root/pk/mmap.c
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2021-02-10 17:03:03 -0800
committerAndrew Waterman <andrew@sifive.com>2021-03-25 22:21:06 -0700
commit817e7d0dfea820a369a5b5c2d5d729942b7daf42 (patch)
treea725081a6966d928cb9ddacdd2172251ef1691f9 /pk/mmap.c
parentb7f64fe5584094a6fe65d94d5e2382ff9289cbda (diff)
downloadpk-817e7d0dfea820a369a5b5c2d5d729942b7daf42.zip
pk-817e7d0dfea820a369a5b5c2d5d729942b7daf42.tar.gz
pk-817e7d0dfea820a369a5b5c2d5d729942b7daf42.tar.bz2
pk: only access user memory through explicit accessors
Enforced with sstatus.SUM.
Diffstat (limited to 'pk/mmap.c')
-rw-r--r--pk/mmap.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/pk/mmap.c b/pk/mmap.c
index 1022f90..8f52c0d 100644
--- a/pk/mmap.c
+++ b/pk/mmap.c
@@ -175,6 +175,7 @@ static int __handle_page_fault(uintptr_t vaddr, int prot)
else if (!(*pte & PTE_V))
{
uintptr_t ppn = vpn + (first_free_paddr / RISCV_PGSIZE);
+ uintptr_t kva = ppn * RISCV_PGSIZE;
vmr_t* v = (vmr_t*)*pte;
*pte = pte_create(ppn, prot_to_type(PROT_READ|PROT_WRITE, 0));
@@ -182,7 +183,7 @@ static int __handle_page_fault(uintptr_t vaddr, int prot)
if (v->file)
{
size_t flen = MIN(RISCV_PGSIZE, v->length - (vaddr - v->addr));
- ssize_t ret = file_pread(v->file, (void*)vaddr, flen, vaddr - v->addr + v->offset);
+ ssize_t ret = file_pread(v->file, (void*)kva, flen, vaddr - v->addr + v->offset);
kassert(ret > 0);
if (ret < RISCV_PGSIZE)
memset((void*)vaddr + ret, 0, RISCV_PGSIZE - ret);