Commit graph

1100 commits

Author SHA1 Message Date
rdiaz
2c2f74a581 SecurityPkg: Break out the user prompt from Tcg2 PPI
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>
2026-08-26 10:54:45 +00:00
rdiaz
ffaaf0f14c SecurityPkg: Introduce Dynamic TCG Log Scaling
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>
2026-08-26 03:58:17 +00:00
rdiaz
f7052e2d02 SecurityPkg: Remove global use pre-memory
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>
2026-08-03 20:16:00 +00:00
Herve ELTER
0af5cb9cd0 SecurityPkg/Tcg: Use TPM names in setup strings
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>
2026-08-03 03:56:36 +00:00
Mikey Strauss
4bd628ce98 SecurityPkg/DeviceSecurity: Update libspdm submodule to 3.8.2
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>
2026-08-03 01:40:40 +00:00
Jeff Brasen
6a4e543b09 SecurityPkg/Test: add AARCH64 to host test DSC
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>
2026-07-31 15:16:47 +00:00
Jeff Brasen
10732648fb SecurityPkg/Test: use BaseRngLibNull for AARCH64 host tests
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>
2026-07-31 15:16:47 +00:00
Kun Qin
bdd36cdc1a SecurityPkg: Tcg2StandaloneMmArm: Align PP buffer with ARM_FFA_ARGS
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>
2026-07-30 13:46:46 +00:00
Michael Kubacki
df9111c2d3 Global: Set MarkdownLintCheck plugin to AuditOnly
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>
2026-07-29 12:32:09 +00:00
rdiaz
479a79c57f MdePkg,SecurityPkg: Fix TPM2 ACPI Table
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>
2026-07-25 01:32:22 +00:00
Richard Lyu
b65fd21591 SecurityPkg/DxeTpmMeasureBootLib: Use GptLib parser
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>
2026-07-20 21:50:57 +00:00
Richard Lyu
7c12d4359a SecurityPkg/DxeTpm2MeasureBootLib: Use GptLib parser
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>
2026-07-20 21:50:57 +00:00
Kun Qin
2938b830f6 SecurityPkg: Tpm over FFA: FFA_RUN command should use the returned ID
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>
2026-07-20 19:13:15 +00:00
Tuan Phan
3613891d77 SecurityPkg/RngDxe: Support RISCV64
Add RISCV64 to the list of valid architectures.

Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
2026-07-17 05:23:45 +00:00
Tuan Phan
fb42b39a7d SecurityPkg/RngDxe: Replace Intel-specific with arch-neutral comments
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>
2026-07-17 05:23:45 +00:00
Joey Vagedes
3fec625408 SecurityPkg: Add Google Test MockSecureBootVariableLib
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>
2026-07-16 17:50:01 +00:00
Alexander Gryanko
1dc6b5e3dd SecurityPkg: added image verification tests for signed images
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>
2026-07-16 02:33:17 +00:00
Alexander Gryanko
7668d8854f SecurityPkg: added image verification test using DB hash
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>
2026-07-16 02:33:17 +00:00
Dāvis Mosāns
855e63ee5c SecurityPkg/Tpm2ServiceFfa.h: fix typo
Replace `TPM_CRB_FFA_FEAT_NOTIFICATION_TYPE_SHIFT` with `TPM2_FFA_FEAT_NOTIFICATION_TYPE_SHIFT`

Fixes #12768

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
2026-07-07 19:57:18 +00:00
Mingjie Shen
65cacd6fcd SecurityPkg/DxeTpmMeasureBootLib: Check GPT event size sanitization
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>
2026-07-07 19:20:07 +00:00
Sami Mujawar
4ae84e3e87 MdePkg, SecurityPkg, OvmfPkg: Move CCEL table defs to ACPI header
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>
2026-07-03 09:26:33 +00:00
20000419
4f475ba542 SecurityPkg/AuthVariableLib: harden signature list filtering
Signed-off-by: 20000419 <lzy20000419@outlook.com>
2026-06-30 02:35:17 +00:00
Michael Kubacki
fd7a2a5488 SecurityPkg: Update Tpm2Ptp.h to follow pragma once coding convention
Update Tpm2Ptp.h to follow the latest EDK II C Coding Standards
Specification (5.3) to use '#pragma once' instead of traditional
macro-based include guards in header files.

