ArmPlatformPkg, MdeModulePkg, SecurityPkg: Update Tpm2StartupLib - #1866
ArmPlatformPkg, MdeModulePkg, SecurityPkg: Update Tpm2StartupLib#1866Raymond Diaz (Raymond-MS) wants to merge 11 commits into
Conversation
❌ QEMU Validation FailedSource Dependencies
Results
Workflow run: https://github.com/microsoft/mu_basecore/actions/runs/33466124640 This comment was automatically generated by the Mu QEMU PR Validation workflow. |
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.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release/202511 #1866 +/- ##
=================================================
Coverage ? 1.86%
=================================================
Files ? 1188
Lines ? 383738
Branches ? 3326
=================================================
Hits ? 7157
Misses ? 376516
Partials ? 65
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:
|
Chris Fernald (cfernald)
left a comment
There was a problem hiding this comment.
Reading through the PR, I do think there is the layering is a bit off for the startup lib. It declares itself as BASE but does take dependence on the phase as we discussed offline with the use of HOB creation. Now the obvious problem is that there is no suitable library (except perhaps TpmMeasurementLib, but that isn't for internal use really) that provides the abstraction for the log writing. Realistically, this means either making StartupLib split into phases or creating yet-another library (e.g. Tcg2EventLogLib) that would have a DXE and a PEI/SEC version.
| return EFI_SUCCESS; | ||
| } | ||
|
|
||
| if (IsFvAlreadyRecorded (FvBase, FvLength)) { |
There was a problem hiding this comment.
Wouldn't you want to check this with the values returned from ResolveMigratedFvBases?
There was a problem hiding this comment.
I took some time to look into this and I don't believe so. The FvBase and FvLength are passed into the measure function and are used to create the mTpm2StartupMeasuredFvHobGuid HOB. ResolveMigratedFvBases return values (FvOrgBase and FvDataBase) wouldn't be found in IsFvAlreadyRecorded.
This reverts commit 4de8ea1.
…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.
…kg CI. It is unable to be built alongside the dynamic version.
6dd8bc0 to
bcbe765
Compare
|
Going to close this PR. After discussions with Sean Brogan (@spbrogan) and Chris Fernald (@cfernald) we decided to go a different route with the startup library. The current implementation has issues where if an intel system wanted to include the library in SEC it would not work. The idea was to have something that worked for PEI-less platforms as well as platforms with PEI. This focused the startup library into a solution that wouldn't always work in both SEC and PEI (not necessarily anyway). The implementation is also too complex and contains measurements of the FVs which we decided should stay within their respective phases. The current idea is to simplify the implementation down to what we think is currently necessary and expand on it in the future if necessary. |
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.