qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Riku Voipio <riku.voipio@iki.fi>
To: Max Filippov <jcmvbkbc@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] linux-user: elfload: allocate and initialize memsz-filesz gap
Date: Thu, 13 Aug 2009 12:55:12 +0300	[thread overview]
Message-ID: <20090813095512.GA6866@kos.to> (raw)
In-Reply-To: <200907121502.39025.jcmvbkbc@gmail.com>

On Sun, Jul 12, 2009 at 03:02:38PM +0400, Max Filippov wrote:
> I'm having ppc ELF binaries that I'm running on x86 in linux-user emulation.
> Some of these binaries work fine, but others segfault.
> The latter binaries have segments with p_filesz < p_memsz and sections like .bss in this gap.
> Segfaults usually happen in attempt to access address within this gap. 
> According to the linux-user/elfload.c only first p_filesz bytes of such segments are mmaped and mprotected.

> This patch mmaps p_memsz bytes and then zero out last p_memsz - p_filesz bytes of such segments.
> Is there a better way to do it?

After applying this patch, any arm-linux binaries on x86 fail run.

> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
> ---
> diff -burN qemu-snapshot-2009-07-11_r7249-orig/linux-user/elfload.c qemu-snapshot-2009-07-11_r7249/linux-user/elfload.c
> --- qemu-snapshot-2009-07-11_r7249-orig/linux-user/elfload.c	2009-07-11 06:12:23.000000000 +0400
> +++ qemu-snapshot-2009-07-11_r7249/linux-user/elfload.c	2009-07-12 04:47:47.000000000 +0400
> @@ -1380,7 +1380,7 @@
>          }
>  
>          error = target_mmap(TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr),
> -                            (elf_ppnt->p_filesz +
> +                            (elf_ppnt->p_memsz +
>                               TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr)),
>                              elf_prot,
>                              (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE),
> @@ -1392,6 +1392,20 @@
>              exit(-1);
>          }
>  
> +        if(elf_ppnt->p_memsz > elf_ppnt->p_filesz) {
> +            abi_ulong pg = TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr) +
> +                (elf_ppnt->p_filesz +
> +                 TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr));
> +            abi_ulong sz = elf_ppnt->p_memsz - elf_ppnt->p_filesz;
> +
> +            void *p = lock_user(PAGE_READ | PAGE_WRITE, pg, sz, 0);
> +
> +            if (p) {
> +                memset(p, 0, sz);
> +                unlock_user(p, pg, sz);
> +            }
> +        }
> +
>  #ifdef LOW_ELF_STACK
>          if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack)
>              elf_stack = TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr);
> 
> 
> Thanks.
> -- Max
> 

      reply	other threads:[~2009-08-13  9:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-12 11:02 [Qemu-devel] [PATCH] linux-user: elfload: allocate and initialize memsz-filesz gap Max Filippov
2009-08-13  9:55 ` Riku Voipio [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090813095512.GA6866@kos.to \
    --to=riku.voipio@iki.fi \
    --cc=jcmvbkbc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).