Skip to content

Commit

Permalink
TpmTestingPkg: Add InputChannelLib
Browse files Browse the repository at this point in the history
Adds a new library class (InputChannelLib) that allows the TPM replay
event log to be passed through a platform-specific mechanism.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Nov 6, 2023
1 parent 07533b7 commit 10651f5
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 8 deletions.
36 changes: 36 additions & 0 deletions TpmTestingPkg/Include/Library/InputChannelLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @file
TPM Event Log Input Channel Library
Allows a TPM replay log to be passed through a custom interface.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef INPUT_CHANNEL_LIB_H
#define INPUT_CHANNEL_LIB_H

#include <Guid/TpmReplayEventLog.h>

/**
Retrieves a TPM Replay Event Log through a custom interface.
@param[out] ReplayEventLog A pointer to a pointer to the buffer to hold the event log data.
@param[out] ReplayEventLogSize The size of the data placed in the buffer.
@retval EFI_SUCCESS The TPM Replay event log was returned successfully.
@retval EFI_INVALID_PARAMETER A pointer argument given is NULL.
@retval EFI_UNSUPPORTED The function is not implemented yet. The arguments are not used.
@retval EFI_COMPROMISED_DATA The event log data found is not valid.
@retval EFI_NOT_FOUND The event log data was not found. The input channel is ignored in this case.
**/
EFI_STATUS
EFIAPI
GetReplayEventLogFromCustomInterface (
OUT VOID **ReplayEventLog,
OUT UINTN *ReplayEventLogSize
);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @file
A null instance of the Input Channel Library.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Uefi.h>
#include <Library/InputChannelLib.h>

/**
Retrieves a TPM Replay Event Log through a custom interface.
@param[out] ReplayEventLog A pointer to a pointer to the buffer to hold the event log data.
@param[out] ReplayEventLogSize The size of the data placed in the buffer.
@retval EFI_SUCCESS The TPM Replay event log was returned successfully.
@retval EFI_INVALID_PARAMETER A pointer argument given is NULL.
@retval EFI_UNSUPPORTED The function is not implemented yet. The arguments are not used.
@retval EFI_COMPROMISED_DATA The event log data found is not valid.
@retval EFI_NOT_FOUND The event log data was not found. The input channel is ignored in this case.
**/
EFI_STATUS
EFIAPI
GetReplayEventLogFromCustomInterface (
OUT VOID **ReplayEventLog,
OUT UINTN *ReplayEventLogSize
)
{
return EFI_NOT_FOUND;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## @file
# A null instance of the Input Channel Library.
#
# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BaseInputChannelLibNull
FILE_GUID = F35B1671-08BC-4231-9CEB-A08E809E32FF
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = InputChannelLib

[Packages]
MdePkg/MdePkg.dec
SecurityPkg/SecurityPkg.dec
TpmTestingPkg/TpmTestingPkg.dec

[Sources]
BaseInputChannelLibNull.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
**/

#include <PiPei.h>
#include <Guid/TpmReplayEventLog.h>
#include <Library/DebugLib.h>
#include <Library/PeiServicesLib.h>

#include "../TpmReplayEventLog.h"
#include "TpmReplayInputChannelInternal.h"

/**
Expand Down
15 changes: 13 additions & 2 deletions TpmTestingPkg/TpmReplayPei/InputChannel/TpmReplayInputChannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
**/

#include <Uefi.h>
#include <Guid/TpmReplayEventLog.h>
#include <Library/DebugLib.h>
#include <Library/InputChannelLib.h>

#include "../TpmReplayEventLog.h"
#include "TpmReplayInputChannel.h"
#include "TpmReplayInputChannelInternal.h"

Expand Down Expand Up @@ -48,10 +49,20 @@ GetReplayEventLog (
goto Done;
}

// Second priority: FFS in the FW image
// Second priority: Custom interface
Status = GetReplayEventLogFromCustomInterface (&ReplayEventLogData, &ReplayEventLogDataSize);
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "[%a] - Using TPM replay event log from a custom interface.\n", __func__));
goto Done;
} else if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
DEBUG ((DEBUG_ERROR, "[%a] - TPM replay event log from custom interface failed - %r.\n", __func__, Status));
}

