diff mbox series

[PULL,2/5] linux-user: Correctly start brk after executable

Message ID 20200907091748.376101-3-laurent@vivier.eu
State Accepted
Commit 8a0451886824fb266fbdcd1ca01d6acb023e3e09
Headers show
Series Linux user for 5.2 patches | expand

Commit Message

Laurent Vivier Sept. 7, 2020, 9:17 a.m. UTC
From: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>


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>

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

Message-Id: <20200728224615.326675-1-T.E.Baldwin99@members.leeds.ac.uk>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>

---
 linux-user/elfload.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

-- 
2.26.2
diff mbox series

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 04c28cbb9ecb..4961e6119e24 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2580,9 +2580,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;
@@ -2637,7 +2637,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()) {