Commit graph

344 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
Levi Yun
96ad9bd397 SecurityPkg/Tcg2Config: use ArmFfaGetPartitionInfo() in Tcg2ConfigFfaPeim
Use ArmFfaGetPartitionInfo() in Tcg2ConfigFfaPeim.
This simplifies the code line to get partition information.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2026-01-08 12:07:46 +00:00
Liqi Qi
ba8296810c SecurityPkg: Fix Tcg2SubmitCommand in TPM field upgrade scenario
There's a bug that after the device was forced shut down during the tpm
firmware update process, then the TPM will stay in field upgrade mode and
refuse to work properly. This will block TPM startup and cause the device
to bootloop.

Now in the TCG_DXE_DATA struct we don’t have a flag to indicate the
current TPM mode, and we will simply treat the upper Scenario with this
DEVICE_ERROR and set the TPMPresentFlag to FALSE.

Later in Tcg2SubmitCommand we will just return DEVICE_ERROR and skip the
actual TPM recovery.

We should have an extra flag that check for the TPM response code and if
it's TPM_RC_UPGRADE, we knew the device is in field upgrade mode and should
continue the workflow.

We should only return EFI_DEVICE_ERROR when both TPMPresentFlag and
TpmUpdateFlag are false.

The field upgrade is part of TCG spec, and the capsule update/recovery
is part of UEFI spec.
Make this PR to bring in the fix for this corner case.

Signed-off-by: Liqi Qi <liqiqi@microsoft.com>
2025-12-11 02:29:14 +00:00
lijunwei
7772a2a347 SecurityPkg: Correct misspelled variable name
Fix the misspelled variable name `mTcg2ConfigPrivateDate` and rename it
to `mTcg2ConfigPrivateData` to improve code readability and
maintainability.

The word "Date" (calendar date) was incorrectly used instead of "Data"
(information data).

Signed-off-by: lijunwei <542095246@qq.com>
2025-12-10 14:29:31 +00:00
Arun Subramanian Baskaran
c6cea09e9a SecurityPkg: Trace and return status are handled.
Added debug trace messages on LocateProtocol failure for
gEfiDxeSmmReadyToLockProtocolGuid. Returned device error in case of
EfiCreateProtocolNotifyEvent failure.
Removed ASSERT due to if condition.

Signed-off-by: Arun Subramanian Baskaran <arun.subramanian.baskaran@intel.com>
2025-10-27 01:49:32 +00:00
Kun Qin
9c06ac56fb SecurityPkg: Tcg2StandaloneMmArm: Enable TPM FFA Instance to Register PPI
Previously, the implementation restricted usage to TPM instances with the
DTPM ID, which worked only if the system supported TPM over FFA but still
set the instance ID to DTPM. However, Tpm2InstanceLibFfa requires the
`PcdTpmInstanceGuid` to be set to `gTpm2ServiceFfaGuid`.

This update expands support by allowing the `PcdTpmInstanceGuid` to
include the TPM-over-FFA instance GUID, enabling proper registration of
the PPI.

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-10-14 17:58:23 +02:00
Kun Qin
4883960e5e SecurityPkg: Tcg2AcpiFfa: Correct TPM Instance Validation
The current implementation checks `PcdTpmInstanceGuid` and enforces the
use of the DTPM instance GUID. However, for FFA-specific modules, the
correct value should be `gTpm2ServiceFfaGuid`.

This update fixes the validation logic to support routing through
Tpm2DeviceLibRouter* with the appropriate instance library, which
requires the instance ID to be set to `gTpm2ServiceFfaGuid`.

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-10-14 17:58:23 +02:00
Levi Yun
d8e875e625 Global: fix ArmFfaLibRun() caller couldn't get ret-args
When ArmFfaLibDirectMsgReq(2) is preempted, caller of these functions
should resume it works via ArmFfaLibRun() and the secure partition
will be return with FFA_DIRECT_MSG_RESP(2) with return arguments.

However, since ArmFfaLibRun() gets its return in its stack variable,
So caller of ArmFfaLibRun() doesn't get the return arguments from
secure partition.

