TianoCore EDK2 master
|
#include <PiDxe.h>
#include <Protocol/TcgService.h>
#include <Protocol/BlockIo.h>
#include <Protocol/DiskIo.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Guid/MeasuredFvHob.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DevicePathLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseCryptLib.h>
#include <Library/PeCoffLib.h>
#include <Library/SecurityManagementLib.h>
#include <Library/HobLib.h>
#include "DxeTpmMeasureBootLibSanitization.h"
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_DATA * | mMeasuredHobData = NULL |
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.
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.
[in] | AuthenticationStatus | This is the authentication status returned from the securitymeasurement services for the input file. |
[in] | File | This is a pointer to the device path of the file that is being dispatched. This will optionally be used for logging. |
[in] | FileBuffer | File buffer matches the input file device path. |
[in] | FileSize | Size of File buffer matches the input file device path. |
[in] | BootPolicy | A boot policy that was used to call LoadImage() UEFI service. |
EFI_SUCCESS | The file specified by DevicePath and non-NULL FileBuffer did authenticate, and the platform policy dictates that the DXE Foundation may use the file. |
other | error value |
Definition at line 740 of file DxeTpmMeasureBootLib.c.
EFI_STATUS EFIAPI DxeTpmMeasureBootLibConstructor | ( | IN EFI_HANDLE | ImageHandle, |
IN EFI_SYSTEM_TABLE * | SystemTable | ||
) |
Register the security handler to provide TPM measure boot service.
ImageHandle | ImageHandle of the loaded driver. |
SystemTable | Pointer to the EFI System Table. |
EFI_SUCCESS | Register successfully. |
EFI_OUT_OF_RESOURCES | No enough memory to register this handler. |
Definition at line 1013 of file DxeTpmMeasureBootLib.c.
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.
FileHandle | Pointer to the file handle to read the PE/COFF image. |
FileOffset | Offset into the PE/COFF image to begin the read operation. |
ReadSize | On input, the size in bytes of the requested read operation. On output, the number of bytes actually read. |
Buffer | Output buffer that contains the data read from the PE/COFF image. |
EFI_SUCCESS | The specified portion of the PE/COFF image was read and the size |
Definition at line 78 of file DxeTpmMeasureBootLib.c.
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.
TcgProtocol | Pointer to the located TCG protocol instance. |
GptHandle | Handle that GPT partition was installed. |
EFI_SUCCESS | Successfully measure GPT table. |
EFI_UNSUPPORTED | Not support GPT table on the given handle. |
EFI_DEVICE_ERROR | Can't get GPT table because device error. |
EFI_OUT_OF_RESOURCES | No enough resource to measure GPT table. |
other | error value |
Definition at line 126 of file DxeTpmMeasureBootLib.c.
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().
[in] | TcgProtocol | Pointer to the located TCG protocol instance. |
[in] | ImageAddress | Start address of image buffer. |
[in] | ImageSize | Image size |
[in] | LinkTimeBase | Address that the image is loaded into memory. |
[in] | ImageType | Image subsystem type. |
[in] | FilePath | File path is corresponding to the input image. |
EFI_SUCCESS | Successfully measure image. |
EFI_OUT_OF_RESOURCES | No enough resource to measure image. |
EFI_UNSUPPORTED | ImageType is unsupported or PE image is mal-format. |
other | error value |
Definition at line 313 of file DxeTpmMeasureBootLib.c.
EFI_HANDLE mCacheMeasuredHandle = NULL |
Definition at line 58 of file DxeTpmMeasureBootLib.c.
VOID* mFileBuffer |
Definition at line 53 of file DxeTpmMeasureBootLib.c.
MEASURED_HOB_DATA* mMeasuredHobData = NULL |
Definition at line 59 of file DxeTpmMeasureBootLib.c.
UINTN mMeasureGptCount = 0 |
Definition at line 52 of file DxeTpmMeasureBootLib.c.
BOOLEAN mMeasureGptTableFlag = FALSE |
Definition at line 51 of file DxeTpmMeasureBootLib.c.
UINTN mTpmImageSize |
Definition at line 54 of file DxeTpmMeasureBootLib.c.