Skip to content

Commit 6b5c8db

Browse files
committed
mprotect whole ELF segment, not just file portion
1 parent c917315 commit 6b5c8db

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pk/elf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ void load_elf(const char* fn, elf_info* info)
8989
goto fail;
9090
}
9191
memset_user((void*)vaddr - prepad, 0, prepad);
92-
if (!(prot & PROT_WRITE))
93-
if (do_mprotect(vaddr - prepad, ph[i].p_filesz + prepad, prot))
94-
goto fail;
9592
size_t mapped = ROUNDUP(ph[i].p_filesz + prepad, RISCV_PGSIZE) - prepad;
9693
if (ph[i].p_memsz > mapped)
9794
if (__do_mmap(vaddr + mapped, ph[i].p_memsz - mapped, prot, flags|MAP_ANONYMOUS, 0, 0) != vaddr + mapped)
9895
goto fail;
96+
if (!(prot & PROT_WRITE))
97+
if (do_mprotect(vaddr - prepad, ph[i].p_memsz + prepad, prot))
98+
goto fail;
9999
}
100100
}
101101

0 commit comments

Comments
 (0)