Skip to content

Commit

Permalink
SecurityPkg: Make TPM2_Startup() return an error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Flickdm committed Jul 31, 2024
1 parent 203d27b commit 9c633e5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 52 deletions.
33 changes: 9 additions & 24 deletions SecurityPkg/Include/Library/Tcg2PreUefiEventLogLib.h
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
/** @file -- Tcg2PreUefiEventLogLib.h
This header file describes the interface that should be published by
instances of the Tcg2PreUefiEventLogLib. This library can be used
to publish TPM EventLog entries for measurements that may have been made prior
to driver initialization.
MS_CHANGE_131467
MSChange [ALL] - Move to TCG2 driver for 256-bit PCRs.
This describes the interface that should be published by instances of the
Tcg2PreUefiEventLogLib. This library can be used to publish TPM EventLog
entries for measurements that may have been made prior to driver
initialization.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Copyright (c) Microsoft Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef _TCG_2_PRE_UEFI_EVENT_LOG_LIB_H_
#define _TCG_2_PRE_UEFI_EVENT_LOG_LIB_H_
#ifndef TCG_2_PRE_UEFI_EVENT_LOG_LIB_H_
#define TCG_2_PRE_UEFI_EVENT_LOG_LIB_H_

/**
Create the EventLog entries.
**/
VOID
EFIAPI
CreateTcg2PreUefiEventLogEntries (
VOID
);

#endif // _TCG_2_PRE_UEFI_EVENT_LOG_LIB_H_
#endif // TCG_2_PRE_UEFI_EVENT_LOG_LIB_H_
Original file line number Diff line number Diff line change
Expand Up @@ -682,24 +682,25 @@ Tcg2HaveValidTpmRequest (
case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS:
// MU_CHANGE_108842
// MU_CHANGE [BEGIN] - Do not allow Flags to bypass confirmation in production mode.
#ifndef SHIP_MODE
if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_PCRS) == 0) {
*RequestConfirmed = TRUE;

if (PcdGetBool(PcdEnableShipMode)) {
if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_PCRS) == 0) {
*RequestConfirmed = TRUE;
}
}

#endif // SHIP_MODE
// MU_CHANGE [END]
break;

case TCG2_PHYSICAL_PRESENCE_CHANGE_EPS:
// MU_CHANGE_108842
// MU_CHANGE [BEGIN] - Do not allow Flags to bypass confirmation in production mode.
#ifndef SHIP_MODE
if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_EPS) == 0) {
*RequestConfirmed = TRUE;
if (PcdGetBool(PcdEnableShipMode)) {
if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_EPS) == 0) {
*RequestConfirmed = TRUE;
}
}

#endif // SHIP_MODE
// MU_CHANGE [END]
break;

Expand All @@ -710,24 +711,24 @@ Tcg2HaveValidTpmRequest (
case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID:
// MU_CHANGE_108842
// MU_CHANGE [BEGIN] - Do not allow Flags to bypass confirmation in production mode.
#ifndef SHIP_MODE
if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) {
*RequestConfirmed = TRUE;
if (PcdGetBool(PcdEnableShipMode)) {
if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) {
*RequestConfirmed = TRUE;
}
}

#endif // SHIP_MODE
// MU_CHANGE [END]
break;

case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID:
// MU_CHANGE_108842
// MU_CHANGE [BEGIN] - Do not allow Flags to bypass confirmation in production mode.
#ifndef SHIP_MODE
if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) {
*RequestConfirmed = TRUE;
if (PcdGetBool(PcdEnableShipMode)) {
if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) {
*RequestConfirmed = TRUE;
}
}

#endif // SHIP_MODE
// MU_CHANGE [END]
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags ## SOMETIMES_CONSUMES
gEfiSecurityPkgTokenSpaceGuid.PcdEnableShipMode ## CONSUMES # MU_CHANGE 108842

[Guids]
## SOMETIMES_CONSUMES ## HII
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,19 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
goto EXIT;
}

// MS_CHANGE_108842
// MU_CHANGE_108842
// MSChange [BEGIN] - Do not allow the PPI flags (persistent clear permission) request in ship mode.
#ifdef SHIP_MODE
if ((*OperationRequest == TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CHANGE_PCRS_FALSE) ||
(*OperationRequest == TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CHANGE_EPS_FALSE) ||
(*OperationRequest == TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_TURN_OFF_FALSE))
{
DEBUG ((EFI_D_ERROR, "[TPM2] Refusing to process PPI flags request in production!\n"));
ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_BLOCKED_BY_BIOS_SETTINGS;
goto EXIT;
if (PcdGetBool(PcdEnableShipMode)) {
if ((*OperationRequest == TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CHANGE_PCRS_FALSE) ||
(*OperationRequest == TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CHANGE_EPS_FALSE) ||
(*OperationRequest == TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_TURN_OFF_FALSE))
{
DEBUG ((DEBUG_ERROR, "[TPM2] Refusing to process PPI flags request in production!\n"));
ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_BLOCKED_BY_BIOS_SETTINGS;
goto EXIT;
}
}

#endif // SHIP_MODE
// MSChange [END]
// MU_CHANGE [END]

if ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) &&
(*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN))
Expand Down
7 changes: 7 additions & 0 deletions SecurityPkg/SecurityPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -666,5 +666,12 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdEnforceSelfsignedPk|FALSE|BOOLEAN|0x00010024
# MU_CHANGE [END]

# MU_CHANGE [BEGIN] - 108842
## Indicates if the device should be in "ship mode" or not.
# TRUE - Device is in ship mode and thus TPM should behave normally
# FALSE - Device is not in ship mode and TPM should be lax
gEfiSecurityPkgTokenSpaceGuid.PcdEnableShipMode|TRUE|BOOLEAN|0x00010028
## MU_CHANGE [END]

[UserExtensions.TianoCore."ExtraFiles"]
SecurityPkgExtra.uni
9 changes: 9 additions & 0 deletions SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,11 @@ PeimEntryMA (
}

if (EFI_ERROR (Status)) {
// MU_CHANGE_58957
// MU_CHANGE [BEGIN] - Make sure that TPM2_Startup() can report an error.
DEBUG ((DEBUG_ERROR, "Tcg2Pei::%a - TPM failed Startup!\n", __func__));
ASSERT_EFI_ERROR (Status);
// MU_CHANGE [END]
goto Done;
}
}
Expand Down Expand Up @@ -1240,6 +1245,10 @@ PeimEntryMA (
if (PcdGet8 (PcdTpm2SelfTestPolicy) == 1) {
Status = Tpm2SelfTest (NO);
if (EFI_ERROR (Status)) {
// MU_CHANGE_58957
// MU_CHANGE [BEGIN] - Make sure that TPM2_Startup() can report an error.
DEBUG ((DEBUG_ERROR, "Tcg2Pei::%a - TPM failed Startup!\n", __func__));
// MU_CHANGE [END]
goto Done;
}
}
Expand Down

0 comments on commit 9c633e5

Please sign in to comment.