From nobody Tue Nov 18 18:25:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=xes-inc.com ARC-Seal: i=1; a=rsa-sha256; t=1612074743; cv=none; d=zohomail.com; s=zohoarc; b=FdgmG8I0WdcqCYp9/2+ZBxObYXok0pRN5RUR0pcHIahmN1gEF/Y4BZqYMv75Y9AtInFgFGwfE2WUsjwOtccR421ZZesY5n2E7qt5jy3L9UZOYCV55qxwEnnwE9VDOAaSX/axepC10KTTqBfeu1Ho0+EB4nGdu9UeAU9+6+ZjhkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612074743; 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=UeH+AN9Hm0yKwkXEz8Yr97TclujVKHtV9+sHtDCwxGQ=; b=Vwc88C2XzHMnmPfKOAwJF28acmII48luz6b+5/7xa2ZpUzmMz00NUutKfZc5EDkNzfZRWKDFrutI9JeGFcRwktncohofQUCVomLAXQikZui3doicNO6bKPjPMfusOLY1e5kp9DlXmidVv7+jdvHLC9g6VxwOpeG6x7QDB8i2Sa0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1612074743818763.3955580543179; Sat, 30 Jan 2021 22:32:23 -0800 (PST) Received: from localhost ([::1]:53842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l66HW-0006xD-NC for importer@patchew.org; Sun, 31 Jan 2021 01:32:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l66Bh-0002GB-J0; Sun, 31 Jan 2021 01:26:21 -0500 Received: from [162.248.234.2] (port=12362 helo=mail.xes-mad.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l66Bf-0004TU-AL; Sun, 31 Jan 2021 01:26:20 -0500 Received: from vfazio1.xes-mad.com (vfazio1.xes-mad.com [10.52.16.140]) by mail.xes-mad.com (Postfix) with ESMTP id D95F12039A; Sun, 31 Jan 2021 00:19:53 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1612073993; bh=QdD3u/iRN0rpMXWQy24nSf8fb5h2Oe01FIKMhkaF85Q=; h=From:To:Cc:Subject:Date:From; b=WJKm4czHW8cMTAetfSTDQiHGnAVpYWYU9QANuwN+U4yiPA/4qTTYlKxxIvTVPRdG0 l+C5E8pXArjrGNo5iAGv5U4lCkitMzPwPSuSrmQc12rzZdALq4AcA1c7FGdzZJtmpH fJMOA10RSDllgNIyEMSW+5MNY9WDviw6OfFyTqdM= From: Vincent Fazio To: qemu-devel@nongnu.org Subject: [PATCH] linux-user/elfload: fix address calculation in fallback scenario Date: Sun, 31 Jan 2021 00:19:48 -0600 Message-Id: <20210131061948.15990-1-vfazio@xes-inc.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 162.248.234.2 (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: pass client-ip=162.248.234.2; envelope-from=vfazio@xes-inc.com; helo=mail.xes-mad.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu-trivial@nongnu.org, laurent@vivier.eu, Vincent Fazio Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vincent Fazio Previously, guest_loaddr was not taken into account when returning an address from pgb_find_hole when /proc/self/maps was unavailable which caused an improper guest_base address to be calculated. This could cause a SIGSEGV later in load_elf_image -> target_mmap for ET_EXEC type images since the mmap MAP_FIXED flag is specified which could clobber existing mappings at the address returnd by g2h(). mmap(0xd87000, 16846912, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESER= VE|0x100000, -1, 0) =3D 0xd87000 munmap(0xd87000, 16846912) =3D 0 write(2, "Locating guest address space @ 0"..., 40Locating guest address = space @ 0xd87000) =3D 40 mmap(0x1187000, 16850944, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|= MAP_NORESERVE, -1, 0) =3D 0x1187000 --- SIGSEGV {si_signo=3DSIGSEGV, si_code=3DSEGV_ACCERR, si_addr=3D0x21883= 10} --- +++ killed by SIGSEGV +++ Now, pgd_find_hole accounts for guest_loaddr in this scenario. Fixes: ad592e37dfcc ("linux-user: provide fallback pgd_find_hole for bare c= hroots") Signed-off-by: Vincent Fazio Reviewed-by: Laurent Vivier --- linux-user/elfload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8d425f9ed0..6d606b9442 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2242,7 +2242,8 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr= , uintptr_t guest_size, brk =3D (uintptr_t)sbrk(0); =20 if (!maps) { - return pgd_find_hole_fallback(guest_size, brk, align, offset); + ret =3D pgd_find_hole_fallback(guest_size, brk, align, offset); + return ret - guest_loaddr; } =20 /* The first hole is before the first map entry. */ --=20 2.30.0