To resolve this, add output parameter to ArmFfaLibRun() to
receive return arguments.

Continuous-integration-options: PatchCheck.ignore-multi-package
Fixes: 5d1b38dd07 ("ArmPkg: Add ArmFfaLib used in Dxe driver")
Reported-by: Mariam Elshakfy <Mariam.Elshakfy@arm.com>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-09-08 13:14:00 +00:00
Michael D Kinney
072ab3846c Revert "SecurityPkg: CodeQL Fixes."
This reverts commit ba6a8eb045.

PR https://github.com/tianocore/edk2/pull/11307 introduced a
logic change that caused regressions in FV verification on
some platforms. This PR is being reverted to restore the prior
logic.

The Code QL fixes in https://github.com/tianocore/edk2/pull/11307
can be resubmitted without the logic change along with one
commit for each type of Code QL issue being addressed.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-08-12 03:50:30 +00:00
Hunter Chang
504a80c151 SecurityPkg/Tcg/OpalPasswordDxe: Fix logic for RemoveDevice()
First, If there are multiple devices in DeviceList and are going to
remove the first device in the DeviceList, the DeviceList will be
cleared up with setting to NULL.
This is not the expected behavior, as it should keep the rest of the
devices in the DeviceList. DeviceList should point to the next device,
Dev->Next.

Second, there is a potential infinite while loop if TmpDev->Next not
equal to Dev. TmpDev should point to next device.

Signed-off-by: Hunter Chang <hunter.chang@intel.com>
2025-08-07 06:40:28 +00:00
Levi Yun
5fc1ba3f25 SecurityPkg/Tcg2Config: add Tcg2ConfigFfaPei
To support TPM2 devices that operate over the FF-A specification using CRB
in the Tcg2Pei PEIM, add the Tcg2ConfigFfaPei PEIM to
detect the presence of such TPM2 devices.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
2025-07-24 04:48:50 +00:00
Michael Kubacki
ba6a8eb045 SecurityPkg: CodeQL Fixes.
Makes changes to comply with alerts raised by CodeQL.

Most of the issues here fall into the following two categories:

1. Potential use of uninitialized pointer.
2. Inconsistent integer width in comparison.

Co-authored-by: Taylor Beebe <31827475+TaylorBeebe@users.noreply.github.com>
Co-authored-by: kenlautner <85201046+kenlautner@users.noreply.github.com>
Co-authored-by: Bret Barkelew <bret@corthon.com>

Signed-off-by: Doug Flick <dougflick@microsoft.com>
2025-07-24 01:58:06 +00:00
Dionna Glaze
0bb4cf0228 SecurityPkg: Clarify Is800155Event
The Event3 memory comparison is technically correct since the
definitions of the struct types are the same. The extended
bodies of the events are different. The Event2 size guard
for the Event3 comparison should be split to use the Event3
in its sizeof for better clarity.

The large single condition makes the function difficult to
understand, so the combined logic is split into different
conditional statements.

Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
[ardb: whitespace fixes]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-07-21 05:07:41 +00:00
Oliver Smith-Denny
d5b8630379 SecurityPkg: Move Noisy Logs to DEBUG_SECURITY
The TPM code is currently very noisy (e.g. in a sample platform,
4,000 of the 5,700 lines printed to the serial port at DEBUG_INFO
level were from the TPM code). For TPM debugging, this is very
critical information, but for most builds it simply spams the logs
and slows down the build.

This commit moves the event log and PCR dumping to log at
DEBUG_SECURITY level.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-07-14 07:25:12 +00:00
Oliver Smith-Denny
1f2adcbba5 SecurityPkg: Remove/Downgrade Noisy TCG Prints
The TCG code is very noisy when a TPM is connected. This
commit downgrades some prints to verbose and removes some
others that do not have value (such as function enter and
exit prints).

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-07-14 07:25:12 +00:00
Kun Qin
7d297e370e SecurityPkg: Tcg2AcpiFfa: Add Tcg2Acpi for FFA enabled ARM platforms
This change adds a new driver Tcg2AcpiFfa. It will publish the TPM2 and
the corresponding SSDT table that is responsible for supporting the
physical presence interface through ASL methods during OS runtime.

