Skip to content

ArmPlatformPkg, MdeModulePkg, SecurityPkg: Update Tpm2StartupLib - #1866

Closed
Raymond Diaz (Raymond-MS) wants to merge 11 commits into
microsoft:release/202511from
Raymond-MS:personal/rdiaz/Tpm2StartupLibUpdates
Closed

ArmPlatformPkg, MdeModulePkg, SecurityPkg: Update Tpm2StartupLib#1866
Raymond Diaz (Raymond-MS) wants to merge 11 commits into
microsoft:release/202511from
Raymond-MS:personal/rdiaz/Tpm2StartupLibUpdates

Conversation

@Raymond-MS

Copy link
Copy Markdown
Contributor

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.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

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.

@mu-automation

mu-automation Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

❌ QEMU Validation Failed

Source Dependencies

Repository Commit
mu_basecore 2d3c8e0
mu_tiano_platforms af5ef34

Results

Platform Target Build Boot Overall Boot Time Build Logs Boot Logs
Q35 DEBUG ❌ failure ⏩ skipped N/A Build Logs N/A
ArmVirt DEBUG ✅ success ✅ success 0m 12s Build Logs Boot Logs

Workflow run: https://github.com/microsoft/mu_basecore/actions/runs/33466124640

This comment was automatically generated by the Mu QEMU PR Validation workflow.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 gPrehashedFvHobGuid and 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 Tcg2Dxe and 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.

Comment thread SecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.c Outdated
Comment thread SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
Comment thread SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c Outdated
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 600 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/202511@f44f77a). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.c 0.00% 494 Missing ⚠️
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c 0.00% 61 Missing ⚠️
...Pkg/Library/HashLibTpm2/HashLibTpm2PeilessSecLib.c 0.00% 26 Missing ⚠️
...lePkg/Library/DeviceStateLib/DeviceStateLibFixed.c 0.00% 16 Missing ⚠️
SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c 0.00% 3 Missing ⚠️
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           
Flag Coverage Δ
FmpDevicePkg 9.53% <ø> (?)
MdeModulePkg 1.65% <0.00%> (?)
NetworkPkg 0.55% <ø> (?)
PolicyServicePkg 30.42% <ø> (?)
SecurityPkg 1.55% <0.00%> (?)
StandaloneMmPkg 0.50% <ø> (?)
UefiCpuPkg 4.78% <ø> (?)
UnitTestFrameworkPkg 11.70% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cfernald Chris Fernald (cfernald) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread SecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.c Outdated
Comment thread SecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.c Outdated
Comment thread ArmPlatformPkg/PeilessSec/PeilessSec.c Outdated
return EFI_SUCCESS;
}

if (IsFvAlreadyRecorded (FvBase, FvLength)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you want to check this with the values returned from ResolveMigratedFvBases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread SecurityPkg/Library/Tpm2StartupLib/Tpm2StartupLib.c Outdated
Comment thread SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c Outdated
Comment thread SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c Outdated
Comment thread SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c Outdated
Comment thread SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c Outdated
Comment thread SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c Outdated
…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.
@Raymond-MS
Raymond Diaz (Raymond-MS) force-pushed the personal/rdiaz/Tpm2StartupLibUpdates branch from 6dd8bc0 to bcbe765 Compare September 1, 2026 03:00
@Raymond-MS

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants