Break out the PromptForUserConfirmation() function into a lib
so it can be abstracted at the platform level.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
Implemented dynamic TCG log scaling in Tcg2Dxe. When the log would become
truncated it instead now dynamically scales doubling the size each time.
An ERROR log is reported that an increase to your base log size should
occur such that scaling is not necessary. This is a precaution against
platforms that log a lot and the addition of new hashing algorithms for
PQC. The log is allocated in BootServices memory. Tests were added via
TcgLogTest which includes a DXE driver and a UEFI shell UnitTest app. The
DXE driver handles pre-ReadyToBoot tests while the TestApp handles
post-ReadyToBoot tests as well as gathering the test results from the DXE
driver. Markdown documents were created to detail the changes.
Added the Truncation event marker to the end of the FinalEventLog when it
becomes truncated. Added a event signal for when scaling occurs on the
normal event log. Consumers can trigger callbacks on this event; the test
app uses this to know when scaling occurs.
Added an ACPI log region for the ACPI table LAML/LASA. This region does
not scale and can become truncated indicated by the Truncation event
marker.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Updated Tpm2DeviceLibFfa to no longer use globals. Updated the
SEC version of Tpm2DeviceLibFfaBase to no longer use globals
when including TPM libraries in the SEC phase. Includes various
cleanup regarding the updated files.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Use TPM 1.2 and TPM 2.0 in setup titles instead of the
implementation-facing TCG and TCG2 names.
Signed-off-by: Herve ELTER <rvnvv74@gmail.com>
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
The libspdm submodule was pinned at 3.7.0 (2025-04-03), three releases behind
upstream 3.8.2 (2026-04-03). libspdm processes untrusted responder (device)
data in the SPDM device attestation path, so tracking upstream keeps that
parsing current with fixes and hardening.
Two responder-side advisories were resolved between 3.7.0 and 3.8.2:
- GHSA-j54w-759w-xj3m: out-of-bounds write in GET_CSR handling.
- GHSA-m4wc-xmvg-369f: integer overflow / out-of-bounds read in
GET_MEASUREMENT_EXTENSION_LOG handling.
Both are responder-side. edk2 links SpdmRequesterLib (it acts as the SPDM
Requester that verifies an untrusted device Responder), so these responder
handlers are not built into edk2 images; this update is defense-in-depth
rather than a fix for a path reachable in edk2 today.
The libspdm sources referenced by the SpdmLib INFs are unchanged in 3.8.2
(the only additions are the optional ENDPOINT_INFO capability sources, which
edk2 does not enable), so no INF change is required.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chris Fernald <chfernal@microsoft.com>
Signed-off-by: Mikey Strauss <mdstrauss91@gmail.com>
Add AARCH64 to SUPPORTED_ARCHITECTURES so the SecurityPkg
host-based unit tests build and run on an AARCH64 host. Depends
on the AARCH64 host-test framework enablement
(UnitTestFrameworkPkg/MdePkg).
Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
BaseRngLib's AARCH64 backend uses an RNDR instruction path that does not
link in the host environment. Map RngLib to BaseRngLibNull for AARCH64
host builds (IA32/X64 keep BaseRngLib) and hoist the common RngLib mapping
so the per-component override can be dropped.
Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
The misc MM communicate buffer now stores the FF-A direct message
registers in an ARM_FFA_ARGS layout that preserves the native register
indices. The TCG physical presence callback must therefore locate the
TCG_NVS payload at the correct register offset instead of the start of
the communication buffer.
Point LocalTcgNvs at CommBuffer + OFFSET_OF (ARM_FFA_ARGS, Arg4) and
validate the buffer size against sizeof (ARM_FFA_ARGS). Add a
STATIC_ASSERT to guarantee TCG_NVS fits within the register space
available for the direct message payload, and include ArmFfaLib.h for
the ARM_FFA_ARGS definition.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
In preparation for the MarkdownLintCheck plugin being added to the
repo, this change defaults the plugin to `AuditOnly` mode in each
package. This allows package maintainers to enable the plugin as they
see fit.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Updated the ACPI code to fix an issue where the template was
outdated and the revision was reporting V5 but the template was still
using the V4 version of the Start Method specific parameters.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
TcgMeasureGptTable() reads the primary GPT header directly from LBA 1
and validates it with field checks only: no header CRC32, no
partition-entry-array CRC32 and no backup fallback. This is the same
divergence between the measured and the parsed partition table that
CVE-2024-13745 reports against DxeTpm2MeasureBootLib, and the tracking
issue lists both libraries as affected.
Mirror the DxeTpm2MeasureBootLib fix: select the GPT header to measure
via the shared GptLib parser. Validate the current primary GPT or, when
it is invalid, validate the backup and the header at its AlternateLBA.
Do not extend PCR[5] if no valid header can be selected.
Signed-off-by: Richard Lyu <richard.lyu@suse.com>
The previous commit introduced GptLib by extracting PartitionDxe's GPT
parsing and validation code. It provides a shared implementation for edk2
components that need to parse and validate GPT data consistently.
Update DxeTpm2MeasureBootLib to use GptLib when selecting on-disk GPT
data for measurement. Validate the current primary GPT or, when it is
invalid, validate the backup and the header at its AlternateLBA. Do not
extend PCR[5] if no valid header can be selected. The measurement therefore
uses GPT data read from disk at measurement time and applies the shared
parser and validation logic.
Ref: https://seclists.org/oss-sec/2026/q2/727
Signed-off-by: Richard Lyu <richard.lyu@suse.com>
As the FFA function now returns the target ID properly, instead of
hardcoding the FFA_RUN target ID being the TPM SP, we use the parsed
ID to issue the FFA_RUN.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
The RngDxe driver and its non-AArch64 support files still contained
comments and descriptions referring to Intel Secure Key technology,
RDRAND/RDSEED instructions, and the Intel DRNG implementation guide.
These references are no longer accurate because the driver obtains
random data through the platform-provided RngLib abstraction rather
than relying on Intel-specific CPU features. Update the comments and
descriptions to use architecture-neutral language that better reflects
the current implementation.
Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
Add Google Test Mock library header and implementation for
SecureBootVariableLib to allow simple mocking for host based unit tests
that utilize the Google Test framework.
Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
Previous changes introduced tests for unsigned
images verified by hash entries in DB/DBX. This commit adds
tests covering verification of signed images, including
certificate chain validation as well as cases where image
hashes are checked against entries in DB/DBX.
Signed-off-by: Alexander Gryanko <xpahos@gmail.com>
The part of DxeImageVerificationHandler responsible for
verifying the image location source has already been
implemented. This commit implements tests for verifying
images in cases where the image has no signature, but
there is a hash record for this file in DB/DBX.
Signed-off-by: Alexander Gryanko <xpahos@gmail.com>
TcgMeasureGptTable() ignored the return status of
TpmSanitizePrimaryHeaderGptEventSize(). On failure the EventSize output
is unreliable and was passed straight into AllocateZeroPool() and the
subsequent CopyMem() operations, which can result in an incorrectly
sized allocation and out-of-bounds access when parsing an untrusted GPT.
Check the status and, on error, free the already-allocated PrimaryHeader
and EntryPtr buffers and return EFI_DEVICE_ERROR, matching the handling
already used in DxeTpm2MeasureBootLib's TcgMeasureGptTable().
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
Although Table 5.5 "DESCRIPTION_HEADER Signatures for tables defined
by ACPI" and the "Links to ACPI-Related Documents" still reference the
"Virtual Firmware Confidential Computing Event Log Table," the CCEL
table has now been formally included in the ACPI specification, see
https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#
description-header-signatures-for-tables-defined-by-acpi
The CCEL (CC Event Log) table is defined in the ACPI 6.5 specification,
section 5.2.34 "CC Event Log ACPI Table":
https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#
cc-event-log-acpi-table
Therefore, move the CCEL table and related definitions to the standard
ACPI header files and update the relevant code to reflect the structure
and macro renaming. Also add the definitions to the ACPI 6.6 headers.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
The HashInstanceLibSha256 library does not call into Tpm2CommandLib.
Removing it from the [LibraryClasses] section reduces unnecessary
dependencies and avoids potential build issues in non-TPM builds.
Also remove the unnecessary include of Tpm2CommandLib.h
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Ensure that either File or FileBuffer is provided before proceeding with
security verification. If both are NULL, return EFI_INVALID_PARAMETER.
This prevents verification from running without a valid input buffer and
aligns with the intended design, where File is optional and FileBuffer
alone is sufficient.
Signed-off-by: Vignesh G <vigneshg@ami.com>
If the machine type of PE/COFF image is LOONGARCH64 or RISCV64, the
LoadPeImage() should return EFI_SUCCESS. This patch is intended as a
preparation for future use of LOONGARCH64 or RISCV64 PE image file.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
Remove mImageType as it is assigned but never used. The definition of
struct IMAGE_TYPE is also removed.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
HashLibBaseCryptoRouterCommon contained a version of
Tpm2GetHashMaskFromAlgo which was causing conflicts with the
version in Tpm2HelpLib. This version used a GUID to query the
HashMask, updated the name to remove the conflict and be more
inline with the actual function implementation.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Update the Tpm2Help.c functions to become wrappers for the
functions in Tpm2HelpLib. This prevents platforms from breaking
due to the updated prefix naming but will still allow us to
keep one instance of the function implementations.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Replace instances of the old Tpm2Help.c functions with the
new Tpm2HelpLib versions. Update files to use Tpm2HelpLib
in place of Tpm2Help.c from Tpm2CommandLib.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
Creation of a new Tpm2HelpLib which contains the functions from
Tpm2Help.c. This new library is meant to replace Tpm2Help.c such
that inclusion of Tpm2CommandLib and Tpm2DeviceLib is not required
when only needing access to the Tpm2Help.c functions. Due to
Tpm2HelpLib being a new library, the prefix Tpm2 has been added
to all library functions to indicate where the functions
originate from.
Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
[Sources.AARCH64] appears twice in RngDxe.inf, remove the redundant
one to make the file more concise.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
Fix spelling errors in definitions in
TcgPhysicalPresence.h, TcgStorageOpal.h, Tpm12.h,
and Tpm2Acpi.h. Update consumer in SecurityPkg.
Temporary backward-compatible aliases are provided
for the old misspelled macro and enum names.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
In SpdmSecuredMessageLib, libspdm_secmes_encode_decode.c appears twice
in [Sources] section, so remove the duplicate one.
Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
Given the start method of FFA is only introduced in revision 5 of the TCG
ACPI specification. A TPM2 table with FFA start method and lower than 5
revision should not be allowed.
This change updates the checks for revision PCD and removed a few
conditions based on new revision 5 assumptions.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
Current Tcg2AcpiFfa will populate the partition ID in byte order of big-
endian. This conflicts with the TCG ACPI Specification, which specifies
the byte-order to be little-endian.
This change corrects the byte order population process by replacing the
platform parameter byte array with MdePkg defined structure.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
Current implementation of Tcg2AcpiFfa does not rely on the interfaces
defined in `Tcg2PhysicalPresenceLib`. Carrying it in the module inf could
bring in unnecessary external dependencies and cause loading orders to
change.
This change removes the dependency from the current "LibraryClasses"
list.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
The current implementation fails to set authenticated variables when the
signature list is empty. This can legitimately occur for dbx when no
signatures are revoked after a certificate rotation.
Update the logic to explicitly handle empty signature lists, avoiding an
implicit dependency on the variable being absent from variable storage.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
The Uni file standard specifies that comments begin with the
characters "//". The following files contained incorrectly
formatted C-style comments and have been updated:
SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/PhysicalPresenceStrings.uni
SecurityPkg/Library/DxeTcgPhysicalPresenceLib/PhysicalPresenceStrings.uni
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigStrings.uni
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigStrings.uni
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni
The problems were identified during testing of the parser
https://github.com/xpahos/edk2-idea.
Signed-off-by: Alexander Gryanko <xpahos@gmail.com>
The TPM2_Startup() function is called in the Tcg2Pei driver to start the
TPM. The function is expected to return an error if the TPM is not in
the correct state.
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
This replaces a assert for a proper runtime check for the status of
Tpm2GetCapabilitySupportedAndActivePcrs()
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
Add a debug message to show the TPM2 PCR bank info in Tcg2Dxe.
Prints out both the TpmHashalgorithmBitmap and the Pcr banks.
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Fix mocked versions of GetVariable() and SetVariable().
* VendorGuid parameter use expect_memory() not expect_value()
* MockSetVariable() use check_expected() for Attributes parameter
* MockSetVariable() use check_expected_ptr() for Data parameter
* Calls to MockGetVariable() use (UINTN) cast for will_return()
of pointer to data buffer returned.
Issues found with Linux GCC NOOPT IA32 builds of unit tests.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
In the previous Pull Request that fixed TPM Field Upgrade Scenario, it was causing regression issues.
Outputs for many non-Field Upgrade scenarios are incorrectly modified.
Refactor the code to minimize the impact to non-Field Upgrade Scenarios.
Now the behavior will match the original design. Only difference is when TPMPresentFlag is false and response code is TPM_RC_UPGRADE.
Signed-off-by: Liqi Qi <liqiqi@microsoft.com>