Co-authored-by: Raymond Diaz <raymonddiaz@microsoft.com>
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-04-18 18:52:33 +00:00
Kun Qin
ec5d8ad35f SecurityPkg: Tcg2StandaloneMmArm: Add Tcg2StandaloneMm for ARM platforms
This change adds a new driver Tcg2StandaloneMmArm. It will register an
MMI handler that is responsible for supporting the physical presence
interface from ASL methods during OS runtime.

Platforms need to expose the PPI ACPI function GUID in the Standalone MM
secure partition.

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2025-04-18 18:52:33 +00:00
Phil Noh
1f6c875d37 SecurityPkg/OpalPasswordDxe: Improve the function to get device name
Improve OpalDriverGetDriverDeviceName function that gets device name
through the component name protocol. Currently the function searches for
all handles (as controller handle) to find the right GetControllerName
service for the child handle. The update improves the way to get device
name and supports better performance (e.g. 1681(μs) -> 3(μs) for 1 NVMe
device). This can prevent a compatibility issue for GetControllerName
service of some drivers, which is not flexible for handle parameter
information (e.g. it was found that an EFI driver caused an exception
error/hang when GetControllerName service for the driver is called in
OpalDriverGetDeviceNameByProtocol function).

Signed-off-by: Phil Noh <Phil.Noh@amd.com>
2025-04-17 08:15:14 +00:00
Mike Maslenkin
b1cdfc556f SecurityPkg/OpalPassword: fix HiiOpCodeHandle leak on error path
Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
2024-12-06 17:13:17 +00:00
Phil Noh
c15bd99342 SecurityPkg/Tcg2Config: Set TPM2.0 for default of Attempt TPM Device
As TPM2.0 is popular, updating default value for the Setup menu supports
a benefit for some systems that have another TPM Setup menu to select
TPM2.0 devices (e.g. dTPM, fTPM) depending on platform bios.
For example, when loading default configuration using F9 key in Setup
(Brower Action: SystemLevel), it is possible for them to load an
unsynchronized value. If user does not adjust the value before saving
Setup, it could influence an unexpected TPM initialization at next boot.
Setting TPM2.0 as default value supports the benefit related to the case.

Signed-off-by: Phil Noh <Phil.Noh@amd.com>
2024-11-26 01:25:03 +00:00
John Strange
1240a722f8 SecurityPkg: Tcg2Acpi: Remove _DSM Memory Clear and _PTS
This patch removes the _DSM Memory Clear and MOR
auto-detect functionality via _PTS, as
_DSM Memory Clear was deprecated in TCG PC Client
Reset Attack Mitigation Spec Version 1.10 revision 17
Family "2.0" and _PTS is deemed security deficient.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-04 01:43:32 +00:00
John Strange
a4245b265d SecurityPkg: Tcg2Smm: Remove Memory Clear SMI Handler
Remove unused MemoryClear SMI Handler, which is no longer
used due to _DSM Memory Clear no longer being used.

_DSM Memory Clear was deprecated in 2019 by TCG PC Client
Platform Reset Attack Mitigation Spec Version 1.10 revision 17
Family "2.0".

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-04 01:43:32 +00:00
Matthew Carlson
96b90e150c SecurityPkg: Measure Invoke EBS even in failure case
This patch measures the ExitBootServices invocation to the
TPM even in the case of ExitBootServices failing, per TCG
PC Client Platform Firmware Profile Version 1.06 Revision
52 Family 2.0 section 8.2.4(i).

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-08-31 09:17:27 +00:00
Dun Tan
5a06afa7dd SecurityPkg: Allocate EfiACPIMemoryNVS buffer for TCG2
Allocate EfiACPIMemoryNVS buffer for TCG2 related usage in
Tcg2ConfigPeim. The buffer will be used in Tcg2Acpi driver
to retrive information from SMM environment.

