Closed TiagoTeixeira-synthara closed 7 months ago
Evidently mmap is supposed to fail for size of 0 (though I'll admit getting that correct was by sheer luck). So the fix is to not call mmap in this case. Fixed in c917315bf7a91e897f6464c62bdda01f9635536a
I agree re: mprotect, too. Fixed in 6b5c8dbb6f40eacbce5b698e957630e56ec30879
Hey, thanks for the follow up, Looks good thanks for the fix
Hello there,
I have a RISC-V ELF binary (
hello.elf
) that I'm trying to run onspike pk
.Running it fails with
couldn't open ELF program: hello.elf!
.After inspecting the source code and the binary, it appears that the binary has one program header where the
FileSiz
/p_filesz
is 0 (zero).(Partial output from
readelf
)From the section headers, it seems that that memory area is for the stack:
(Partial output from
readelf
)From the source code,
pk/elf.c
at functionload_elf
(referencing latest commit I'm at) [https://github.com/riscv-software-src/riscv-pk/blob/9637e60b96b21a7f85a85bf033b87f64fb823b6c/pk/elf.c#L85]()(source)
The length passed to the
__do_mmap
function is 0 (zero), having the__do_mmap
function failing at [https://github.com/riscv-software-src/riscv-pk/blob/9637e60b96b21a7f85a85bf033b87f64fb823b6c/pk/mmap.c#L366]()From the previous line:
The
(length-1)
may give the max value forsize_t
type givingnpage
a false big value, which would be bigger than the number of free pagesAs a suggestion on how to fix this, should the loader handle the cases where
p_filesz
is zero? Possibly just skipping over that memory mapping. In general, ifp_memsz
is zero, then it shouldn't even have the need to be loaded?And should the
mprotect
call protect all ofp_memsz
memory instead of justp_filesz
?Thanks for the support