MdeModulePkg/PeiCore: Enable T-RAM evacuation in PeiCore (CVE-2019-11098)

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1614

Introduces new changes to PeiCore to move the contents of temporary
RAM visible to the PeiCore to permanent memory. This expands on
pre-existing shadowing support in the PeiCore to perform the following
additional actions:

 1. Migrate pointers in PPIs installed in PeiCore to the permanent
    memory copy of PeiCore.

 2. Copy all installed firmware volumes to permanent memory.

 3. Relocate and fix up the PEIMs within the firmware volumes.

 4. Convert all PPIs into the migrated firmware volume to the corresponding
    PPI address in the permanent memory location.

    This applies to PPIs and PEI notifications.

 5. Convert all status code callbacks in the migrated firmware volume to
    the corresponding address in the permanent memory location.

 6. Update the FV HOB to the corresponding firmware volume in permanent
    memory.

 7. Use PcdMigrateTemporaryRamFirmwareVolumes to control if enable the
    feature or not. when disable the PCD, the EvacuateTempRam() will
    never be called.

The function control flow as below:
  PeiCore()
    DumpPpiList()
    EvacuateTempRam()
      ConvertPeiCorePpiPointers()
        ConvertPpiPointersFv()
      MigratePeimsInFv()
        MigratePeim()
          PeiGetPe32Data()
          LoadAndRelocatePeCoffImageInPlace()
      MigrateSecModulesInFv()
      ConvertPpiPointersFv()
      ConvertStatusCodeCallbacks()
      ConvertFvHob()
      RemoveFvHobsInTemporaryMemory()
    DumpPpiList()

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Debkumar De <debkumar.de@intel.com>
Cc: Harry Han <harry.han@intel.com>
Cc: Catharine West <catharine.west@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Michael Kubacki
2019-04-12 06:46:02 +08:00
committed by mergify[bot]
parent 1facb8fdef
commit 9bedaec05b
7 changed files with 1099 additions and 9 deletions

View File

@@ -166,6 +166,88 @@ MigrateMemoryPages (
Private->FreePhysicalMemoryTop = NewMemPagesBase;
}
/**
Removes any FV HOBs whose base address is not in PEI installed memory.
@param[in] Private Pointer to PeiCore's private data structure.
**/
VOID
RemoveFvHobsInTemporaryMemory (
IN PEI_CORE_INSTANCE *Private
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
DEBUG ((DEBUG_INFO, "Removing FVs in FV HOB not already migrated to permanent memory.\n"));
for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV || GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2 || GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
FirmwareVolumeHob = Hob.FirmwareVolume;
DEBUG ((DEBUG_INFO, " Found FV HOB.\n"));
DEBUG ((
DEBUG_INFO,
" BA=%016lx L=%016lx\n",
FirmwareVolumeHob->BaseAddress,
FirmwareVolumeHob->Length
));
if (
!(
((EFI_PHYSICAL_ADDRESS) (UINTN) FirmwareVolumeHob->BaseAddress >= Private->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS) (UINTN) FirmwareVolumeHob->BaseAddress + (FirmwareVolumeHob->Length - 1)) < Private->FreePhysicalMemoryTop)
)
) {
DEBUG ((DEBUG_INFO, " Removing FV HOB to an FV in T-RAM (was not migrated).\n"));
Hob.Header->HobType = EFI_HOB_TYPE_UNUSED;
}
}
}
}
/**
Migrate the base address in firmware volume allocation HOBs
from temporary memory to PEI installed memory.
@param[in] PrivateData Pointer to PeiCore's private data structure.
@param[in] OrgFvHandle Address of FV Handle in temporary memory.
@param[in] FvHandle Address of FV Handle in permanent memory.
**/
VOID
ConvertFvHob (
IN PEI_CORE_INSTANCE *PrivateData,
IN UINTN OrgFvHandle,
IN UINTN FvHandle
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
EFI_HOB_FIRMWARE_VOLUME2 *FirmwareVolume2Hob;
EFI_HOB_FIRMWARE_VOLUME3 *FirmwareVolume3Hob;
DEBUG ((DEBUG_INFO, "Converting FVs in FV HOB.\n"));
for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
FirmwareVolumeHob = Hob.FirmwareVolume;
if (FirmwareVolumeHob->BaseAddress == OrgFvHandle) {
FirmwareVolumeHob->BaseAddress = FvHandle;
}
} else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {
FirmwareVolume2Hob = Hob.FirmwareVolume2;
if (FirmwareVolume2Hob->BaseAddress == OrgFvHandle) {
FirmwareVolume2Hob->BaseAddress = FvHandle;
}
} else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
FirmwareVolume3Hob = Hob.FirmwareVolume3;
if (FirmwareVolume3Hob->BaseAddress == OrgFvHandle) {
FirmwareVolume3Hob->BaseAddress = FvHandle;
}
}
}
}
/**
Migrate MemoryBaseAddress in memory allocation HOBs
from the temporary memory to PEI installed memory.