All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user: Correctly start brk after executable
@ 2020-07-28 22:46 Timothy E Baldwin
  2020-07-29 15:47 ` Richard Henderson
  2020-09-05 20:51 ` Laurent Vivier
  0 siblings, 2 replies; 3+ messages in thread
From: Timothy E Baldwin @ 2020-07-28 22:46 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel; +Cc: Timothy E Baldwin

info->brk was erroneously set to the end of highest addressed
writable segment which could result it in overlapping the executable.

As per load_elf_binary in fs/binfmt_elf.c in Linux, it should be
set to end of highest addressed segment.

Signed-off-by: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>
---
 linux-user/elfload.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7e7f642332..d5d444f698 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2564,9 +2564,9 @@ static void load_elf_image(const char *image_name, int image_fd,
                 if (vaddr_ef > info->end_data) {
                     info->end_data = vaddr_ef;
                 }
-                if (vaddr_em > info->brk) {
-                    info->brk = vaddr_em;
-                }
+            }
+            if (vaddr_em > info->brk) {
+                info->brk = vaddr_em;
             }
         } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
             char *interp_name;
@@ -2621,7 +2621,6 @@ static void load_elf_image(const char *image_name, int image_fd,
     if (info->end_data == 0) {
         info->start_data = info->end_code;
         info->end_data = info->end_code;
-        info->brk = info->end_code;
     }
 
     if (qemu_log_enabled()) {
-- 
2.25.1

Given an executable with a read-write segment between 2 executable segments
qemu was unmapping most of the execuateble instead of area reserved for brk
at the end of the execuatable.


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user: Correctly start brk after executable
  2020-07-28 22:46 [PATCH] linux-user: Correctly start brk after executable Timothy E Baldwin
@ 2020-07-29 15:47 ` Richard Henderson
  2020-09-05 20:51 ` Laurent Vivier
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2020-07-29 15:47 UTC (permalink / raw)
  To: Timothy E Baldwin, Laurent Vivier, qemu-devel

On 7/28/20 3:46 PM, Timothy E Baldwin wrote:
> info->brk was erroneously set to the end of highest addressed
> writable segment which could result it in overlapping the executable.
> 
> As per load_elf_binary in fs/binfmt_elf.c in Linux, it should be
> set to end of highest addressed segment.
> 
> Signed-off-by: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>
> ---
>  linux-user/elfload.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user: Correctly start brk after executable
  2020-07-28 22:46 [PATCH] linux-user: Correctly start brk after executable Timothy E Baldwin
  2020-07-29 15:47 ` Richard Henderson
@ 2020-09-05 20:51 ` Laurent Vivier
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2020-09-05 20:51 UTC (permalink / raw)
  To: Timothy E Baldwin, qemu-devel

Le 29/07/2020 à 00:46, Timothy E Baldwin a écrit :
> info->brk was erroneously set to the end of highest addressed
> writable segment which could result it in overlapping the executable.
> 
> As per load_elf_binary in fs/binfmt_elf.c in Linux, it should be
> set to end of highest addressed segment.
> 
> Signed-off-by: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>
> ---
>  linux-user/elfload.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 7e7f642332..d5d444f698 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2564,9 +2564,9 @@ static void load_elf_image(const char *image_name, int image_fd,
>                  if (vaddr_ef > info->end_data) {
>                      info->end_data = vaddr_ef;
>                  }
> -                if (vaddr_em > info->brk) {
> -                    info->brk = vaddr_em;
> -                }
> +            }
> +            if (vaddr_em > info->brk) {
> +                info->brk = vaddr_em;
>              }
>          } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
>              char *interp_name;
> @@ -2621,7 +2621,6 @@ static void load_elf_image(const char *image_name, int image_fd,
>      if (info->end_data == 0) {
>          info->start_data = info->end_code;
>          info->end_data = info->end_code;
> -        info->brk = info->end_code;
>      }
>  
>      if (qemu_log_enabled()) {
> 

Applied to my linux-user-for-5.2 branch.

Thanks,
Laurent




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-05 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 22:46 [PATCH] linux-user: Correctly start brk after executable Timothy E Baldwin
2020-07-29 15:47 ` Richard Henderson
2020-09-05 20:51 ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.