https://tianocore-docs.github.io/edk2-CCodingStandardsSpecification/draft/5_source_files/53_include_files.html#53-include-files

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-06-25 19:40:31 +00:00
Sami Mujawar
8a6cd66acb SecurityPkg/HashInstanceLibSha256: Remove unused Tpm2CommandLib dependency
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>
2026-06-25 16:53:36 +00:00
Vignesh G
56cad12011 SecurityPkg: Add sanity check for File and FileBuffer inputs
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>
2026-06-24 17:51:16 +00:00
Qihang Gao
08258192d4 SecurityPkg: Add support for LOONGARCH64 and RISCV64 when parsing PE image
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>
2026-06-24 17:31:06 +00:00
Qihang Gao
d984c9b63c SecurityPkg/SecureBootConfigDxe: Remove unused variable mImageType
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>
2026-06-24 17:31:06 +00:00
rdiaz
a48fae6611 SecurityPkg: Update HashLibBaseCryptoRouter
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>
2026-06-17 19:16:45 +00:00
rdiaz
c0208dc79e SecurityPkg: Update Tpm2Help.c Functions
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>
2026-06-17 19:16:45 +00:00
rdiaz
2d49d51722 SecurityPkg: Integrate Tpm2HelpLib
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>
2026-06-17 19:16:45 +00:00
rdiaz
fde05ad8f6 SecurityPkg: Introduce Tpm2HelpLib
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>
2026-06-17 19:16:45 +00:00
Mingjie Shen
9b816d5bf0 SecurityPkg: Replace manual alignment checks with helper macros
Replace manual alignment checks with IS_ALIGNED() and
ADDRESS_IS_ALIGNED().

Convert the following bitmask and modulo forms:

- ((E & ((PowOf2Expr) - ONE)) == ZERO)
- ((E & ((PowOf2Expr) - ONE)) != ZERO)
- ((E % (PowOf2Expr)) == ZERO)
- ((E % (PowOf2Expr)) != ZERO)

to the corresponding helper macro forms:

+ IS_ALIGNED (E, PowOf2Expr)
+ !IS_ALIGNED (E, PowOf2Expr)

PowOf2Expr is limited to known power-of-two expressions, including
SIZE_* and BASE_* macros, EFI_PAGE_SIZE, CPU_STACK_ALIGNMENT,
RUNTIME_PAGE_ALLOCATION_GRANULARITY, sizeof() of UEFI integer types
(e.g. BOOLEAN, CHAR16, UINT32, UINTN) and pointer types, and 1 << E1
expressions.

Address checks that cast the checked value to UINTN are written with
ADDRESS_IS_ALIGNED().

The change was generated with the Coccinelle semantic patch below.

