Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Register/Intel/Microcode.h>
#include <Register/Intel/Cpuid.h>
#include <Guid/MicrocodeShadowInfoHob.h>
#include <Guid/FitEntryHob.h>
//
// Data structure for microcode patch information
//
Expand Down Expand Up @@ -168,36 +169,29 @@ ShadowMicrocodePatchWorker (
}

/**
Check if FIT table content is valid according to FIT BIOS specification.
Check if cached FIT table content is valid according to FIT BIOS specification.

**/
BOOLEAN
IsValidFitTable (
IN UINT64 FitPointer
IsValidFitEntryHob (
IN FIT_ENTRY_HOB_DATA *FitHobData
)
{
UINT64 FitEnding;
FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;
UINT32 EntryNum;
UINT32 Type0Count;
UINT32 Index;

//
// The entire FIT table must reside with in the firmware address range
// of (4GB-16MB) to (4GB-40h).
//
if ((FitPointer < (SIZE_4GB - SIZE_16MB)) || (FitPointer >= (SIZE_4GB - 0x40))) {
//
// Invalid FIT address, treat it as no FIT table.
//
DEBUG ((DEBUG_ERROR, "Error: Invalid FIT pointer 0x%p.\n", FitPointer));
if ((FitHobData == NULL) || (FitHobData->EntryCount == 0)) {
DEBUG ((DEBUG_ERROR, "Error: FIT HOB is empty.\n"));
return FALSE;
}

FitEntry = FitHobData->Entry;

//
// Check FIT header.
//
FitEntry = (FIRMWARE_INTERFACE_TABLE_ENTRY *)(UINTN)FitPointer;
if ((FitEntry[0].Type != FIT_TYPE_00_HEADER) ||
(FitEntry[0].Address != FIT_TYPE_00_SIGNATURE))
{
Expand All @@ -214,14 +208,9 @@ IsValidFitTable (
}

//
// Check FIT ending address in valid range.
// Check cached FIT entry count against the FIT header.
//
EntryNum = *(UINT32 *)(&FitEntry[0].Size[0]) & 0xFFFFFF;
FitEnding = FitPointer + sizeof (FIRMWARE_INTERFACE_TABLE_ENTRY) * EntryNum;
if (FitEnding > (SIZE_4GB - 0x40)) {
DEBUG ((DEBUG_ERROR, "Error: FIT table exceeds valid range.\n"));
return FALSE;
}
EntryNum = *(UINT32 *)(&FitEntry[0].Size[0]) & 0xFFFFFF;

//
// Calculate FIT checksum if Checksum Valid bit is set.
Expand Down Expand Up @@ -286,7 +275,8 @@ ShadowMicrocode (
)
{
EFI_STATUS Status;
UINT64 FitPointer;
VOID *Hob;
FIT_ENTRY_HOB_DATA *FitHobData;
FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;
UINT32 EntryNum;
UINT32 Index;
Expand All @@ -305,15 +295,21 @@ ShadowMicrocode (
return EFI_INVALID_PARAMETER;
}

FitPointer = *(UINT64 *)(UINTN)FIT_POINTER_ADDRESS;
if (!IsValidFitTable (FitPointer)) {
Hob = GetFirstGuidHob (&gFitEntryHobGuid);
if (Hob == NULL) {
DEBUG ((DEBUG_ERROR, "%a: FIT Entry HOB not found.\n", __func__));
return EFI_NOT_FOUND;
}

FitHobData = (FIT_ENTRY_HOB_DATA *)GET_GUID_HOB_DATA (Hob);
if (!IsValidFitEntryHob (FitHobData)) {
return EFI_NOT_FOUND;
}

//
// Calculate microcode entry number
//
FitEntry = (FIRMWARE_INTERFACE_TABLE_ENTRY *)(UINTN)FitPointer;
FitEntry = FitHobData->Entry;
EntryNum = *(UINT32 *)(&FitEntry[0].Size[0]) & 0xFFFFFF;
MaxPatchNumber = 0;
for (Index = 0; Index < EntryNum; Index++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
[Guids]
gEdkiiMicrocodeShadowInfoHobGuid
gEdkiiMicrocodeStorageTypeFlashGuid
gFitEntryHobGuid

[Pcd]
gIntelSiliconPkgTokenSpaceGuid.PcdShadowAllMicrocode
Expand Down
Loading