// Third priority: FFS in the FW image
Status = GetTpmReplayEventLogFfsFile (&ReplayEventLogData, &ReplayEventLogDataSize);
ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "[%a] - Using TPM replay event log from the firmware flash image.\n", __func__));
goto Done;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef TPM_REPLAY_INPUT_CHANNEL_H_
#define TPM_REPLAY_INPUT_CHANNEL_H_

#include "../TpmReplayEventLog.h"
#include <Guid/TpmReplayEventLog.h>

/**
Retrieves a TPM Replay Event Log from the highest priority input channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef TPM_REPLAY_INPUT_CHANNEL_INTERNAL_H_
#define TPM_REPLAY_INPUT_CHANNEL_INTERNAL_H_

#include "../TpmReplayEventLog.h"
#include <Guid/TpmReplayEventLog.h>

/**
Retrieves a TPM Replay Event Log from a FFS file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
**/

#include <PiPei.h>
#include <Guid/TpmReplayEventLog.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PeiServicesLib.h>
#include <Ppi/ReadOnlyVariable2.h>

#include "../TpmReplayEventLog.h"
#include "TpmReplayInputChannelInternal.h"

/**
Expand Down
2 changes: 1 addition & 1 deletion TpmTestingPkg/TpmReplayPei/Pei/TpmReplayPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
ENTRY_POINT = TpmReplayPeiEntryPoint

[Sources]
../TpmReplayEventLog.h
../TpmReplayReportingManager.c
../TpmReplayReportingManager.h
../TpmReplayTcg.c
Expand Down Expand Up @@ -51,6 +50,7 @@
DebugLib
FvMeasurementExclusionLib
HobLib
InputChannelLib
IoLib
MemoryAllocationLib
PcdLib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <PiPei.h>

#include <Guid/TcgEventHob.h>
#include <Guid/TpmReplayEventLog.h>
#include <IndustryStandard/Tpm2Acpi.h> // For locality code
#include <IndustryStandard/TpmPtp.h> // For locality code
#include <Library/BaseLib.h>
Expand All @@ -32,7 +33,6 @@

#include <TpmReplayConfig.h>
#include "../InputChannel/TpmReplayInputChannel.h"
#include "../TpmReplayEventLog.h"
#include "../TpmReplayReportingManager.h"
#include "../TpmReplayTcg.h"
#include "../TpmReplayTcgRegs.h"
Expand Down
1 change: 1 addition & 0 deletions TpmTestingPkg/TpmTestingPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

[LibraryClasses]
FvMeasurementExclusionLib|Include/Library/FvMeasurementExclusionLib.h
InputChannelLib|Include/Library/InputChannelLib.h

[Guids]
## Tokenspace GUID for TPM Testing Package PCDs
Expand Down
2 changes: 2 additions & 0 deletions TpmTestingPkg/TpmTestingPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
FvMeasurementExclusionLib|TpmTestingPkg/Library/BaseFvMeasurementExclusionLibNull/BaseFvMeasurementExclusionLibNull.inf
InputChannelLib|TpmTestingPkg/Library/BaseInputChannelLibNull/BaseInputChannelLibNull.inf
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf
Expand Down Expand Up @@ -85,6 +86,7 @@

[Components]
TpmTestingPkg/Library/BaseFvMeasurementExclusionLibNull/BaseFvMeasurementExclusionLibNull.inf
TpmTestingPkg/Library/BaseInputChannelLibNull/BaseInputChannelLibNull.inf
TpmTestingPkg/TpmReplayPei/Pei/TpmReplayPei.inf

#
Expand Down

0 comments on commit 10651f5

Please sign in to comment.