TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeTpmMeasureBootLib.c File Reference

Go to the source code of this file.

Functions

EFI_STATUS EFIAPI DxeTpmMeasureBootLibImageRead (IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
 
EFI_STATUS EFIAPI TcgMeasureGptTable (IN EFI_TCG_PROTOCOL *TcgProtocol, IN EFI_HANDLE GptHandle)
 
EFI_STATUS EFIAPI TcgMeasurePeImage (IN EFI_TCG_PROTOCOL *TcgProtocol, IN EFI_PHYSICAL_ADDRESS ImageAddress, IN UINTN ImageSize, IN UINTN LinkTimeBase, IN UINT16 ImageType, IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
 
EFI_STATUS EFIAPI DxeTpmMeasureBootHandler (IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *File OPTIONAL, IN VOID *FileBuffer, IN UINTN FileSize, IN BOOLEAN BootPolicy)
 
EFI_STATUS EFIAPI DxeTpmMeasureBootLibConstructor (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

BOOLEAN mMeasureGptTableFlag = FALSE
 
UINTN mMeasureGptCount = 0
 
VOID * mFileBuffer
 
UINTN mTpmImageSize
 
EFI_HANDLE mCacheMeasuredHandle = NULL
 
MEASURED_HOB_DATAmMeasuredHobData = NULL
 

Detailed Description

The library instance provides security service of TPM measure boot.

Caution: This file requires additional review when modified. This library will have external input - PE/COFF image and GPT partition. This external input must be validated carefully to avoid security issue like buffer overflow, integer overflow.

DxeTpmMeasureBootLibImageRead() function will make sure the PE/COFF image content read is within the image buffer.

TcgMeasurePeImage() function will accept untrusted PE/COFF image and validate its data structure within this image buffer before use.

TcgMeasureGptTable() function will receive untrusted GPT partition table, and parse partition data carefully.

Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent Copyright (c) Microsoft Corporation.

Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file DxeTpmMeasureBootLib.c.

Function Documentation

◆ DxeTpmMeasureBootHandler()

EFI_STATUS EFIAPI DxeTpmMeasureBootHandler ( IN UINT32  AuthenticationStatus,
IN CONST EFI_DEVICE_PATH_PROTOCOL *File  OPTIONAL,
IN VOID *  FileBuffer,
IN UINTN  FileSize,
IN BOOLEAN  BootPolicy 
)

The security handler is used to abstract platform-specific policy from the DXE core response to an attempt to use a file that returns a given status for the authentication check from the section extraction protocol.

The possible responses in a given SAP implementation may include locking flash upon failure to authenticate, attestation logging for all signed drivers, and other exception operations. The File parameter allows for possible logging within the SAP of the driver.

If the file specified by File with an authentication status specified by AuthenticationStatus is safe for the DXE Core to use, then EFI_SUCCESS is returned.

If the file specified by File with an authentication status specified by AuthenticationStatus is not safe for the DXE Core to use under any circumstances, then EFI_ACCESS_DENIED is returned.

If the file specified by File with an authentication status specified by AuthenticationStatus is not safe for the DXE Core to use right now, but it might be possible to use it at a future time, then EFI_SECURITY_VIOLATION is returned.

If check image specified by FileBuffer and File is NULL meanwhile, return EFI_ACCESS_DENIED.

Parameters
[in]AuthenticationStatusThis is the authentication status returned from the securitymeasurement services for the input file.
[in]FileThis is a pointer to the device path of the file that is being dispatched. This will optionally be used for logging.
[in]FileBufferFile buffer matches the input file device path.
[in]FileSizeSize of File buffer matches the input file device path.
[in]BootPolicyA boot policy that was used to call LoadImage() UEFI service.
Return values
EFI_SUCCESSThe file specified by DevicePath and non-NULL FileBuffer did authenticate, and the platform policy dictates that the DXE Foundation may use the file.
othererror value

Definition at line 740 of file DxeTpmMeasureBootLib.c.

◆ DxeTpmMeasureBootLibConstructor()

EFI_STATUS EFIAPI DxeTpmMeasureBootLibConstructor ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Register the security handler to provide TPM measure boot service.

Parameters
ImageHandleImageHandle of the loaded driver.
SystemTablePointer to the EFI System Table.
Return values
EFI_SUCCESSRegister successfully.
EFI_OUT_OF_RESOURCESNo enough memory to register this handler.

Definition at line 1013 of file DxeTpmMeasureBootLib.c.

◆ DxeTpmMeasureBootLibImageRead()

EFI_STATUS EFIAPI DxeTpmMeasureBootLibImageRead ( IN VOID *  FileHandle,
IN UINTN  FileOffset,
IN OUT UINTN ReadSize,
OUT VOID *  Buffer 
)

Reads contents of a PE/COFF image in memory buffer.

Caution: This function may receive untrusted input. PE/COFF image is external input, so this function will make sure the PE/COFF image content read is within the image buffer.

Parameters
FileHandlePointer to the file handle to read the PE/COFF image.
FileOffsetOffset into the PE/COFF image to begin the read operation.
ReadSizeOn input, the size in bytes of the requested read operation. On output, the number of bytes actually read.
BufferOutput buffer that contains the data read from the PE/COFF image.
Return values
EFI_SUCCESSThe specified portion of the PE/COFF image was read and the size

Definition at line 78 of file DxeTpmMeasureBootLib.c.

◆ TcgMeasureGptTable()

EFI_STATUS EFIAPI TcgMeasureGptTable ( IN EFI_TCG_PROTOCOL TcgProtocol,
IN EFI_HANDLE  GptHandle 
)

Measure GPT table data into TPM log.

Caution: This function may receive untrusted input. The GPT partition table is external input, so this function should parse partition data carefully.

Parameters
TcgProtocolPointer to the located TCG protocol instance.
GptHandleHandle that GPT partition was installed.
Return values
EFI_SUCCESSSuccessfully measure GPT table.
EFI_UNSUPPORTEDNot support GPT table on the given handle.
EFI_DEVICE_ERRORCan't get GPT table because device error.
EFI_OUT_OF_RESOURCESNo enough resource to measure GPT table.
othererror value

Definition at line 126 of file DxeTpmMeasureBootLib.c.

◆ TcgMeasurePeImage()

EFI_STATUS EFIAPI TcgMeasurePeImage ( IN EFI_TCG_PROTOCOL TcgProtocol,
IN EFI_PHYSICAL_ADDRESS  ImageAddress,
IN UINTN  ImageSize,
IN UINTN  LinkTimeBase,
IN UINT16  ImageType,
IN EFI_DEVICE_PATH_PROTOCOL FilePath 
)

Measure PE image into TPM log based on the authenticode image hashing in PE/COFF Specification 8.0 Appendix A.

Caution: This function may receive untrusted input. PE/COFF image is external input, so this function will validate its data structure within this image buffer before use.

Notes: PE/COFF image has been checked by BasePeCoffLib PeCoffLoaderGetImageInfo() in its caller function DxeTpmMeasureBootHandler().

Parameters
[in]TcgProtocolPointer to the located TCG protocol instance.
[in]ImageAddressStart address of image buffer.
[in]ImageSizeImage size
[in]LinkTimeBaseAddress that the image is loaded into memory.
[in]ImageTypeImage subsystem type.
[in]FilePathFile path is corresponding to the input image.
Return values
EFI_SUCCESSSuccessfully measure image.
EFI_OUT_OF_RESOURCESNo enough resource to measure image.
EFI_UNSUPPORTEDImageType is unsupported or PE image is mal-format.
othererror value

Definition at line 313 of file DxeTpmMeasureBootLib.c.

Variable Documentation

◆ mCacheMeasuredHandle

EFI_HANDLE mCacheMeasuredHandle = NULL

Definition at line 58 of file DxeTpmMeasureBootLib.c.

◆ mFileBuffer

VOID* mFileBuffer

Definition at line 53 of file DxeTpmMeasureBootLib.c.

◆ mMeasuredHobData

MEASURED_HOB_DATA* mMeasuredHobData = NULL

Definition at line 59 of file DxeTpmMeasureBootLib.c.

◆ mMeasureGptCount

UINTN mMeasureGptCount = 0

Definition at line 52 of file DxeTpmMeasureBootLib.c.

◆ mMeasureGptTableFlag

BOOLEAN mMeasureGptTableFlag = FALSE

Definition at line 51 of file DxeTpmMeasureBootLib.c.

◆ mTpmImageSize

UINTN mTpmImageSize

Definition at line 54 of file DxeTpmMeasureBootLib.c.