From 75d6d78c533936a5ceb654aa2dd2ae6e6594506b Mon Sep 17 00:00:00 2001 From: Min Xu Date: Thu, 15 Apr 2021 10:56:01 +0800 Subject: [PATCH] OvmfPkg: Measure QemuCfg SystemStates in SEC --- OvmfPkg/Include/Library/TdvfPlatformLib.h | 4 ++-- OvmfPkg/Library/TdxStartupLib/Tcg.c | 22 +++++++++++++++++++ OvmfPkg/Library/TdxStartupLib/TdxStartup.c | 4 +++- .../TdxStartupLib/TdxStartupInternal.h | 7 ++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Include/Library/TdvfPlatformLib.h b/OvmfPkg/Include/Library/TdvfPlatformLib.h index c97b005fba12..27bfb03ee2e8 100644 --- a/OvmfPkg/Include/Library/TdvfPlatformLib.h +++ b/OvmfPkg/Include/Library/TdvfPlatformLib.h @@ -8,7 +8,7 @@ #include #define EFI_RESOURCE_ATTRIBUTE_ENCRYPTED 0x04000000 - +#pragma pack(1) typedef struct { /// EFI_HOB_GUID_TYPE GuidHeader; @@ -17,7 +17,7 @@ typedef struct { BOOLEAN SetNxForStack; UINT8 SystemStates[6]; } EFI_HOB_PLATFORM_INFO; - +#pragma pack() VOID EFIAPI TdvfPlatformInitialize ( diff --git a/OvmfPkg/Library/TdxStartupLib/Tcg.c b/OvmfPkg/Library/TdxStartupLib/Tcg.c index 5ef0ec378246..a97cdcea75de 100644 --- a/OvmfPkg/Library/TdxStartupLib/Tcg.c +++ b/OvmfPkg/Library/TdxStartupLib/Tcg.c @@ -229,3 +229,25 @@ TdxMeasureFvImage ( return Status; } +EFI_STATUS +MeasureQemuCfgSystemSts ( + IN TCG_PCRINDEX PCRIndex, + IN UINT8 *HashData, + IN UINTN HashDataLength + ) +{ + EFI_STATUS Status; + CHAR8 *Item = "etc/system-states"; + + Status = CreateTdxExtendEvent ( + PCRIndex, // PCRIndex + EV_PLATFORM_CONFIG_FLAGS, // EventType + (UINT8*)Item, // EventData + AsciiStrLen(Item), // EventSize + HashData, // HashData + HashDataLength // HashDataLen + ); + + return Status; +} + diff --git a/OvmfPkg/Library/TdxStartupLib/TdxStartup.c b/OvmfPkg/Library/TdxStartupLib/TdxStartup.c index 747c422cd6ad..e548ec425406 100644 --- a/OvmfPkg/Library/TdxStartupLib/TdxStartup.c +++ b/OvmfPkg/Library/TdxStartupLib/TdxStartup.c @@ -103,6 +103,7 @@ TdxStartup( UINT32 DxeCodeBase; UINT32 DxeCodeSize; TD_RETURN_DATA TdReturnData; + UINT8 *PlatformInfoPtr; Status = EFI_SUCCESS; BootFv = NULL; @@ -224,7 +225,8 @@ TdxStartup( MeasureConfigurationVolume ((UINT64)(UINTN)PcdGet32 (PcdCfvBase)); - BuildGuidDataHob (&gUefiOvmfPkgTdxPlatformGuid, &PlatformInfoHob, sizeof (EFI_HOB_PLATFORM_INFO)); + PlatformInfoPtr = (UINT8*)BuildGuidDataHob (&gUefiOvmfPkgTdxPlatformGuid, &PlatformInfoHob, sizeof (EFI_HOB_PLATFORM_INFO)); + MeasureQemuCfgSystemSts (1, PlatformInfoPtr + sizeof(EFI_HOB_PLATFORM_INFO) - 6, 6); BuildStackHob ((UINTN)SecCoreData->StackBase, SecCoreData->StackSize <<=1 ); diff --git a/OvmfPkg/Library/TdxStartupLib/TdxStartupInternal.h b/OvmfPkg/Library/TdxStartupLib/TdxStartupInternal.h index 4adac00583e5..e652de76555c 100644 --- a/OvmfPkg/Library/TdxStartupLib/TdxStartupInternal.h +++ b/OvmfPkg/Library/TdxStartupLib/TdxStartupInternal.h @@ -188,6 +188,13 @@ CreateTdxExtendEvent ( IN UINTN HashDataLen ); +EFI_STATUS +MeasureQemuCfgSystemSts ( + IN TCG_PCRINDEX PCRIndex, + IN UINT8 *HashData, + IN UINTN HashDataLength + ); + VOID EFIAPI AsmGetRelocationMap (