From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 275FF211BA47D for ; Wed, 30 Jan 2019 19:38:18 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2019 19:38:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,543,1539673200"; d="scan'208";a="120853863" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga008.fm.intel.com with ESMTP; 30 Jan 2019 19:38:17 -0800 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 30 Jan 2019 19:38:17 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 30 Jan 2019 19:38:17 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by shsmsx102.ccr.corp.intel.com ([169.254.2.207]) with mapi id 14.03.0415.000; Thu, 31 Jan 2019 11:38:14 +0800 From: "Gao, Liming" To: "Gao, Liming" , "Bi, Dandan" , "Hsueh, Hong-chihX" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , Laszlo Ersek Thread-Topic: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if reloc info is invalid Thread-Index: AQHUuDng0Kn8sXlFaU29E2i+s4fp86XIANoAgAC5XRCAAAIQsA== Date: Thu, 31 Jan 2019 03:38:14 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3D3D66@SHSMSX104.ccr.corp.intel.com> References: <20190130011936.5804-1-hong-chihx.hsueh@intel.com> <3C0D5C461C9E904E8F62152F6274C0BB40B8EFC5@SHSMSX104.ccr.corp.intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E3D3D37@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3D3D37@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZWE1ZWY3ZjctZGEyMy00Nzc0LTgxMTMtMzllMmY0NWI3NTU3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoidFpiVU5jV05BXC9Xa2R3bVkzOFluNzFPbCtxd2J1bUFXUGs0aGlJcGpzYko1Um5hY2RRWE9ZMzZSNk0zSkJicXYifQ== dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if reloc info is invalid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2019 03:38:18 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Push at a824c7ebde0a431413329049252b8c1d3770de82 > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ga= o, Liming > Sent: Thursday, January 31, 2019 11:31 AM > To: Bi, Dandan ; Hsueh, Hong-chihX ; edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Laszlo Ersek > Subject: Re: [edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation= if reloc info is invalid >=20 > Reviewed-by: Liming Gao >=20 > > -----Original Message----- > > From: Bi, Dandan > > Sent: Thursday, January 31, 2019 8:27 AM > > To: Hsueh, Hong-chihX ; edk2-devel@lists.01= .org > > Cc: Kinney, Michael D ; Gao, Liming ; Laszlo Ersek > > Subject: RE: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if r= eloc info is invalid > > > > Reviewed-by: Bi Dandan > > > > Thanks, > > Dandan > > > -----Original Message----- > > > From: Hsueh, Hong-chihX > > > Sent: Wednesday, January 30, 2019 9:20 AM > > > To: edk2-devel@lists.01.org > > > Cc: Kinney, Michael D ; Gao, Liming > > > ; Bi, Dandan ; Laszlo Erse= k > > > > > > Subject: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if rel= oc info > > > is invalid > > > > > > Skip runtime relocation for PE images that provide invalid relocation > > > infomation (ex: RelocDir->Size =3D 0) to fix a hang observed while bo= oting > > > Windows. > > > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > > Signed-off-by: Neo Hsueh > > > Cc: Michael D Kinney > > > Cc: Liming Gao > > > Cc: Dandan Bi > > > Cc: Laszlo Ersek > > > --- > > > MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 30 > > > ++++++++++++++++++++---------- > > > 1 file changed, 20 insertions(+), 10 deletions(-) > > > > > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > > > b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > > > index 1bd079ad6a..e2c62e1932 100644 > > > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > > > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > > > @@ -1002,7 +1002,7 @@ PeCoffLoaderRelocateImage ( > > > = RelocDir->VirtualAddress + RelocDir- > > > >Size - 1, > > > = TeStrippedOffset > > > = ); > > > - if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || RelocBa= seEnd < > > > RelocBase) { > > > + if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || (UINTN) > > > + RelocBaseEnd < (UINTN) RelocBase) { > > > ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; > > > return RETURN_LOAD_ERROR; > > > } > > > @@ -1022,7 +1022,7 @@ PeCoffLoaderRelocateImage ( > > > // Run the relocation information and apply the fixups > > > // > > > FixupData =3D ImageContext->FixupData; > > > - while (RelocBase < RelocBaseEnd) { > > > + while ((UINTN) RelocBase < (UINTN) RelocBaseEnd) { > > > > > > Reloc =3D (UINT16 *) ((CHAR8 *) RelocBase + sizeof > > > (EFI_IMAGE_BASE_RELOCATION)); > > > // > > > @@ -1051,7 +1051,7 @@ PeCoffLoaderRelocateImage ( > > > // > > > // Run this relocation record > > > // > > > - while (Reloc < RelocEnd) { > > > + while ((UINTN) Reloc < (UINTN) RelocEnd) { > > > Fixup =3D PeCoffLoaderImageAddress (ImageContext, RelocBase- > > > >VirtualAddress + (*Reloc & 0xFFF), TeStrippedOffset); > > > if (Fixup =3D=3D NULL) { > > > ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION= ; > > > @@ -1739,13 +1739,23 @@ PeCoffLoaderRelocateImageForRuntime ( > > > // is present in the image. You have to check the NumberOfRvaAndSi= zes in > > > // the optional header to verify a desired directory entry is ther= e. > > > // > > > + RelocBase =3D NULL; > > > + RelocBaseEnd =3D NULL; > > > if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { > > > RelocDir =3D DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASE= RELOC; > > > - RelocBase =3D (EFI_IMAGE_BASE_RELOCATION *) > > > PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0)= ; > > > - RelocBaseEnd =3D (EFI_IMAGE_BASE_RELOCATION *) > > > PeCoffLoaderImageAddress (&ImageContext, > > > - = RelocDir->VirtualAddress + RelocDir- > > > >Size - 1, > > > - = 0 > > > - = ); > > > + if ((RelocDir !=3D NULL) && (RelocDir->Size > 0)) { > > > + RelocBase =3D (EFI_IMAGE_BASE_RELOCATION *) > > > PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0)= ; > > > + RelocBaseEnd =3D (EFI_IMAGE_BASE_RELOCATION *) > > > PeCoffLoaderImageAddress (&ImageContext, > > > + = RelocDir->VirtualAddress + RelocDir- > > > >Size - 1, > > > + = 0 > > > + = ); > > > + } > > > + if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || (UINTN)= RelocBaseEnd > > > < (UINTN) RelocBase) { > > > + // > > > + // relocation block is not valid, just return > > > + // > > > + return; > > > + } > > > } else { > > > // > > > // Cannot find relocations, cannot continue to relocate the imag= e, ASSERT > > > for this invalid image. > > > @@ -1769,7 +1779,7 @@ PeCoffLoaderRelocateImageForRuntime ( > > > // > > > FixupData =3D RelocationData; > > > RelocBaseOrig =3D RelocBase; > > > - while (RelocBase < RelocBaseEnd) { > > > + while ((UINTN) RelocBase < (UINTN) RelocBaseEnd) { > > > // > > > // Add check for RelocBase->SizeOfBlock field. > > > // > > > @@ -1794,7 +1804,7 @@ PeCoffLoaderRelocateImageForRuntime ( > > > // > > > // Run this relocation record > > > // > > > - while (Reloc < RelocEnd) { > > > + while ((UINTN) Reloc < (UINTN) RelocEnd) { > > > > > > Fixup =3D PeCoffLoaderImageAddress (&ImageContext, RelocBase= - > > > >VirtualAddress + (*Reloc & 0xFFF), 0); > > > if (Fixup =3D=3D NULL) { > > > -- > > > 2.16.2.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel