Skip to content

[DRAFT][WIP] SecurityPkg: DxeImageValidationLib rewrite#1809

Draft
Javagedes wants to merge 12 commits into
microsoft:release/202511from
Javagedes:personal/joeyvagedes/securitypkg-image-validation
Draft

[DRAFT][WIP] SecurityPkg: DxeImageValidationLib rewrite#1809
Javagedes wants to merge 12 commits into
microsoft:release/202511from
Javagedes:personal/joeyvagedes/securitypkg-image-validation

Conversation

@Javagedes

@Javagedes Javagedes commented May 28, 2026

Copy link
Copy Markdown
Contributor

Description

This is a complete rewrite of DxeImageValidationLib.

Please review the Scenario scoped tests found in GoogleTest/DxeImageVerificationLibGoogleTest.cpp.

Notable differences from original implementation:

  1. Policy management has been simplified (almost completely removed). Policy now dictates that if the image comes from an FV, it should be ALWAYS_EXECUTE. Anything else is set to DENY_EXECUTE_ON_SECURITY_VIOLATION and must go through the handler. There are no longer PCDs to configure Policy for certain scenarios.
  2. PE image parsing is delegated to PeCoffLib.
  3. Hashing is delegated to BaseCryptLib.
  4. AuditMode has been removed. Secureboot is either enabled or disabled and that logic comes from the existing SecureBootVariableLib.
  5. Multi-signed images only require one signer to fully validate. The previous implementation requires all signers fully validate.
  6. Added X509 cert hash support in the DB
  7. Global data, including digests, have been removed. A Cache system has been created to reduce duplicate hashing.
  8. Functionality has been compartmentalized into small testable functions that do not rely on global state
  9. Test coverage is around 95%

TODOS

  1. Write action to Image Execution Information Table when denying image
  2. Write to PCR7 when allowing image that is validated via signer
  3. Implement IsSignedImageRevoked

@mu-automation

mu-automation Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

⏳ QEMU Validation In Progress

A new QEMU validation run has started. Results from any previous run(s) are now outdated.

Note: Previous results are available in this comment's edit history.

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

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

@codecov-commenter

codecov-commenter commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
MdePkg/Library/BasePeCoffLib/BasePeCoff.c 0.00% 38 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             release/202511    #1809   +/-   ##
=================================================
  Coverage                  ?    1.10%           
=================================================
  Files                     ?     1477           
  Lines                     ?   377980           
  Branches                  ?     4863           
=================================================
  Hits                      ?     4160           
  Misses                    ?   372901           
  Partials                  ?      919           
Flag Coverage Δ
FmpDevicePkg 9.53% <ø> (?)
MdeModulePkg 0.26% <ø> (?)
MdePkg 3.30% <0.00%> (?)
NetworkPkg 0.55% <ø> (?)
PolicyServicePkg 30.42% <ø> (?)
UefiCpuPkg 3.00% <ø> (?)
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.

@makubacki

Copy link
Copy Markdown
Member

I wasn't sure about adding the AI skills to this repo. But in any case, it shouldn't be included in this PR.

@Javagedes Javagedes force-pushed the personal/joeyvagedes/securitypkg-image-validation branch from 07ae785 to c5f9a3d Compare May 29, 2026 16:00
Javagedes added 10 commits June 3, 2026 15:09
Adds two additional fields of PE_COFF_LOADER_IMAGE_CONTEXT:

1. `DataDirectoryRead`: An optional caller provided callback to
   to execute code on the given `EFI_IMAGE_DATA_DIRECTORY`
2. `DataDirectoryReadContext`: An optional caller provided opaque
   pointer that can be used by `DataDirectoryRead`.
Adds a API to the BaseCryptLib Library that accepts a image buffer
and a hash type guid and returns a digest buffer and size.
Adds an API to the BaseCryptLib that accepts an X.509 buffer
and a hash type guid and returns a digest buffer and size
Adds the policy verification implementation and security data directory lookup to determine
if image validation is necessary, and if so, which method to use (ValidateUnsignedImage vs
ValidateSignedImage). Additionally includes unit tests for Policy.c and Support.c
Adds functionality for the full path of ValidateUnsignedImage and
adds tests for the code.
…ntation

Adds an implementation for ValidateSignedImage and adds unit tests.

NOTE: IsSignedImageRevoked is still a stub. WIP.
@Javagedes Javagedes force-pushed the personal/joeyvagedes/securitypkg-image-validation branch from c5f9a3d to 8140e11 Compare June 3, 2026 15:10
@Javagedes Javagedes force-pushed the personal/joeyvagedes/securitypkg-image-validation branch from 1333d6a to a38aaf1 Compare June 9, 2026 14:23
@jyao1

jyao1 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I checked the code with AI.

It seems the code does not handle 2 cases:

  1. intermediate cert in DBX.
    Thinking of a case that: Chain leaf→intermediate→root, db trusts root, dbx lists the intermediate:
    I think the expectation is to revoke the image, right? But it seems allow.
    Is there a test to cover that?

  2. signed image hash in DBX
    It seems the code only check unsigned image hash in DBX, not signed image hash.
    Is there a test to cover that?

I have not got chance to review all the code yet. Maybe I am wrong.

But I feel we have better have a test to cover that.

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