aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2024-04-17 14:58:02 -0700
committerAndrew Waterman <andrew@sifive.com>2024-05-20 18:37:48 -0700
commitdd86101e7148e95f60eeb58a498b0ab6be8829dd (patch)
treef00bdd12c1a5d80cf33326baecf7a30f9defee99
parent395f318f5ea0cc450020a3b413c585a452ba8398 (diff)
downloadriscv-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.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/pk/elf.c b/pk/elf.c
index ad52bf6..b520609 100644
--- a/pk/elf.c
+++ b/pk/elf.c
@@ -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))