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.88; helo=mga01.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 911AA211BA46B for ; Wed, 30 Jan 2019 19:30:49 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2019 19:30:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,543,1539673200"; d="scan'208";a="271331229" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga004.jf.intel.com with ESMTP; 30 Jan 2019 19:30:48 -0800 Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 30 Jan 2019 19:30:48 -0800 Received: from shsmsx154.ccr.corp.intel.com (10.239.6.54) by fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 30 Jan 2019 19:30:48 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX154.ccr.corp.intel.com ([169.254.7.232]) with mapi id 14.03.0415.000; Thu, 31 Jan 2019 11:30:45 +0800 From: "Gao, Liming" To: "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+s4fp86XIANoAgAC5XRA= Date: Thu, 31 Jan 2019 03:30:45 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3D3D37@SHSMSX104.ccr.corp.intel.com> References: <20190130011936.5804-1-hong-chihx.hsueh@intel.com> <3C0D5C461C9E904E8F62152F6274C0BB40B8EFC5@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <3C0D5C461C9E904E8F62152F6274C0BB40B8EFC5@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:30:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Bi, Dandan > Sent: Thursday, January 31, 2019 8:27 AM > To: Hsueh, Hong-chihX ; edk2-devel@lists.01.o= rg > Cc: Kinney, Michael D ; Gao, Liming ; Laszlo Ersek > Subject: RE: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if rel= oc info is invalid >=20 > Reviewed-by: Bi Dandan >=20 > 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 Ersek > > > > Subject: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if reloc= 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 boot= ing > > 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 || RelocBase= End < > > 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 NumberOfRvaAndSize= s in > > // the optional header to verify a desired directory entry is there. > > // > > + RelocBase =3D NULL; > > + RelocBaseEnd =3D NULL; > > if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { > > RelocDir =3D DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERE= LOC; > > - 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) R= elocBaseEnd > > < (UINTN) RelocBase) { > > + // > > + // relocation block is not valid, just return > > + // > > + return; > > + } > > } else { > > // > > // Cannot find relocations, cannot continue to relocate the image,= 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