Skip to content

Commit

Permalink
SecurityPkg/FvReportPei: Use FirmwareVolumeShadowPpi
Browse files Browse the repository at this point in the history
If FirmwareVolumeShadow PPI is available, then use it to
shadow FVs to memory.  Otherwise fallback to CopyMem().

Cc: Jiewen Yao <[email protected]>
Cc: Jian J Wang <[email protected]>
Signed-off-by: Patel Umang <[email protected]>
Reviewed-by: Jian J Wang <[email protected]>
  • Loading branch information
umang-intel authored and mergify[bot] committed Mar 27, 2023
1 parent c8e6315 commit 1440286
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
37 changes: 30 additions & 7 deletions SecurityPkg/FvReportPei/FvReportPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ VerifyHashedFv (
IN EFI_BOOT_MODE BootMode
)
{
UINTN FvIndex;
CONST HASH_ALG_INFO *AlgInfo;
UINT8 *HashValue;
UINT8 *FvHashValue;
VOID *FvBuffer;
EFI_STATUS Status;
UINTN FvIndex;
CONST HASH_ALG_INFO *AlgInfo;
UINT8 *HashValue;
UINT8 *FvHashValue;
VOID *FvBuffer;
EDKII_PEI_FIRMWARE_VOLUME_SHADOW_PPI *FvShadowPpi;
EFI_STATUS Status;

if ((HashInfo == NULL) ||
(HashInfo->HashSize == 0) ||
Expand Down Expand Up @@ -191,8 +192,30 @@ VerifyHashedFv (
// Copy FV to permanent memory to avoid potential TOC/TOU.
//
FvBuffer = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)FvInfo[FvIndex].Length));

ASSERT (FvBuffer != NULL);
CopyMem (FvBuffer, (CONST VOID *)(UINTN)FvInfo[FvIndex].Base, (UINTN)FvInfo[FvIndex].Length);
Status = PeiServicesLocatePpi (
&gEdkiiPeiFirmwareVolumeShadowPpiGuid,
0,
NULL,
(VOID **)&FvShadowPpi
);

if (!EFI_ERROR (Status)) {
Status = FvShadowPpi->FirmwareVolumeShadow (
(EFI_PHYSICAL_ADDRESS)FvInfo[FvIndex].Base,
FvBuffer,
(UINTN)FvInfo[FvIndex].Length
);
}

if (EFI_ERROR (Status)) {
CopyMem (
FvBuffer,
(CONST VOID *)(UINTN)FvInfo[FvIndex].Base,
(UINTN)FvInfo[FvIndex].Length
);
}

if (!AlgInfo->HashAll (FvBuffer, (UINTN)FvInfo[FvIndex].Length, FvHashValue)) {
Status = EFI_ABORTED;
Expand Down
1 change: 1 addition & 0 deletions SecurityPkg/FvReportPei/FvReportPei.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <IndustryStandard/Tpm20.h>

#include <Ppi/FirmwareVolumeInfoStoredHashFv.h>
#include <Ppi/FirmwareVolumeShadowPpi.h>

#include <Library/PeiServicesLib.h>
#include <Library/PcdLib.h>
Expand Down
1 change: 1 addition & 0 deletions SecurityPkg/FvReportPei/FvReportPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
[Ppis]
gEdkiiPeiFirmwareVolumeInfoPrehashedFvPpiGuid ## PRODUCES
gEdkiiPeiFirmwareVolumeInfoStoredHashFvPpiGuid ## CONSUMES
gEdkiiPeiFirmwareVolumeShadowPpiGuid ## CONSUMES

[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdStatusCodeFvVerificationPass
Expand Down

0 comments on commit 1440286

Please sign in to comment.