```smpl
@power_of_2_expr@
expression PowOf2Expr;
expression E1;
typedef BOOLEAN, CHAR8, CHAR16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, INTN, UINTN;
type ScalarType = { BOOLEAN, CHAR8, CHAR16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, INTN, UINTN };
type AnyType;
type PointerType = AnyType *;
idexpression ScalarType ScalarValue;
idexpression PointerType PointerValue;
constant SizeBase =~ "^(SIZE|BASE)_(1|2|4|8|16|32|64|128|256|512)[KMGTPE]B$";
constant NamedPowerOf2 =~ "^(EFI_PAGE_SIZE|CPU_STACK_ALIGNMENT|RUNTIME_PAGE_ALLOCATION_GRANULARITY)$";
constant ONE = {1, 1U, 1u};
@@
(
(
  SizeBase
|
  NamedPowerOf2
|
  ONE << E1
|
  sizeof (ScalarType)
|
  sizeof (PointerType)
|
  sizeof (ScalarValue)
|
  sizeof (PointerValue)
)
&
PowOf2Expr
)

@aligned depends on power_of_2_expr disable is_zero,isnt_zero@
expression E;
expression power_of_2_expr.PowOf2Expr;
constant ONE = {1, 1U, 1u};
constant ZERO = {0, 0U, 0u};
@@
(
  ((E & (E - ONE)) == ZERO)
|
- ((E & ((PowOf2Expr) - ONE)) == ZERO)
+ IS_ALIGNED (E, PowOf2Expr)
|
  ((E & (E - ONE)) != ZERO)
|
- ((E & ((PowOf2Expr) - ONE)) != ZERO)
+ !IS_ALIGNED (E, PowOf2Expr)
|
- ((E % (PowOf2Expr)) == ZERO)
+ IS_ALIGNED (E, PowOf2Expr)
|
- ((E % (PowOf2Expr)) != ZERO)
+ !IS_ALIGNED (E, PowOf2Expr)
)

@address_is_aligned@
typedef UINTN;
expression *Address;
expression Alignment;
@@
- IS_ALIGNED ((UINTN) Address, Alignment)
+ ADDRESS_IS_ALIGNED (Address, Alignment)

@normalize_aligned disable paren expression@
expression E, SZ;
@@
(
- (IS_ALIGNED (E, SZ))
+ IS_ALIGNED (E, SZ)
|
- (!IS_ALIGNED (E, SZ))
+ !IS_ALIGNED (E, SZ)
)

@normalize_macro_args disable paren expression@
expression E, SZ;
@@
(
- IS_ALIGNED ((E), SZ)
+ IS_ALIGNED (E, SZ)
|
- IS_ALIGNED (E, (SZ))
+ IS_ALIGNED (E, SZ)
)
```

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2026-06-09 07:20:10 +00:00
Qihang Gao
9c7e0db74b SecurityPkg: Remove redundant section name in inf file
[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>
2026-06-03 02:18:39 +00:00
Oliver Smith-Denny
81b7c2912b MdePkg,SecurityPkg: Fix Spelling Errors in TCG/TPM Definitions
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>
2026-05-08 02:15:34 +00:00
Benjamin Doron
441873c2a9 SecurityPkg/SecureBootVariableLib: Cleanup debug print readability
All debug prints should end in a newline character.

Signed-off-by: Benjamin Doron <benjamin.doron@9elements.com>
2026-05-06 10:43:05 +00:00
Qihang Gao
25540b069f SecurityPkg: Remove duplicate file name in INF file
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>
2026-04-29 11:18:10 +02:00
Kun Qin
f1fc41cff2 SecurityPkg: Tcg2AcpiFfa: Polish revision checks for TPM2 table
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>
2026-04-07 04:23:57 +00:00
Kun Qin
a270773cce SecurityPkg: Tcg2AcpiFfa: Fix endianness of partition ID
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>
2026-04-07 04:23:57 +00:00
Kun Qin
c60df38f10 SecurityPkg: Tcg2AcpiFfa: Remove Tcg2PhysicalPresenceLib from dependencies
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>
2026-04-07 04:23:57 +00:00
Sherry Fan
11af818b3e SecurityPkg: Refactor performance to use new PERF_FUNCTION_* measurements
Use the new PERF_FUNCTION_START/END instrumentation for simpler perf
measurement.

Signed-off-by: Sherry Fan <sherryfan@microsoft.com>
2026-03-17 02:38:07 +00:00
20000419
6fb6ef54e7 SecurityPkg/Tcg2Smm: harden NVS/SMI state initialization
Signed-off-by: 20000419 <lzy20000419@outlook.com>
2026-03-13 02:33:10 +00:00
Kun Qin
b980aa0719 SecurityPkg: AuthVariableLib: Handle empty signature lists
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>
2026-03-10 06:33:40 +00:00
Alexander Gryanko
201a4fe3ec SecurityPkg: align UNI file headers with UNI Spec standard
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>
2026-03-02 19:32:17 +00:00
Bret Barkelew
d85a9c6e23 SecurityPkg: Make TPM2_Startup() return an error
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>
2026-03-02 07:26:21 +00:00
Bret Barkelew
673842aefc SecurityPkg: Check for Tpm2GetCapabilitySupportedAndActivePcrs()
This replaces a assert for a proper runtime check for the status of
Tpm2GetCapabilitySupportedAndActivePcrs()

Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
2026-03-02 07:26:21 +00:00
Bret Barkelew
e412a892b3 SecurityPkg: Add Debug Message to show the TPM2 PCR bank info
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>
2026-03-02 07:26:21 +00:00
Michael Kubacki
9326c0eb0a SecurityPkg: Replace include guards with #pragma once
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>
2026-02-23 21:01:28 +00:00
Michael D Kinney
715a8dc067 SecurityPkg/Library/SecureBootVariableLib/UnitTest: Cmocka use issues
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>
2026-01-21 09:15:06 +00:00
Michael D Kinney
43e0552a74 SecurityPkg: Fix VS2022 NOOPT IA32 use of intrinsics
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-01-21 08:27:09 +00:00
Liqi Qi
454e1fc40f SecurityPkg: Fix Tcg2SubmitCommand in most cases
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>
2026-01-19 07:23:02 +00:00