From 479613bd06546e30652354d5dd76ee7b377fb92c Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Sun, 21 Apr 2019 14:21:55 -0700 Subject: UefiCpuPkg/SecMigrationPei: Add initial PEIM (CVE-2019-11098) REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1614 Adds a PEIM that republishes structures produced in SEC. This is done because SEC modules may not be shadowed in some platforms due to space constraints or special alignment requirements. The SecMigrationPei module locates interfaces that may be published in SEC and reinstalls the interface with permanent memory addresses. This is important if pre-memory address access is forbidden after memory initialization and data such as a PPI descriptor, PPI GUID, or PPI inteface reside in pre-memory. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Debkumar De Cc: Harry Han Cc: Catharine West Signed-off-by: Michael Kubacki Acked-by: Laszlo Ersek Reviewed-by: Liming Gao --- UefiCpuPkg/SecCore/SecCore.inf | 2 ++ UefiCpuPkg/SecCore/SecMain.c | 26 ++++++++++++++++++++++++-- UefiCpuPkg/SecCore/SecMain.h | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) (limited to 'UefiCpuPkg/SecCore') diff --git a/UefiCpuPkg/SecCore/SecCore.inf b/UefiCpuPkg/SecCore/SecCore.inf index 0562820..545781d 100644 --- a/UefiCpuPkg/SecCore/SecCore.inf +++ b/UefiCpuPkg/SecCore/SecCore.inf @@ -68,6 +68,8 @@ ## SOMETIMES_CONSUMES gPeiSecPerformancePpiGuid gEfiPeiCoreFvLocationPpiGuid + ## CONSUMES + gRepublishSecPpiPpiGuid [Guids] ## SOMETIMES_PRODUCES ## HOB diff --git a/UefiCpuPkg/SecCore/SecMain.c b/UefiCpuPkg/SecCore/SecMain.c index 5d5e7f1..155be49 100644 --- a/UefiCpuPkg/SecCore/SecMain.c +++ b/UefiCpuPkg/SecCore/SecMain.c @@ -370,7 +370,12 @@ SecTemporaryRamDone ( VOID ) { - BOOLEAN State; + EFI_STATUS Status; + EFI_STATUS Status2; + UINTN Index; + BOOLEAN State; + EFI_PEI_PPI_DESCRIPTOR *PeiPpiDescriptor; + REPUBLISH_SEC_PPI_PPI *RepublishSecPpiPpi; // // Republish Sec Platform Information(2) PPI @@ -378,6 +383,23 @@ SecTemporaryRamDone ( RepublishSecPlatformInformationPpi (); // + // Re-install SEC PPIs using a PEIM produced service if published + // + for (Index = 0, Status = EFI_SUCCESS; Status == EFI_SUCCESS; Index++) { + Status = PeiServicesLocatePpi ( + &gRepublishSecPpiPpiGuid, + Index, + &PeiPpiDescriptor, + (VOID **) &RepublishSecPpiPpi + ); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "Calling RepublishSecPpi instance %d.\n", Index)); + Status2 = RepublishSecPpiPpi->RepublishSecPpis (); + ASSERT_EFI_ERROR (Status2); + } + } + + // // Migrate DebugAgentContext. // InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL); @@ -385,7 +407,7 @@ SecTemporaryRamDone ( // // Disable interrupts and save current interrupt state // - State = SaveAndDisableInterrupts(); + State = SaveAndDisableInterrupts (); // // Disable Temporary RAM after Stack and Heap have been migrated at this point. diff --git a/UefiCpuPkg/SecCore/SecMain.h b/UefiCpuPkg/SecCore/SecMain.h index e8c05d7..e20bcf8 100644 --- a/UefiCpuPkg/SecCore/SecMain.h +++ b/UefiCpuPkg/SecCore/SecMain.h @@ -15,6 +15,7 @@ #include #include #include +#include #include -- cgit v1.1