From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web09.1236.1579221733535285990 for ; Thu, 16 Jan 2020 16:42:13 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2020 16:42:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,327,1574150400"; d="scan'208";a="214302836" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga007.jf.intel.com with ESMTP; 16 Jan 2020 16:42:12 -0800 Received: from shsmsx602.ccr.corp.intel.com (10.109.6.142) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 16 Jan 2020 16:41:48 -0800 Received: from shsmsx606.ccr.corp.intel.com (10.109.6.216) by SHSMSX602.ccr.corp.intel.com (10.109.6.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 17 Jan 2020 08:41:46 +0800 Received: from shsmsx606.ccr.corp.intel.com ([10.109.6.216]) by SHSMSX606.ccr.corp.intel.com ([10.109.6.216]) with mapi id 15.01.1713.004; Fri, 17 Jan 2020 08:41:46 +0800 From: "Liming Gao" To: "devel@edk2.groups.io" , "Gao, Liming" CC: "Oram, Isaac W" , "Feng, Bob C" Subject: Re: [edk2-devel] [edk2-platform] FitGen: Fix the issue to run in X64 linux machine Thread-Topic: [edk2-devel] [edk2-platform] FitGen: Fix the issue to run in X64 linux machine Thread-Index: AQHVzDw2K03p46ZoDE2QJNiFiCq3tKfuBOgQ Date: Fri, 17 Jan 2020 00:41:46 +0000 Message-ID: <1f3168ae87a848eeb69e1c2d53a75a14@intel.com> References: <15EA4C765FD15EA4.4264@groups.io> In-Reply-To: <15EA4C765FD15EA4.4264@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2466 -----Original Message----- From: devel@edk2.groups.io On Behalf Of Liming Gao Sent: 2020=1B$BG/=1B(B1=1B$B7n=1B(B16=1B$BF|=1B(B 15:11 To: devel@edk2.groups.io Cc: Oram, Isaac W Subject: [edk2-devel] [edk2-platform] FitGen: Fix the issue to run in X64 = linux machine Cc: Isaac Oram Signed-off-by: Liming Gao --- Silicon/Intel/Tools/FitGen/FitGen.c | 29 +++++++++++++++++++---------- S= ilicon/Intel/Tools/FitGen/FitGen.h | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/Fit= Gen/FitGen.c index 833610f2a0..b6ec551333 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.c +++ b/Silicon/Intel/Tools/FitGen/FitGen.c @@ -226,9 +226,17 @@ typedef struct { #define FIT_TABLE_TYPE_BIOS_DATA_AREA 13 #define FIT_TABLE_TYPE_CSE_SECURE_BOOT 16 =20 +// +// With OptionalModule Address isn't known until free space has been //= =20 +identified and the optional module has been copied into the FLASH //=20 +image buffer (or initialized to be populated later by another program). +// This is very dangerous code as it can truncate 64b pointers to //=20 +allocated memory buffers. The full pointer is in Buffer for that case. +// typedef struct { UINT32 Type; UINT32 Address; + UINT8 *Buffer; // Used by OptionalModule only UINT32 Size; UINT32 Version; // Used by OptionalModule and PortModule only } FIT_T= ABLE_CONTEXT_ENTRY; @@ -575,9 +583,9 @@ Returns: UINT64 FvLength; EFI_GUID *TempGuid; UINT8 *FixPoint; - UINT32 Offset; - UINT32 FileLength; - UINT32 FileOccupiedSize; + UINTN Offset; + UINTN FileLength; + UINTN FileOccupiedSize; =20 // // Find the FFS file @@ -595,7 +603,7 @@ Returns: InitializeFvLib (FvHeader, (UINT32)FvLength); =20 FileHeader =3D (EFI_FFS_FILE_HEADER *)((UINTN)FvHeader + FvHead= er->HeaderLength); - Offset =3D (UINT32) (UINTN) FileHeader - (UINT32) (UINTN) F= vHeader; + Offset =3D (UINTN) FileHeader - (UINTN) FvHeader; =20 while (Offset < FvLength) { TempGuid =3D (EFI_GUID *)&(FileHeader->Name); @@ -625,7 +633,7 @@ R= eturns: return FixPoint; } FileHeader =3D (EFI_FFS_FILE_HEADER *)((UINTN)FileHeader + FileOccu= piedSize); - Offset =3D (UINT32) (UINTN) FileHeader - (UINT32) (UINTN) FvHeader; + Offset =3D (UINTN) FileHeader - (UINTN) FvHeader; } =20 // @@ -1082,7 +1090,7 @@ Returns: return 0; } gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber= ].Type =3D FIT_TABLE_TYPE_MICROCODE; - gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber= ].Address =3D MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) = (UINTN) MicrocodeFileBuffer); + + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address =3D= = =20 + MicrocodeBase + (UINT32)((UINTN) MicrocodeBuffer - (UINTN)=20 + MicrocodeFileBuffer); gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber= ].Size =3D MicrocodeSize; gFitTableContext.MicrocodeNumber++; gFitTableContext.FitEntryNumber++; @@ -1110,7 +1118,7 @@ Returns: /// while (MicrocodeBuffer + SlotSize <=3D MicrocodeFileBuffer = + MicrocodeFileSize) { gFitTableContext.Microcode[gFitTableContext.MicrocodeNumb= er].Type =3D FIT_TABLE_TYPE_MICROCODE; - gFitTableContext.Microcode[gFitTableContext.MicrocodeNumb= er].Address =3D MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32= ) (UINTN) MicrocodeFileBuffer); + + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address =3D= = =20 + MicrocodeBase + (UINT32)((UINTN) MicrocodeBuffer - (UINTN)=20 + MicrocodeFileBuffer); gFitTableContext.MicrocodeNumber++; gFitTableContext.FitEntryNumber++; =20 @@ -1428,7 +1436,7 @@ Returns: return 0; } gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = =3D FIT_TABLE_TYPE_MICROCODE; - gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Addres= s =3D MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) = MicrocodeFileBuffer); + + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address =3D= = =20 + MicrocodeBase + (UINT32)((UINTN) MicrocodeBuffer - (UINTN)=20 + MicrocodeFileBuffer); gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = =3D MicrocodeSize; gFitTableContext.MicrocodeNumber++; gFitTableContext.FitEntryNumber++; @@ -1557,6 +1565,7 @@ Returns: } gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber= ].Type =3D Type; gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber= ].Address =3D (UINT32) (UINTN) FileBuffer; + + gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber] + .Buffer =3D FileBuffer; gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber= ].Size =3D FileSize; =20 // @@ -1846,8 +1855,8 @@ Returns: } } } - memcpy (OptionalModuleAddress, (VOID *) (UINTN) gFitTableContext.Op= tionalModule[Index].Address, gFitTableContext.OptionalModule[Index].Size); - free ((VOID *) (UINTN) gFitTableContext.OptionalModule[Index].Addre= ss); + memcpy (OptionalModuleAddress, gFitTableContext.OptionalModule[gFit= TableContext.OptionalModuleNumber].Buffer, gFitTableContext.OptionalModule[= Index].Size); + free=20 + (gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber + ].Buffer); gFitTableContext.OptionalModule[Index].Address =3D MEMORY_TO_FLASH = (OptionalModuleAddress, FvBuffer, FvSize); } // diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/Fit= Gen/FitGen.h index 9bd3f6824b..ecb5822d32 100644 --- a/Silicon/Intel/Tools/FitGen/FitGen.h +++ b/Silicon/Intel/Tools/FitGen/FitGen.h @@ -31,7 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Utility= version information // #define UTILITY_MAJOR_VERSION 0 -#define UTILITY_= MINOR_VERSION 56 +#define UTILITY_MINOR_VERSION 57 #define UTILITY_DATE __DATE__ =20 // -- 2.13.0.windows.1