diff mbox series

[for-8.2] linux-user: Fix loaddr computation for some elf files

Message ID 20231114201742.183271-1-richard.henderson@linaro.org
State Superseded
Headers show
Series [for-8.2] linux-user: Fix loaddr computation for some elf files | expand

Commit Message

Richard Henderson Nov. 14, 2023, 8:17 p.m. UTC
The file offset of the load segment is not relevant to the
low address, only the beginning of the virtual address page.

Cc: qemu-stable@nongnu.org
Fixes: a93934fecd4 ("elf: take phdr offset into account when calculating the program load address")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1952
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Tokarev Nov. 15, 2023, 9:09 a.m. UTC | #1
14.11.2023 23:17, Richard Henderson:
> The file offset of the load segment is not relevant to the
> low address, only the beginning of the virtual address page.
> 
> Cc: qemu-stable@nongnu.org
> Fixes: a93934fecd4 ("elf: take phdr offset into account when calculating the program load address")
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1952
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>

> ---
>   linux-user/elfload.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 4cd6891d7b..cf9e74468b 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -3308,7 +3308,7 @@ static void load_elf_image(const char *image_name, const ImageSource *src,
>       for (i = 0; i < ehdr->e_phnum; ++i) {
>           struct elf_phdr *eppnt = phdr + i;
>           if (eppnt->p_type == PT_LOAD) {
> -            abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
> +            abi_ulong a = eppnt->p_vaddr & TARGET_PAGE_MASK;
>               if (a < loaddr) {
>                   loaddr = a;
>               }
diff mbox series

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 4cd6891d7b..cf9e74468b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3308,7 +3308,7 @@  static void load_elf_image(const char *image_name, const ImageSource *src,
     for (i = 0; i < ehdr->e_phnum; ++i) {
         struct elf_phdr *eppnt = phdr + i;
         if (eppnt->p_type == PT_LOAD) {
-            abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
+            abi_ulong a = eppnt->p_vaddr & TARGET_PAGE_MASK;
             if (a < loaddr) {
                 loaddr = a;
             }