ArmPlatformPkg, MdeModulePkg, SecurityPkg: Update Tpm2StartupLib - #1866
ArmPlatformPkg, MdeModulePkg, SecurityPkg: Update Tpm2StartupLib#1866Raymond-MS wants to merge 4 commits into
Conversation
This reverts commit 4de8ea1.
✅ QEMU Validation PassedSource Dependencies
Results
Workflow run: https://github.com/microsoft/mu_basecore/actions/runs/30313400091 This comment was automatically generated by the Mu QEMU PR Validation workflow. |
…Pei. This functionality was updated such that it can be used in both SEC and PEI. Updated PeilessSec to include the updated Tpm2StartupLib functionality. Verified boot to UEFI shell on both Q35 (PEI path) and VIRT (SEC path). Moved the SyncPcrs functionality to Tcg2Dxe; this is only able to be done when the PCD lib is available due to dynamic PCDs. This gives us a common location for syncing to occur on both PEI and PEI-less platforms. Created a fixed version of the DeviceStateLib. This was required due to the use of another dynamic PCD which is not available in SEC. Moved the PCD in MdeModulePkg.dec such that it can be set as FixedAtBuild.
e1fc822 to
76b0397
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors TPM2 startup and early measurement flows by consolidating logic into Tpm2StartupLib so it can be invoked from both PEI (traditional) and SEC (PEI-less) paths. It also relocates PCR bank sync logic into DXE (where dynamic PCD writes are legal) and introduces a phase-agnostic mechanism (HOB) for passing pre-hashed FV digests.
Changes:
- Consolidate TPM startup + pre-DXE measurements into
SecurityPkg/Library/Tpm2StartupLib, and update PEI/SEC call sites to use the new entry points. - Add a new
gPrehashedFvHobGuidand HOB format for pre-hashed FV digests; update Tcg2 PEI to translate the pre-hashed FV PPI into these HOBs. - Move PCR bank sync logic to
Tcg2Dxeand adjust PCD consumption accordingly.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | Removes direct deps and switches PEI flow to use Tpm2StartupLib; adds PrehashedFV PPI + HOB GUID usage. |
| SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c | Replaces in-module TPM init/measurement logic with Tpm2StartupLib calls; adds translation of excluded/prehashed FV PPIs to HOBs. |
| SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf | Adds PCDs and libs needed for PCR allocation/mask sync in DXE. |
| SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c | Implements DXE-side PCR bank/mask synchronization and calls it from driver entry. |
| SecurityPkg/SecurityPkg.dec | Adds gPrehashedFvHobGuid and documents its intent. |
| SecurityPkg/Library/Tpm2StartupLibNull/Tpm2StartupLibNull.inf | Drops unused DebugLib dependency. |
| SecurityPkg/Library/Tpm2StartupLibNull/Tpm2StartupLibNull.c | Expands NULL lib to provide no-op implementations for the new Tpm2StartupLib API. |
| SecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.inf | Updates library dependencies and declares additional PCD/GUID usage needed after consolidation. |
| SecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.c | Implements consolidated TPM startup, core measurements, FV measurement, and measured-FV HOB publishing. |
| SecurityPkg/Library/HashLibTpm2/HashLibTpm2PeilessSecLib.inf | Removes unused PEI-less SEC dependencies tied to transfer list parsing. |
| SecurityPkg/Library/HashLibTpm2/HashLibTpm2PeilessSecLib.c | Changes hash bitmap selection to derive from TPM active PCR banks instead of transfer list event log parsing. |
| SecurityPkg/Include/Library/Tpm2StartupLib.h | Defines the expanded Tpm2StartupLib API used by both PEI and PEI-less SEC paths. |
| SecurityPkg/Include/Guid/PrehashedFvHob.h | Introduces the phase-agnostic HOB payload definition for pre-hashed FV digests. |
| MdeModulePkg/MdeModulePkg.dec | Moves PcdDeviceStateBitmask so it can be set FixedAtBuild. |
| MdeModulePkg/Library/DeviceStateLib/DeviceStateLibFixed.inf | Adds a FixedAtBuild-compatible DeviceStateLib implementation for SEC environments. |
| MdeModulePkg/Library/DeviceStateLib/DeviceStateLibFixed.c | Implements read-only device-state access and returns RETURN_UNSUPPORTED for writes. |
| ArmPlatformPkg/PeilessSec/PeilessSec.h | Adds Tpm2StartupLib include for PEI-less SEC. |
| ArmPlatformPkg/PeilessSec/PeilessSec.c | Replaces legacy startup call with new consolidated TPM init/measurement/FV measurement flow. |
| ArmPlatformPkg/ArmPlatformPkg.dsc | Removes the explicit binding to the NULL Tpm2StartupLib instance for PEI-less SEC. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ((Hdr->FvBase == FvBase) && (Hdr->FvLength == FvLength)) { | ||
| PreHashInfo = (HASH_INFO *)(Hdr + 1); | ||
| DigestCount = 0; | ||
| for (Index = 0; Index < Hdr->Count; Index++) { | ||
| HashAlgoMask = GetHashMaskFromAlgo (PreHashInfo->HashAlgoId); | ||
| if ((*RemainingTpm2HashMask & HashAlgoMask) != 0) { | ||
| WriteUnaligned16 (&(DigestList->digests[DigestCount].hashAlg), PreHashInfo->HashAlgoId); | ||
| CopyMem (&DigestList->digests[DigestCount].digest, PreHashInfo + 1, PreHashInfo->HashSize); | ||
| DigestCount++; | ||
| *RemainingTpm2HashMask &= ~HashAlgoMask; | ||
| } | ||
|
|
||
| PreHashInfo = (HASH_INFO *)((UINT8 *)(PreHashInfo + 1) + PreHashInfo->HashSize); | ||
| } | ||
|
|
||
| WriteUnaligned32 (&DigestList->count, DigestCount); | ||
| return EFI_SUCCESS; | ||
| } |
| Status = Tpm2PcrAllocateBanks (NULL, (UINT32)TpmHashAlgorithmBitmap, Tpm2PcrMask); | ||
| if (EFI_ERROR (Status)) { | ||
| DEBUG ((DEBUG_ERROR, "%a - Failed to reallocate PCRs!\n", __func__)); | ||
| ASSERT_EFI_ERROR (Status); | ||
| } | ||
|
|
||
| ResetCold (); | ||
| } |
| if (MeasurementExcludedFvPpi->Count <= 0) { | ||
| DEBUG ((DEBUG_ERROR, "ExcludedFvPpi has invalid count %d", MeasurementExcludedFvPpi->Count)); | ||
| ASSERT (MeasurementExcludedFvPpi->Count > 0); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/202511 #1866 +/- ##
=================================================
Coverage ? 1.91%
=================================================
Files ? 1025
Lines ? 336602
Branches ? 2634
=================================================
Hits ? 6449
Misses ? 330112
Partials ? 41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Updated the Tpm2StartupLib to consolidate the functionality from Tcg2Pei. This functionality was updated such that it can be used in both SEC and PEI. Updated PeilessSec to include the updated Tpm2StartupLib functionality. Moved the SyncPcrs functionality to Tcg2Dxe; this is only able to be done when the PCD lib is available due to dynamic PCDs. This gives us a common location for syncing to occur on both PEI and PEI-less platforms. Created a fixed version of the DeviceStateLib. This was required due to the use of another dynamic PCD which is not available in SEC. Moved the PCD in MdeModulePkg.dec such that it can be set as FixedAtBuild.
For details on how to complete these options and their meaning refer to CONTRIBUTING.md.
How This Was Tested
Verified boot to UEFI shell on both Q35 (PEI path) and VIRT (SEC path).
Integration Instructions
Add Tpm2StartupLib.inf to your platform's .dsc.