Previously, the buffer used in Tcg2Acpi driver is AcpiNvs
type. But I mistakenly thought the Runtime Data type buffer
should also work. So I used API AllocateRuntimePages() to
allocate buffer in 9a76c7945b and consume the buffer in
e939ecf6c1. Recently we found that if the buffer type is
Runtime Data instead of AcpiNvs, BSOD issue happened after
boot into OS.

So this commit is to Allocate EfiACPIMemoryNVS buffer for
TCG2 usage in SMM to align with the initial code logic.

Signed-off-by: Dun Tan <dun.tan@intel.com>
2024-08-27 06:14:36 +00:00
Dun Tan
fadb9dcb9d SecurityPkg: Correct Pages for TCG2 communication buffer
The value of the Pages for TCG2 communication buffer
should be EFI_SIZE_TO_PAGES(sizeof(TCG_NVS)) instead of
sizeof(TCG_NVS).

Signed-off-by: Dun Tan <dun.tan@intel.com>
2024-08-27 06:14:36 +00:00
Michael Kubacki
d4dbe5e101 SecurityPkg/Tcg2Acpi: Revise debug print
This debug print may attempt to print a string without a null
terminator that can lead to a machine check.

The value printed is substituted with a source buffer to still
allow debug.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2024-07-12 16:04:10 +00:00
Jiaxin Wu
d5fad2176c SecurityPkg/Tcg: Correct buffer valid check func
For SMM, the SMM Handlers is to validate the buffer outside MMRAM
including the Primary & NonPrimary buffer.

For MM, the MM Handlers do not need to validate the Primary buffer
if it is passed from MmCore through the MmiHandler() parameter.
Return TRUE directly in this case. But need to validate NonPrimary
buffer that outside MMRAM.

Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Hongbin1 Zhang <hongbin1.zhang@intel.com>
Cc: Wei6 Xu <wei6.xu@intel.com>
Cc: Dun Tan <dun.tan@intel.com>
Cc: Yuanhao Xie <yuanhao.xie@intel.com>
2024-07-07 08:40:03 +00:00
Dun Tan
ed9a64af1b SecurityPkg/Tcg2Config: avoid potential build error
Cast pointer type to VOID* to avoid potential build error.
If the two PCD are FixAtBuild, PcdGetPtr will return a const
type pointer. Since the second parameter of BuildGuidDataHob
is VOID*, build error may happen with following log:
C4090: 'function': different 'const' qualifiers

Signed-off-by: Dun Tan <dun.tan@intel.com>
2024-07-04 21:33:44 +00:00
Dun Tan
e939ecf6c1 SecurityPkg: Consume gEdkiiTcg2AcpiCommunicateBufferHobGuid
Consume gEdkiiTcg2AcpiCommunicateBufferHobGuid in Tcg2Acpi
driver. Tcg2Acpi will use the buffer stored in the HOB to
exchange information with Tcg2StandaloneMm by the
MM_COMMUNICATION_PROTOCOL.

Signed-off-by: Dun Tan <dun.tan@intel.com>
2024-07-02 03:31:31 +00:00
Dun Tan
9a76c7945b SecurityPkg: Build gEdkiiTcg2AcpiCommunicateBufferHobGuid
Install a callback of gEfiPeiMemoryDiscoveredPpiGuid to
build the gEdkiiTcg2AcpiCommunicateBufferHobGuid in the
Tcg2ConfigPei PEIM.
The HOB contains a buffer reserved by MmUnblockMemoryLib.
The buffer will be used in Tcg2Acpi driver to retrive
information from standalone mm environment.

Signed-off-by: Dun Tan <dun.tan@intel.com>
2024-07-02 03:31:31 +00:00
Dun Tan
97ede07beb SecurityPkg/Tcg2StandaloneMm:Consume gEdkiiTpmInstanceHobGuid
Consume gEdkiiTpmInstanceHobGuid in Tcg2StandaloneMm
driver. It's to avoid using dynamic PcdTpmInstanceGuid
in StandaloneMm driver.

Signed-off-by: Dun Tan <dun.tan@intel.com>
2024-07-02 03:31:31 +00:00