From nobody Thu Apr 25 23:55:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=members.leeds.ac.uk ARC-Seal: i=1; a=rsa-sha256; t=1595977586; cv=none; d=zohomail.com; s=zohoarc; b=NsrHT2Uyy2mj3Ub6I7DGnRPsQ+T5jk34CVmoPO19CcWlJcg/zYBdWCRwdfPisQlYxHedJpaeohePRFqk2xTrOw3w+CWUXLp0VzycD1ZH+2eqXnzSEHHCbhK3cRFWqH34/SSfX5K6idqfraAfTx84WHTvi0iriERhnQJQwIQW2HA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595977586; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=92dG9jZ2wb8mryRahKFuljKouUbwOU7y6P7GNPzazZE=; b=RNNfJhSZbWv5fsTU/oFGd1MSE1i3hWHydwgg6F1jwfohM7OLIrbK0XJtmZfWrp1LGjNNyP629C41TNTGvbsWUM3lQ65imOwOl3dbYbPkv3cW+ASwteepVByAPsLV+TQLf/RauyyyRceyLaL2cgk6ROUuB2aublxq79XgXZuwpMY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595977586005282.7407813347428; Tue, 28 Jul 2020 16:06:26 -0700 (PDT) Received: from localhost ([::1]:51908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k0Yfw-0006lg-T7 for importer@patchew.org; Tue, 28 Jul 2020 19:06:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0YeR-0005pA-1w for qemu-devel@nongnu.org; Tue, 28 Jul 2020 19:04:51 -0400 Received: from [31.132.33.241] (port=47098 helo=pi.majoroak.me.uk) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0YeP-0003W1-3A for qemu-devel@nongnu.org; Tue, 28 Jul 2020 19:04:50 -0400 Received: from [2001:470:1f09:8f6:2e0:4cff:fe39:267e] (helo=localhost.localdomain) by pi.majoroak.me.uk with esmtp (Exim 4.92) (envelope-from ) id 1k0YMa-0000mh-VC; Tue, 28 Jul 2020 23:46:37 +0100 From: Timothy E Baldwin To: Laurent Vivier , qemu-devel@nongnu.org Date: Tue, 28 Jul 2020 23:46:15 +0100 Message-Id: <20200728224615.326675-1-T.E.Baldwin99@members.leeds.ac.uk> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2001:470:1f09:8f6:2e0:4cff:fe39:267e X-SA-Exim-Mail-From: T.E.Baldwin99@members.leeds.ac.uk Subject: [PATCH] linux-user: Correctly start brk after executable X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on pi.majoroak.me.uk) X-Host-Lookup-Failed: Reverse DNS lookup failed for 31.132.33.241 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=31.132.33.241; envelope-from=T.E.Baldwin99@members.leeds.ac.uk; helo=pi.majoroak.me.uk X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/28 18:46:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Timothy E Baldwin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Richard Henderson --- 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, in= t image_fd, if (vaddr_ef > info->end_data) { info->end_data =3D vaddr_ef; } - if (vaddr_em > info->brk) { - info->brk =3D vaddr_em; - } + } + if (vaddr_em > info->brk) { + info->brk =3D vaddr_em; } } else if (eppnt->p_type =3D=3D PT_INTERP && pinterp_name) { char *interp_name; @@ -2621,7 +2621,6 @@ static void load_elf_image(const char *image_name, in= t image_fd, if (info->end_data =3D=3D 0) { info->start_data =3D info->end_code; info->end_data =3D info->end_code; - info->brk =3D info->end_code; } =20 if (qemu_log_enabled()) { --=20 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.