Skip to content

Commit 1f326d6

Browse files
committed
Add ELF header sanity check
1 parent 9637e60 commit 1f326d6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pk/elf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void load_elf(const char* fn, elf_info* info)
7676
panic("not a statically linked ELF program");
7777
}
7878
if(ph[i].p_type == PT_LOAD && ph[i].p_memsz) {
79+
if (ph[i].p_filesz > ph[i].p_memsz)
80+
goto fail;
7981
uintptr_t prepad = ph[i].p_vaddr % RISCV_PGSIZE;
8082
uintptr_t vaddr = ph[i].p_vaddr + bias;
8183
if (vaddr + ph[i].p_memsz > info->brk_min)

0 commit comments

Comments
 (0)