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.web10.3492.1580804768077922830 for ; Tue, 04 Feb 2020 00:26:08 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: bob.c.feng@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Feb 2020 00:26:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,398,1574150400"; d="scan'208";a="224222845" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga008.jf.intel.com with ESMTP; 04 Feb 2020 00:26:07 -0800 Received: from shsmsx602.ccr.corp.intel.com (10.109.6.142) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 4 Feb 2020 00:26:00 -0800 Received: from shsmsx601.ccr.corp.intel.com (10.109.6.141) 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; Tue, 4 Feb 2020 16:25:58 +0800 Received: from shsmsx601.ccr.corp.intel.com ([10.109.6.141]) by SHSMSX601.ccr.corp.intel.com ([10.109.6.141]) with mapi id 15.01.1713.004; Tue, 4 Feb 2020 16:25:58 +0800 From: "Bob Feng" To: "devel@edk2.groups.io" , "Gao, Liming" CC: "Oram, Isaac W" 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: AQHVzDwxsCqwFS4n3kuUyzPKFaQ0XagK0MTQ Date: Tue, 4 Feb 2020 08:25:58 +0000 Message-ID: <06b1e930d79f47b382c54ffab5522276@intel.com> References: <20200116071125.170-1-liming.gao@intel.com> In-Reply-To: <20200116071125.170-1-liming.gao@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Liming, Would you add more description for this patch? Thanks, Bob -----Original Message----- From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Limi= ng Gao Sent: Thursday, January 16, 2020 3:11 PM 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