Skip to content

Fix: BaseCryptLibOnOneCrypto#1787

Open
Flickdm wants to merge 4 commits into
microsoft:release/202511from
Flickdm:fix/OneCryptoLib
Open

Fix: BaseCryptLibOnOneCrypto#1787
Flickdm wants to merge 4 commits into
microsoft:release/202511from
Flickdm:fix/OneCryptoLib

Conversation

@Flickdm
Copy link
Copy Markdown
Member

@Flickdm Flickdm commented May 7, 2026

Description

This PR should be rebased and merged to keep the commit history because it also has a fewer other smaller but nice to have changes that should go in with this.

This is a workaround to not use VA_LIST in X509ConstructCertificateStackV - which goes against the UEFI specification and is broken today when using a CLANGPDB compiled binary vs a GCC5 DxeCore. This change will unblock our partner teams but the long term fix is to deprecate the (now unused) function X509ConstructCertificateStackV.

This pull request refactors and improves the implementation of the X509ConstructCertificateStack functions in the OneCrypto library, making them more robust and better tested. The main changes include replacing a macro-based implementation with an explicit function, adding comprehensive unit tests for various input scenarios, and fixing a logic bug in the error handling macro. These changes enhance the reliability and maintainability of the certificate stack construction logic.

X509 Certificate Stack Construction Refactor and Bug Fixes

Implementation improvements:

  • Replaced the macro-based implementation of X509ConstructCertificateStackV with an explicit function that iterates through the variadic arguments, validates certificate sizes, and appends certificates to the stack, improving clarity and error handling. (CryptoPkg/Library/BaseCryptLibOnOneCrypto/OneCryptoLib.c)
  • Updated X509ConstructCertificateStack to call the new X509ConstructCertificateStackV function and return its result, ensuring consistent logic and error propagation. (CryptoPkg/Library/BaseCryptLibOnOneCrypto/OneCryptoLib.c)

Bug fixes:

  • Fixed a logic bug in the CryptoServiceNotAvailable macro: changed the condition from && to || to correctly handle cases where the protocol pointer is NULL, preventing possible null pointer dereference. (CryptoPkg/Library/BaseCryptLibOnOneCrypto/OneCryptoLib.c)
    Testing improvements:
  • Added a comprehensive suite of unit tests for X509ConstructCertificateStack, covering scenarios such as null input, single and multiple certificates, appending certificates, invalid certificates, zero-size certificates, empty lists, and direct variadic calls. (CryptoPkg/Test/UnitTest/Library/BaseCryptLib/X509Tests.c)

Metadata update:

  • Added the "id": "onecrypto-bin" field to the OneCrypto_ext_dep.json file, improving package identification. (CryptoPkg/Binaries/OneCrypto_ext_dep.json)

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

QemuSbsaPkg && Platform Testing

Integration Instructions

<Describe how these changes should be integrated. Use N/A if nothing is required.>

@mu-automation
Copy link
Copy Markdown
Contributor

mu-automation Bot commented May 7, 2026

✅ QEMU Validation Passed

Source Dependencies

Repository Commit
mu_basecore c19dcba
mu_tiano_platforms f499bb0

Results

Platform Target Build Boot Overall Boot Time Build Logs Boot Logs
Q35 DEBUG ✅ success ✅ success 0m 17s Build Logs Boot Logs
SBSA DEBUG ✅ success ✅ success 0m 30s Build Logs Boot Logs

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

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

@Flickdm Flickdm force-pushed the fix/OneCryptoLib branch from 7755938 to eec6d57 Compare May 9, 2026 01:30
@Flickdm Flickdm marked this pull request as ready for review May 13, 2026 20:07
@Flickdm Flickdm force-pushed the fix/OneCryptoLib branch 2 times, most recently from 593536f to 17b6cc9 Compare May 13, 2026 20:08
@Flickdm Flickdm requested review from Javagedes, apop5 and os-d May 13, 2026 20:25
@Flickdm Flickdm force-pushed the fix/OneCryptoLib branch from 17b6cc9 to dacc97a Compare May 13, 2026 20:29
Flickdm added 4 commits May 13, 2026 13:34
Use logical OR in the protocol and function pointer null checks in the
dispatch macros. This avoids null dereference risk and correctly handles
either missing protocol or missing service function pointers.

Signed-off-by: Doug Flick <dougflick@microsoft.com>
Add 8 new unit tests for X509ConstructCertificateStack and
X509ConstructCertificateStackV to improve coverage of the X509
certificate stack construction API:

- NullInput: NULL X509Stack pointer returns FALSE
- SingleCert: construct stack with one CA certificate
- Append: build stack incrementally across multiple calls
- InvalidCert: truncated DER data fails without losing the stack
- MultipleCertsOneCall: three certs in a single variadic call
- ZeroSize: cert with size 0 fails gracefully
- EmptyList: NULL-only terminator succeeds
- VDirect: two certs exercising the VA_LIST code path

Also fix the test class string for TestVerifyX509 from
"CryptoPkg.BaseCryptLib.Hkdf" to "CryptoPkg.BaseCryptLib.X509".

Signed-off-by: Doug Flick <dougflick@microsoft.com>
On AARCH64, VA_LIST is incompatible across GCC5 (ELF/AAPCS64) and
CLANGPDB (PE/COFF/MSVC) toolchains. GCC5 uses a 32-byte struct
tracking register and stack save areas, while CLANGPDB uses a simple
char pointer. Passing VA_LIST through the OneCrypto protocol boundary
causes the binary to misinterpret arguments - reading the cert pointer
value as the cert size.

Replace the direct CALL_CRYPTO_SERVICE dispatch of
X509ConstructCertificateStackV with a caller-side loop that unpacks
the VA_LIST locally (same toolchain, safe) and calls the non-variadic
X509ConstructCertificateStack protocol function once per certificate.
Each call passes a single cert/size pair terminated by NULL, avoiding
any VA_LIST crossing the cross-toolchain protocol boundary.

Signed-off-by: Doug Flick <dougflick@microsoft.com>
Add the missing "id" field to OneCrypto_ext_dep.json. This field is
required by the edk2-pytool ext_dep override mechanism to allow
downstream platforms to override the OneCrypto binary dependency
using "override_id" in a local ext_dep file.

Signed-off-by: Doug Flick <dougflick@microsoft.com>
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