From nobody Fri May 17 03:39:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+88456+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88456+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1649253126; cv=none; d=zohomail.com; s=zohoarc; b=AsAJ8JGh2cb/HxQdxI/PQrIl2/s3zhmR+qC3YoaOuWQy6lgbQ1yldtdVrp6Fd1joJh35abdeHiE9UQqoBLd/zX44yFYyUsADnIpUyfjeSE2scOByAbxAU48FVbpt1a2cMXGqpJTSM6+5RMWHlCBud62TtHwUIPk42j/sfYlQNL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649253126; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=JVfUaZ32ndDPAtnpQ52xv1Yc3513pb0ESKxzPDxPLe8=; b=aoCUpnto7Y3FswHuIwpAsSzMId85Be8MCtGBIUUJU1TA7DfN4a6zEpYws8/mxyVO5DRxLISq5qWcew5hmDuXel1iKsjXCkeZXGLUWZEyEjxsLBrdqAVrEpFXRWdAQZ/DOs8FluMr4nX7bU9HZXIYkIT0pG97CRHW3ZvvAxW/1fQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88456+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1649253126612985.0198074218118; Wed, 6 Apr 2022 06:52:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Dg8tYY1788612xL9Ds8m6XeT; Wed, 06 Apr 2022 06:52:06 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web09.8779.1649253124365465085 for ; Wed, 06 Apr 2022 06:52:05 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="286016648" X-IronPort-AV: E=Sophos;i="5.90,239,1643702400"; d="scan'208";a="286016648" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2022 06:52:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,239,1643702400"; d="scan'208";a="722521274" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.158]) by orsmga005.jf.intel.com with ESMTP; 06 Apr 2022 06:52:01 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Guo Dong , Ray Ni , Maurice Ma , Benjamin You , Sean Rhodes Subject: [edk2-devel] [PATCH] UefiPayloadPkg: Fix bug that Elf loader doesn't relocate in some case Date: Wed, 6 Apr 2022 21:51:55 +0800 Message-Id: <20220406135155.822-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhiguang.liu@intel.com X-Gm-Message-State: emb35XyBfyThTvtAi964eRSnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1649253126; bh=6ekCIDRcLId1ncOGug81/sPMapJ3ty3KvkIBNu03rDU=; h=Cc:Date:From:Reply-To:Subject:To; b=dITZ99fZWQcBxHaGmmzzlWNT5CIzbKPdLOL9ibKVB4I9eAdWJ2aPBtrU5WIZOx6GWZ3 XER9hUZZYKcSzoaXNUfTnzbZ74hQd8tAw26FWEd1T8RRPSwHRNSvYe6WpNgyswY2HcQfX zt/MMPcYn3v0kUeik442N2wPKkJpyb696eo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1649253128323100003 Content-Type: text/plain; charset="utf-8" Current implementation of the Elf loader reuses the same memory range if the desired memory range is covered by [file base, file base + file size]. However, there is a potentil bug, for example: If the first segment is located at 0x1000, and the desired address is 0x2000. While the second segment is located at 0x2000, and the desired address is 0x2000. When we parse and try to load the elf file, current implementation may load the first segment at 0x2000, and override second segment. Cc: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Cc: Sean Rhodes Signed-off-by: Zhiguang Liu Reviewed-by: Guo Dong --- UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c b/UefiPayload= Pkg/PayloadLoaderPeim/ElfLib/ElfLib.c index 2a6305c67b..c7dfae14af 100644 --- a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c +++ b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/ElfLib.c @@ -312,6 +312,13 @@ ParseElfImage ( ElfCt->ReloadRequired =3D TRUE; } =20 + if (SegInfo.MemAddr !=3D ((UINTN)ElfCt->FileBase + SegInfo.Offset)) { + // + // Need to relocate if the desired address is not the current address + // + ElfCt->ReloadRequired =3D TRUE; + } + if (Base > (SegInfo.MemAddr & ~(EFI_PAGE_SIZE - 1))) { Base =3D SegInfo.MemAddr & ~(EFI_PAGE_SIZE - 1); } --=20 2.32.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88456): https://edk2.groups.io/g/devel/message/88456 Mute This Topic: https://groups.io/mt/90289885/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-