diff options
author | Andrew Waterman <andrew@sifive.com> | 2024-04-17 14:58:02 -0700 |
---|---|---|
committer | Andrew Waterman <andrew@sifive.com> | 2024-05-20 18:37:48 -0700 |
commit | dd86101e7148e95f60eeb58a498b0ab6be8829dd (patch) | |
tree | f00bdd12c1a5d80cf33326baecf7a30f9defee99 | |
parent | 395f318f5ea0cc450020a3b413c585a452ba8398 (diff) | |
download | riscv-pk-dd86101e7148e95f60eeb58a498b0ab6be8829dd.zip riscv-pk-dd86101e7148e95f60eeb58a498b0ab6be8829dd.tar.gz riscv-pk-dd86101e7148e95f60eeb58a498b0ab6be8829dd.tar.bz2 |
Don't mmap ELF segments with zero filesz
-rw-r--r-- | pk/elf.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -84,8 +84,10 @@ void load_elf(const char* fn, elf_info* info) info->brk_min = vaddr + ph[i].p_memsz; int flags2 = flags | (prepad ? MAP_POPULATE : 0); int prot = get_prot(ph[i].p_flags); - if (__do_mmap(vaddr - prepad, ph[i].p_filesz + prepad, prot | PROT_WRITE, flags2, file, ph[i].p_offset - prepad) != vaddr - prepad) - goto fail; + if (ph[i].p_filesz != 0) { + if (__do_mmap(vaddr - prepad, ph[i].p_filesz + prepad, prot | PROT_WRITE, flags2, file, ph[i].p_offset - prepad) != vaddr - prepad) + goto fail; + } memset_user((void*)vaddr - prepad, 0, prepad); if (!(prot & PROT_WRITE)) if (do_mprotect(vaddr - prepad, ph[i].p_filesz + prepad, prot)) |