From: Fabiano Rosas Date: Thu, 13 Feb 2025 14:35:58 +0000 (-0300) Subject: elfload: Fix alignment when unmapping excess reservation X-Git-Tag: v8.2.10~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c837358c2f3b30524754ffebedb6c5d60ae3552;p=thirdparty%2Fqemu.git elfload: Fix alignment when unmapping excess reservation When complying with the alignment requested in the ELF and unmapping the excess reservation, having align_end not aligned to the guest page causes the unmap to be rejected by the alignment check at target_munmap and later brk adjustments hit an EEXIST. Fix by aligning the start of region to be unmapped. Fixes: c81d1fafa6 ("linux-user: Honor elf alignment when placing images") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1913 Signed-off-by: Fabiano Rosas [rth: Align load_end as well.] Signed-off-by: Richard Henderson Message-ID: <20250213143558.10504-1-farosas@suse.de> (cherry picked from commit 4b7b20a3b72c5000ea71bef505c16e6e628268b6) Signed-off-by: Michael Tokarev --- diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e1a8b102d4..84b640c1bf 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3432,8 +3432,8 @@ static void load_elf_image(const char *image_name, const ImageSource *src, if (align_size != reserve_size) { abi_ulong align_addr = ROUND_UP(load_addr, align); - abi_ulong align_end = align_addr + reserve_size; - abi_ulong load_end = load_addr + align_size; + abi_ulong align_end = TARGET_PAGE_ALIGN(align_addr + reserve_size); + abi_ulong load_end = TARGET_PAGE_ALIGN(load_addr + align_size); if (align_addr != load_addr) { target_munmap(load_addr, align_addr - load_addr);