Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecurityPkg: Add measurement of Firmware Debugger Enabled based on DeviceState #342

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SecurityPkg/SecurityPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
MemLibWrapper|SecurityPkg/DeviceSecurity/OsStub/MemLibWrapper/MemLibWrapper.inf
NULL|MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf # MU_CHANGE: /GS and -fstack-protector support

## MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled
DeviceStateLib|MdeModulePkg/Library/DeviceStateLib/DeviceStateLib.inf
PanicLib|MdePkg/Library/BasePanicLibNull/BasePanicLibNull.inf
# MU_CHANGE [END]

[LibraryClasses.X64, LibraryClasses.IA32]
Tcg2PreUefiEventLogLib|SecurityPkg/Library/Tcg2PreUefiEventLogLibNull/Tcg2PreUefiEventLogLibNull.inf ## MU_CHANGE

Expand Down
20 changes: 20 additions & 0 deletions SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// MU_CHANGE [BEGIN] - Add the OemTpm2InitLib
#include <Library/OemTpm2InitLib.h>
// MU_CHANGE [END]
// MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled
#include <Library/DeviceStateLib.h>
#include <Library/PanicLib.h>
// MU_CHANGE [END]

// #define PERF_ID_TCG2_DXE 0x3120 // MU_CHANGE

Expand Down Expand Up @@ -2500,11 +2504,27 @@ MeasureSecureBootPolicy (
EFI_STATUS Status;
VOID *Protocol;

DEVICE_STATE CurrentDeviceState; // MU_CHANGE - Measure Firmware Debugger Enabled
VivianNK marked this conversation as resolved.
Show resolved Hide resolved

Status = gBS->LocateProtocol (&gEfiVariableWriteArchProtocolGuid, NULL, (VOID **)&Protocol);
if (EFI_ERROR (Status)) {
return;
}

// MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled
CurrentDeviceState = GetDeviceState ();

if ((CurrentDeviceState & DEVICE_STATE_SOURCE_DEBUG_ENABLED) != 0) {
Status = MeasureLaunchOfFirmwareDebugger ();
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to measure Firmware Debugger Enabled!\n"));
PanicReport (__FILE__, __LINE__, "Failed to measure Firmware Debugger Enabled!\n");
return;
}
}

// MU_CHANGE [END]

if (PcdGetBool (PcdFirmwareDebuggerInitialized)) {
Status = MeasureLaunchOfFirmwareDebugger ();
DEBUG ((DEBUG_INFO, "MeasureLaunchOfFirmwareDebugger - %r\n", Status));
Expand Down
4 changes: 4 additions & 0 deletions SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
OemTpm2InitLib
## MU_CHANGE [END]
PcdLib # MU_CHANGE
## MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled
DeviceStateLib
PanicLib
## MU_CHANGE [END]

[Guids]
## SOMETIMES_CONSUMES ## Variable:L"SecureBoot"
Expand Down
53 changes: 53 additions & 0 deletions SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// MU_CHANGE [BEGIN] - Move to 256-bit PCRs.
#include <Library/Tcg2PreUefiEventLogLib.h>
// MU_CHANGE [END]
// MU_CHANGE [BEGIN] - Measure DebugEnabled and Insecure Device State into PCR7
#include <Library/DeviceStateLib.h>
#include <Library/PanicLib.h>
// MU_CHANGE [END]
#define PERF_ID_TCG2_PEI 0x3080

typedef struct {
Expand Down Expand Up @@ -644,6 +648,39 @@ MeasureCRTMVersion (
);
}

// MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled

/**
Measure and log firmware debugger enabled, and extend the measurement result into a specific PCR.

@retval EFI_SUCCESS Operation completed successfully.
@retval EFI_OUT_OF_RESOURCES Out of memory.
@retval EFI_DEVICE_ERROR The operation was unsuccessful.
**/
EFI_STATUS
MeasureFirmwareDebuggerEnabled (
VOID
)
{
TCG_PCR_EVENT_HDR TcgEventHdr;

TcgEventHdr.PCRIndex = 7;
TcgEventHdr.EventType = EV_EFI_ACTION;
TcgEventHdr.EventSize = sizeof (FIRMWARE_DEBUGGER_EVENT_STRING) - 1;

DEBUG ((DEBUG_INFO, "Measuring Device State: Firmware Debugger Enabled\n"));
return HashLogExtendEvent (
&mEdkiiTcgPpi,
0,
(UINT8 *)FIRMWARE_DEBUGGER_EVENT_STRING,
sizeof (FIRMWARE_DEBUGGER_EVENT_STRING) - 1,
&TcgEventHdr,
(UINT8 *)FIRMWARE_DEBUGGER_EVENT_STRING
);
}

// MU_CHANGE [END]

/**
Get the FvName from the FV header.

Expand Down Expand Up @@ -1062,6 +1099,8 @@ PeimEntryMP (
{
EFI_STATUS Status;

DEVICE_STATE CurrentDeviceState; // MU_CHANGE - Measure Firmware Debugger Enabled

//
// install Tcg Services
//
Expand All @@ -1073,6 +1112,20 @@ PeimEntryMP (
CreateTcg2PreUefiEventLogEntries ();
// MU_CHANGE [END]

// MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled
CurrentDeviceState = GetDeviceState ();

if ((CurrentDeviceState & DEVICE_STATE_SOURCE_DEBUG_ENABLED) != 0) {
Status = MeasureFirmwareDebuggerEnabled ();
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to measure Firmware Debugger Enabled!\n"));
PanicReport (__FILE__, __LINE__, "Failed to measure Firmware Debugger Enabled!\n");
return Status;
}
}

// MU_CHANGE [END]

if (PcdGet8 (PcdTpm2ScrtmPolicy) == 1) {
Status = MeasureCRTMVersion ();
}
Expand Down
4 changes: 4 additions & 0 deletions SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
Tcg2PreUefiEventLogLib
## MU_CHANGE [END]
VivianNK marked this conversation as resolved.
Show resolved Hide resolved

## MU_CHANGE [BEGIN] - Measure Firmware Debugger Enabled
DeviceStateLib
PanicLib
## MU_CHANGE [END]
[Guids]
gTcgEventEntryHobGuid ## PRODUCES ## HOB
gTpmErrorHobGuid ## SOMETIMES_PRODUCES ## HOB
Expand Down
Loading