From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web12.5613.1579158690311020461 for ; Wed, 15 Jan 2020 23:11:30 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, 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 orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2020 23:11:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,325,1574150400"; d="scan'208";a="213982477" Received: from lgao4-mobl.ccr.corp.intel.com ([10.255.31.242]) by orsmga007.jf.intel.com with ESMTP; 15 Jan 2020 23:11:28 -0800 From: "Liming Gao" To: devel@edk2.groups.io Cc: Isaac Oram Subject: [edk2-platform] FitGen: Fix the issue to run in X64 linux machine Date: Thu, 16 Jan 2020 15:11:25 +0800 Message-Id: <20200116071125.170-1-liming.gao@intel.com> X-Mailer: git-send-email 2.24.1.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Isaac Oram Signed-off-by: Liming Gao --- Silicon/Intel/Tools/FitGen/FitGen.c | 29 +++++++++++++++++++---------- Silicon/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/FitGen/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 +// +// With OptionalModule Address isn't known until free space has been +// identified and the optional module has been copied into the FLASH +// image buffer (or initialized to be populated later by another program). +// This is very dangerous code as it can truncate 64b pointers to +// 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_TABLE_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; // // Find the FFS file @@ -595,7 +603,7 @@ Returns: InitializeFvLib (FvHeader, (UINT32)FvLength); FileHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FvHeader + FvHeader->HeaderLength); - Offset = (UINT32) (UINTN) FileHeader - (UINT32) (UINTN) FvHeader; + Offset = (UINTN) FileHeader - (UINTN) FvHeader; while (Offset < FvLength) { TempGuid = (EFI_GUID *)&(FileHeader->Name); @@ -625,7 +633,7 @@ Returns: return FixPoint; } FileHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FileHeader + FileOccupiedSize); - Offset = (UINT32) (UINTN) FileHeader - (UINT32) (UINTN) FvHeader; + Offset = (UINTN) FileHeader - (UINTN) FvHeader; } // @@ -1082,7 +1090,7 @@ Returns: return 0; } gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE; - gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer); + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + (UINT32)((UINTN) MicrocodeBuffer - (UINTN) MicrocodeFileBuffer); gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize; gFitTableContext.MicrocodeNumber++; gFitTableContext.FitEntryNumber++; @@ -1110,7 +1118,7 @@ Returns: /// while (MicrocodeBuffer + SlotSize <= MicrocodeFileBuffer + MicrocodeFileSize) { gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE; - gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer); + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + (UINT32)((UINTN) MicrocodeBuffer - (UINTN) MicrocodeFileBuffer); gFitTableContext.MicrocodeNumber++; gFitTableContext.FitEntryNumber++; @@ -1428,7 +1436,7 @@ Returns: return 0; } gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE; - gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer); + gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + (UINT32)((UINTN) MicrocodeBuffer - (UINTN) MicrocodeFileBuffer); gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize; gFitTableContext.MicrocodeNumber++; gFitTableContext.FitEntryNumber++; @@ -1557,6 +1565,7 @@ Returns: } gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber].Type = Type; gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber].Address = (UINT32) (UINTN) FileBuffer; + gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber].Buffer = FileBuffer; gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber].Size = FileSize; // @@ -1846,8 +1855,8 @@ Returns: } } } - memcpy (OptionalModuleAddress, (VOID *) (UINTN) gFitTableContext.OptionalModule[Index].Address, gFitTableContext.OptionalModule[Index].Size); - free ((VOID *) (UINTN) gFitTableContext.OptionalModule[Index].Address); + memcpy (OptionalModuleAddress, gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber].Buffer, gFitTableContext.OptionalModule[Index].Size); + free (gFitTableContext.OptionalModule[gFitTableContext.OptionalModuleNumber].Buffer); gFitTableContext.OptionalModule[Index].Address = MEMORY_TO_FLASH (OptionalModuleAddress, FvBuffer, FvSize); } // diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitGen/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__ // -- 2.13.0.windows.1