qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk>,
	Richard Henderson <richard.henderson@linaro.org>,
	Laurent Vivier <laurent@vivier.eu>
Subject: [PULL 2/5] linux-user: Correctly start brk after executable
Date: Mon,  7 Sep 2020 11:17:45 +0200	[thread overview]
Message-ID: <20200907091748.376101-3-laurent@vivier.eu> (raw)
In-Reply-To: <20200907091748.376101-1-laurent@vivier.eu>

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(-)

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()) {
-- 
2.26.2



  parent reply	other threads:[~2020-09-07  9:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-07  9:17 [PULL 0/5] Linux user for 5.2 patches Laurent Vivier
2020-09-07  9:17 ` [PULL 1/5] linux-user: Add support for ppoll_time64() and pselect6_time64() Laurent Vivier
2020-09-07  9:17 ` Laurent Vivier [this message]
2020-09-07  9:17 ` [PULL 3/5] linux-user: Map signal numbers in fcntl Laurent Vivier
2020-09-07  9:17 ` [PULL 4/5] linux-user: fix ppc/termbits.h Laurent Vivier
2020-09-07  9:17 ` [PULL 5/5] linux-user: Protect btrfs ioctl target definitions Laurent Vivier
2020-09-07 15:50 ` [PULL 0/5] Linux user for 5.2 patches Peter Maydell

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=20200907091748.376101-3-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=T.E.Baldwin99@members.leeds.ac.uk \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).