From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.1673.1625027394223677506 for ; Tue, 29 Jun 2021 21:29:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=B/1sziDl; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: guo.dong@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10030"; a="272141614" X-IronPort-AV: E=Sophos;i="5.83,311,1616482800"; d="scan'208";a="272141614" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2021 21:29:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,311,1616482800"; d="scan'208";a="457064854" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga008.fm.intel.com with ESMTP; 29 Jun 2021 21:29:51 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 29 Jun 2021 21:29:50 -0700 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 29 Jun 2021 21:29:50 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Tue, 29 Jun 2021 21:29:50 -0700 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.40) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.4; Tue, 29 Jun 2021 21:29:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B0jPOkst499xqoN3JwBS/xVD3avCOETLlbvJYRP4lZ22xZY71ia9bNAe9R9w6bITQFZPVwClTmJpP8YG1cG49gJZJt6si46Y9Ix3npETbzimUdVQ+Sw/Tde1xeg96l5EbQ+x0p2fXfs69icvh9cNuF34oF2z5mh4pCKcWEOkyCnh9YW0lM0duhfVkVFiNiRPGoVIQBfzRiUrV3QdOgr2AZ8SYITn6d6TrrxE0DJe3bD2ZfdP+QV0lCnH5dE59AXLEcPtRV4m/SXMXVtcLOSjkz77naQ4oWBFn0XIunKoBQa/M2QG4Iamw4CkqvP2myJYp96oXurzpg8H0rKuAD5u0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LgBBnr2WOxPzJXvzD/4uofligHfWBPq2hRBeqoZx/JY=; b=YY6Kh0SmmUqVyJXYqUygQal6wLDSxJP3eoh/zEjhbz+AQnC/Rt2o0QxanUdZ6RzA+oY6LXwgyBytAidZou4fgi8H8EyB2dlaTuAd2PcWCW8mhnZI8wSWpiN828Pdnz2z5ESHeXWIM1G0sV96lpRumiptKhh/j1XIeA4eWWUkD+e3TUgoky6WRoNZXWSPCwIU/NBbcnPLh1bzyqSQizA4HTml6NQZij6xtEmo0MiGe/4J9V2MCh/CSU/g048ehlS1ry0iJ0qAI8ee4hhhlfu5KIYCPUa/i/2K9UePaZ/Hdk1KThJmsc0yEmXXwJsokgkCIYXgaVCuLa/dfEY8h+UsNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LgBBnr2WOxPzJXvzD/4uofligHfWBPq2hRBeqoZx/JY=; b=B/1sziDlrWRSxO97EvXRCnd6uRfI4e+QnW2JGhm1fExQpV8G0VKtZYbYsTHwbxV3oNSpOVc7c3A+yrBN2hwDyyg4y/EQjkLZv4cec62DNR3RZZu4UwXRvhM1uNh+Mmw5PSu9ET8P5t1MgJPXwJnZoZUaO/VWN8qwvZck4zOLGsQ= Received: from BYAPR11MB3622.namprd11.prod.outlook.com (2603:10b6:a03:fe::30) by BYAPR11MB2726.namprd11.prod.outlook.com (2603:10b6:a02:be::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Wed, 30 Jun 2021 04:29:48 +0000 Received: from BYAPR11MB3622.namprd11.prod.outlook.com ([fe80::247b:262c:b8da:710b]) by BYAPR11MB3622.namprd11.prod.outlook.com ([fe80::247b:262c:b8da:710b%7]) with mapi id 15.20.4264.027; Wed, 30 Jun 2021 04:29:48 +0000 From: "Guo Dong" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Ma, Maurice" , "You, Benjamin" Subject: Re: [PATCH 1/2] UefiPayloadPkg/PayloadLoader: Fix bug in locating relocation section Thread-Topic: [PATCH 1/2] UefiPayloadPkg/PayloadLoader: Fix bug in locating relocation section Thread-Index: AQHXbK/i6tKZg5FgH0CXQMQOztDBXasr97VQ Date: Wed, 30 Jun 2021 04:29:47 +0000 Message-ID: References: <20210629062707.1855-1-ray.ni@intel.com> <20210629062707.1855-2-ray.ni@intel.com> In-Reply-To: <20210629062707.1855-2-ray.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [68.104.146.79] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 41d8cd61-0ae3-4f1f-72a8-08d93b7fb1d5 x-ms-traffictypediagnostic: BYAPR11MB2726: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: T3XJ94jnXiG+1K0kbTEe2eoPOp3C1nUuai3p2aJU1qBrjEupkgsnytHN1OfAXBivfxkJcjq/ddB9A9CXqaGPW8olls3RfIU7rgClnApz7uFonzqAFagEQS+5cFBDTknhdVQCItmuy3dULrW7csNG7PZxT+j/M3ERUzVEVnPmJ0D5PI4E2vJgE2EFZIE/afFxUCTyce/kpZ17Gm1rRe9yJ0NFwkew7Ks73aKRD/zz63O7tPGNYNX8GzkJfQY6+Q/ElWxSAUlQMFUOQWApZ7LInwXZ2YdfUsIyon4KIDoork4Zp0tqb5kXpYCMe7FDYMSOi/wjJeYoahG9HwCRK8vipNL0A+kEF0oOT25hGRW8hwJ2wvsnhG0wuv9hVEJDkx5aJofQr37ni+UimZjcoAS8g0pYt6Hk7wofvLgepi31lc6AMwZJDldyjebv2koA83UA1Gds5RwFnZBQjPDGS3pU3AJl6y5Kr0QoftXt8DMJeXDQfBAdVqxZOHcDBUQv62YTSUO+fZUGKsmkscjdKrV4DWKEP1omiz3Jn30Y8AQj2QEiWK3PI0QnuD564EyYbZ6viPiPNP6UEF9js9eQNuQBCSSxNgdFr9uSkuEjR30Mu4TqTUM+a7XMrPiNxkmwoAhYUSs5Q0yhgLwhbQ32QenPgw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR11MB3622.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(376002)(346002)(396003)(39860400002)(136003)(7696005)(5660300002)(2906002)(478600001)(66446008)(66556008)(66476007)(6506007)(8676002)(86362001)(8936002)(53546011)(64756008)(66946007)(76116006)(110136005)(26005)(55016002)(107886003)(9686003)(19627235002)(316002)(4326008)(83380400001)(52536014)(122000001)(38100700002)(71200400001)(186003)(54906003)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?CNuthy907o5VJp+N0/r4cXjBEcSO/AgwSko2UElVmyV1POJ5a+PimGxdde42?= =?us-ascii?Q?grtr8eLzFlQdxTfqj/WO8J8GQmPkAVHOMUEkIoCO78ZqfdanYWntb/K3U71y?= =?us-ascii?Q?CSuNE82/zAHHtEb6wBN1X2jr5klR4e6FL020kXSHcHN1o/tUL6Q3k0nuGeeq?= =?us-ascii?Q?asqJTyVMAxCkiqC657POdz02mizZy/VvPmZOk5TH4V+aeMHjQ1E2Iaiw71bH?= =?us-ascii?Q?Vz7kK9yNdUpzxHr+GKvAdwi+Yn6tb4BWE3yB2jXer8enxA2qZNmX61t//NOW?= =?us-ascii?Q?oig1ecJLr3tbGfpW7tvz18h00Q1rWwvzWI5kcUY/2ke7ExZJ9vLTdZIQobuS?= =?us-ascii?Q?q3vgcW3kzBPbStuDt8qRnN+F2q/lp264h6L+EnwhRqt/JGooba+4Sq90SspB?= =?us-ascii?Q?/t+jsdbMJtHS28LUcpbqPekIlpMVN4U1ZIoBJ0eTLg0fhRXPxaA5Xq6OVgZT?= =?us-ascii?Q?ALucWD8Ffa5N9TDGcwCuJSsdJFXsoDpN8pa1648qEO83yebFR5xl4jkn0fgR?= =?us-ascii?Q?5LDMT9yULBCLwAYHVEBEaReESQXiwZexibr6rYnQawyD2yueLpsfUXonZA7Y?= =?us-ascii?Q?xPuu2OF9C4Oig94LzJsoITU0Bl2uCxWWWF7yKxHRP2TXb7h4wkc7oJqSL8b9?= =?us-ascii?Q?1OklAuH1oXEY/9QR4yB+BRScpmfUusOafZpslWF7BPevBHW/xXAWZ1nD7GTI?= =?us-ascii?Q?eSPG6pdWpgNGzTDrswlXwdrNbyci7xJNdn2ItX9p6yIcXj+7SOp0sf3hDuJH?= =?us-ascii?Q?x+8ldPRd8runNJd+m01xllTznH+1pa5/s62wgP8Ngka1jpWhXCOfCz3Nr3Z0?= =?us-ascii?Q?szcVb8wvn7ItdNHBLlr5BW/srge4RmGy+0r+SlJUs7PMnzdbDfTFG9g6Nx9r?= =?us-ascii?Q?8uliJIZ/RX9XrpBycanH1rxXUY9Dkw3PfWUO2av6vcFJD5uCrwNT8ZerNJiA?= =?us-ascii?Q?4fi98q014GQWNzd871n6kAXc7h14lRON82EZ99EZQkJec8Ubo3mvV7PWYc4X?= =?us-ascii?Q?cZaQSFTmJlPj5OLFSufAfa8NR1FCiai6Cbiq2lF3dtyt5QQkEbawbmHQLft2?= =?us-ascii?Q?y93VT4bZRVVIUdGC/KFVO9+cKSSTOmrTBeKobuPmvA3t9Wsbot2IfdtpuMqG?= =?us-ascii?Q?S9tSbtjNFQKgME3KVIWh2d/Z7pgnxjm8RShxlTmyDjE7Kvzxf+7XEPWNiMMO?= =?us-ascii?Q?Zdy+0HqNQo4Ygc8U9L9Pm6diN4dZzVDUJbS99aImftdxCQ3dJYfHEoAQmyn5?= =?us-ascii?Q?WFSc4nKnfdSBhts2ZAnc44JSeUpaCE5gNPV201WuFZPtzDpGucm7LdFEQvgz?= =?us-ascii?Q?7mY69NEN47T016oNg449LlwC?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3622.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41d8cd61-0ae3-4f1f-72a8-08d93b7fb1d5 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jun 2021 04:29:47.8427 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: t6G1R5nZyvw7B+BfbIMqKPcAzSJ+B7f1VfBh41UNOyoxkV7g5BwZq5Yg3CBW74JCeycbnBkewDFwRNpf88yD+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB2726 Return-Path: guo.dong@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Guo Dong > -----Original Message----- > From: Ni, Ray > Sent: Monday, June 28, 2021 11:27 PM > To: devel@edk2.groups.io > Cc: Ma, Maurice ; Dong, Guo > ; You, Benjamin > Subject: [PATCH 1/2] UefiPayloadPkg/PayloadLoader: Fix bug in locating > relocation section >=20 > Per ELF spec, the DT_REL/DT_RELA tag in dynamic section stores the > virtual address of the relocation section. >=20 > But today's code logic treats it as the section offset and finds > the relocation section whose offset equals to DT_REL/DT_RELA. >=20 > The logic can work when the section offset equals to the section > virtual address. But when the ELF is generated from the link script > that reserves a sizeof(pe_header) in the file beginning, the section > offset doesn't equal to section virtual address. Such logic can > not find the relocation section. >=20 > The patch fixes this bug. >=20 > Signed-off-by: Ray Ni > Cc: Maurice Ma > Cc: Guo Dong > Cc: Benjamin You > --- > .../PayloadLoaderPeim/ElfLib/Elf32Lib.c | 22 +++++++++++++------ > .../PayloadLoaderPeim/ElfLib/Elf64Lib.c | 22 +++++++++++++------ > 2 files changed, 30 insertions(+), 14 deletions(-) >=20 > diff --git a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf32Lib.c > b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf32Lib.c > index 3fa100ce4a..dd27d3ce59 100644 > --- a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf32Lib.c > +++ b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf32Lib.c > @@ -206,7 +206,7 @@ RelocateElf32Dynamic ( > Elf32_Shdr *DynShdr; >=20 > Elf32_Shdr *RelShdr; >=20 > Elf32_Dyn *Dyn; >=20 > - UINT32 RelaOffset; >=20 > + UINT32 RelaAddress; >=20 > UINT32 RelaCount; >=20 > UINT32 RelaSize; >=20 > UINT32 RelaEntrySize; >=20 > @@ -246,7 +246,7 @@ RelocateElf32Dynamic ( > // >=20 > // 2. Locate the relocation section from the dynamic section. >=20 > // >=20 > - RelaOffset =3D MAX_UINT32; >=20 > + RelaAddress =3D MAX_UINT32; >=20 > RelaSize =3D 0; >=20 > RelaCount =3D 0; >=20 > RelaEntrySize =3D 0; >=20 > @@ -265,8 +265,8 @@ RelocateElf32Dynamic ( > // based on the original file value and the memory base address. >=20 > // For consistency, files do not contain relocation entries to `= `correct'' > addresses in the dynamic structure. >=20 > // >=20 > - RelaOffset =3D Dyn->d_un.d_ptr - (UINT32) (UINTN) ElfCt- > >PreferredImageAddress; >=20 > - RelaType =3D (Dyn->d_tag =3D=3D DT_RELA) ? SHT_RELA: SHT_REL; >=20 > + RelaAddress =3D Dyn->d_un.d_ptr; >=20 > + RelaType =3D (Dyn->d_tag =3D=3D DT_RELA) ? SHT_RELA: SHT_REL; >=20 > break; >=20 > case DT_RELACOUNT: >=20 > case DT_RELCOUNT: >=20 > @@ -285,7 +285,7 @@ RelocateElf32Dynamic ( > } >=20 > } >=20 >=20 >=20 > - if (RelaOffset =3D=3D MAX_UINT64) { >=20 > + if (RelaAddress =3D=3D MAX_UINT64) { >=20 > ASSERT (RelaCount =3D=3D 0); >=20 > ASSERT (RelaEntrySize =3D=3D 0); >=20 > ASSERT (RelaSize =3D=3D 0); >=20 > @@ -298,8 +298,16 @@ RelocateElf32Dynamic ( > // >=20 > // Verify the existence of the relocation section. >=20 > // >=20 > - RelShdr =3D GetElf32SectionByRange (ElfCt->FileBase, RelaOffset, RelaS= ize); >=20 > - ASSERT (RelShdr !=3D NULL); >=20 > + RelShdr =3D NULL; >=20 > + for (Index =3D 0; Index < ElfCt->ShNum; Index++) { >=20 > + RelShdr =3D GetElf32SectionByIndex (ElfCt->FileBase, Index); >=20 > + ASSERT (RelShdr !=3D NULL); >=20 > + if ((RelShdr->sh_addr =3D=3D RelaAddress) && (RelShdr->sh_size =3D= =3D RelaSize)) > { >=20 > + break; >=20 > + } >=20 > + RelShdr =3D NULL; >=20 > + } >=20 > + >=20 > if (RelShdr =3D=3D NULL) { >=20 > return EFI_UNSUPPORTED; >=20 > } >=20 > diff --git a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c > b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c > index e364807007..3f4f12903c 100644 > --- a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c > +++ b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c > @@ -215,7 +215,7 @@ RelocateElf64Dynamic ( > Elf64_Shdr *DynShdr; >=20 > Elf64_Shdr *RelShdr; >=20 > Elf64_Dyn *Dyn; >=20 > - UINT64 RelaOffset; >=20 > + UINT64 RelaAddress; >=20 > UINT64 RelaCount; >=20 > UINT64 RelaSize; >=20 > UINT64 RelaEntrySize; >=20 > @@ -255,7 +255,7 @@ RelocateElf64Dynamic ( > // >=20 > // 2. Locate the relocation section from the dynamic section. >=20 > // >=20 > - RelaOffset =3D MAX_UINT64; >=20 > + RelaAddress =3D MAX_UINT64; >=20 > RelaSize =3D 0; >=20 > RelaCount =3D 0; >=20 > RelaEntrySize =3D 0; >=20 > @@ -274,8 +274,8 @@ RelocateElf64Dynamic ( > // based on the original file value and the memory base address. >=20 > // For consistency, files do not contain relocation entries to `= `correct'' > addresses in the dynamic structure. >=20 > // >=20 > - RelaOffset =3D Dyn->d_un.d_ptr - (UINTN) ElfCt->PreferredImageAd= dress; >=20 > - RelaType =3D (Dyn->d_tag =3D=3D DT_RELA) ? SHT_RELA: SHT_REL; >=20 > + RelaAddress =3D Dyn->d_un.d_ptr; >=20 > + RelaType =3D (Dyn->d_tag =3D=3D DT_RELA) ? SHT_RELA: SHT_REL; >=20 > break; >=20 > case DT_RELACOUNT: >=20 > case DT_RELCOUNT: >=20 > @@ -294,7 +294,7 @@ RelocateElf64Dynamic ( > } >=20 > } >=20 >=20 >=20 > - if (RelaOffset =3D=3D MAX_UINT64) { >=20 > + if (RelaAddress =3D=3D MAX_UINT64) { >=20 > ASSERT (RelaCount =3D=3D 0); >=20 > ASSERT (RelaEntrySize =3D=3D 0); >=20 > ASSERT (RelaSize =3D=3D 0); >=20 > @@ -307,8 +307,16 @@ RelocateElf64Dynamic ( > // >=20 > // Verify the existence of the relocation section. >=20 > // >=20 > - RelShdr =3D GetElf64SectionByRange (ElfCt->FileBase, RelaOffset, RelaS= ize); >=20 > - ASSERT (RelShdr !=3D NULL); >=20 > + RelShdr =3D NULL; >=20 > + for (Index =3D 0; Index < ElfCt->ShNum; Index++) { >=20 > + RelShdr =3D GetElf64SectionByIndex (ElfCt->FileBase, Index); >=20 > + ASSERT (RelShdr !=3D NULL); >=20 > + if ((RelShdr->sh_addr =3D=3D RelaAddress) && (RelShdr->sh_size =3D= =3D RelaSize)) > { >=20 > + break; >=20 > + } >=20 > + RelShdr =3D NULL; >=20 > + } >=20 > + >=20 > if (RelShdr =3D=3D NULL) { >=20 > return EFI_UNSUPPORTED; >=20 > } >=20 > -- > 2.31.1.windows.1