From: Helge Deller <[email protected]> Static built ARM binaries for Cortex-m55 may have been linked to have their load address at address 0. When qemu-user is running as non-root user and thus will try to mmap() a host address which is smaller than mmap_min_addr (/proc/sys/vm/mmap_min_addr), it will fail with EPERM and as such loading those guest programs will fail.
Avoid this EPERM failure by automatically choosing a valid starting guest_base address which has to be higher than mmap_min_addr. Signed-off-by: Helge Deller <[email protected]> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1890 --- linux-user/elfload.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0e757787d2..152c122a23 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1033,8 +1033,9 @@ static void pgb_dynamic(const char *image_name, uintptr_t guest_loaddr, uintptr_t brk, ret; PGBAddrs ga; - /* Try the identity map first. */ - if (pgb_addr_set(&ga, guest_loaddr, guest_hiaddr, true)) { + /* Try the identity map first if guest_loadaddr is above mmap_min_addr. */ + if (guest_loaddr >= mmap_min_addr && + pgb_addr_set(&ga, guest_loaddr, guest_hiaddr, true)) { brk = (uintptr_t)sbrk(0); if (pgb_try_mmap_set(&ga, 0, brk)) { guest_base = 0; -- 2.54.0
