SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c File Reference


Defines

#define PERF_ID_TCG2_PEI   0x3080

Functions

EFI_STATUS EFIAPI FirmwareVolmeInfoPpiNotifyCallback (IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack (IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS Tpm2GetDigestFromDigestList (IN TPMI_ALG_HASH HashAlg, IN TPML_DIGEST_VALUES *DigestList, IN VOID *Digest)
BOOLEAN IsZeroBuffer (IN VOID *Buffer, IN UINTN BufferSize)
UINT32 GetDigestListSize (IN TPML_DIGEST_VALUES *DigestList)
BOOLEAN IsHashAlgSupportedInPcrBank (IN TPMI_ALG_HASH HashAlg)
VOID * CopyDigestListToBuffer (IN OUT VOID *Buffer, IN TPML_DIGEST_VALUES *DigestList)
VOID SetTpm2HashMask (VOID)
EFI_STATUS LogHashEvent (IN TPML_DIGEST_VALUES *DigestList, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
EFI_STATUS HashLogExtendEvent (IN UINT64 Flags, IN UINT8 *HashData, IN UINTN HashDataLen, IN TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
EFI_STATUS MeasureCRTMVersion (VOID)
EFI_STATUS MeasureFvImage (IN EFI_PHYSICAL_ADDRESS FvBase, IN UINT64 FvLength)
EFI_STATUS MeasureMainBios (VOID)
EFI_STATUS PeimEntryMP (IN EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI PeimEntryMA (IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)

Variables

TCG2_EVENT_INFO_STRUCT mTcg2EventInfo []
BOOLEAN mImageInMemory = FALSE
EFI_PEI_FILE_HANDLE mFileHandle
EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList
EFI_PLATFORM_FIRMWARE_BLOB * mMeasuredBaseFvInfo
UINT32 mMeasuredBaseFvIndex = 0
EFI_PLATFORM_FIRMWARE_BLOB * mMeasuredChildFvInfo
UINT32 mMeasuredChildFvIndex = 0
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList []
EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPImMeasurementExcludedFvPpi

Detailed Description

Initialize TPM2 device and measure FVs before handing off control to DXE.

Copyright (c) 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.


Define Documentation

#define PERF_ID_TCG2_PEI   0x3080

Referenced by MeasureMainBios().


Function Documentation

VOID* CopyDigestListToBuffer ( IN OUT VOID *  Buffer,
IN TPML_DIGEST_VALUES *  DigestList 
)

Copy TPML_DIGEST_VALUES into a buffer

Parameters:
[in,out] Buffer Buffer to hold TPML_DIGEST_VALUES.
[in] DigestList TPML_DIGEST_VALUES to be copied.
Returns:
The end of buffer to hold TPML_DIGEST_VALUES.

References GetHashSizeFromAlgo(), IsHashAlgSupportedInPcrBank(), and UINTN().

EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack ( IN EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *  NotifyDescriptor,
IN VOID *  Ppi 
)

Record all measured Firmware Volum Information into a Guid Hob

Parameters:
[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in] NotifyDescriptor Address of the notification descriptor data structure.
[in] Ppi Address of the PPI that was installed.
Return values:
EFI_SUCCESS The FV Info is measured and recorded to TPM.
Returns:
Others Fail to measure FV.
Record all measured Firmware Volum Information into a Guid Hob Guid Hob payload layout is

UINT32 *************************** FIRMWARE_BLOB number EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array

Parameters:
[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in] NotifyDescriptor Address of the notification descriptor data structure.
[in] Ppi Address of the PPI that was installed.
Return values:
EFI_SUCCESS The FV Info is measured and recorded to TPM.
Returns:
Others Fail to measure FV.

References gMeasuredFvHobGuid, MEASURED_HOB_DATA::MeasuredFvBuf, mMeasuredBaseFvIndex, mMeasuredBaseFvInfo, mMeasuredChildFvIndex, mMeasuredChildFvInfo, MEASURED_HOB_DATA::Num, and UINTN().

EFI_STATUS EFIAPI FirmwareVolmeInfoPpiNotifyCallback ( IN EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *  NotifyDescriptor,
IN VOID *  Ppi 
)

Measure and record the Firmware Volum Information once FvInfoPPI install.

Parameters:
[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in] NotifyDescriptor Address of the notification descriptor data structure.
[in] Ppi Address of the PPI that was installed.
Return values:
EFI_SUCCESS The FV Info is measured and recorded to TPM.
Returns:
Others Fail to measure FV.

References EFI_STATUS(), MeasureFvImage(), mMeasuredChildFvIndex, mMeasuredChildFvInfo, and UINTN().

UINT32 GetDigestListSize ( IN TPML_DIGEST_VALUES *  DigestList  ) 

Get TPML_DIGEST_VALUES data size.

Parameters:
[in] DigestList TPML_DIGEST_VALUES data.
Returns:
TPML_DIGEST_VALUES data size.

References GetHashSizeFromAlgo(), and UINTN().

EFI_STATUS HashLogExtendEvent ( IN UINT64  Flags,
IN UINT8 *  HashData,
IN UINTN  HashDataLen,
IN TCG_PCR_EVENT_HDR *  NewEventHdr,
IN UINT8 *  NewEventData 
)

Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and build a GUIDed HOB recording the event which will be passed to the DXE phase and added into the Event Log.

Parameters:
[in] Flags Bitmap providing additional information.
[in] HashData Physical address of the start of the data buffer to be hashed, extended, and logged.
[in] HashDataLen The length, in bytes, of the buffer referenced by HashData.
[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
[in] NewEventData Pointer to the new event data.
Return values:
EFI_SUCCESS Operation completed successfully.
EFI_OUT_OF_RESOURCES No enough memory to log the new event.
EFI_DEVICE_ERROR The command was unsuccessful.

References EFI_STATUS(), gTpmErrorHobGuid, HashAndExtend(), and LogHashEvent().

Referenced by MeasureCRTMVersion(), and MeasureFvImage().

BOOLEAN IsHashAlgSupportedInPcrBank ( IN TPMI_ALG_HASH  HashAlg  ) 

Return if hash alg is supported in TPM PCR bank.

Parameters:
HashAlg Hash algorithm to be checked.
Return values:
TRUE Hash algorithm is supported.
FALSE Hash algorithm is not supported.

References TRUE.

BOOLEAN IsZeroBuffer ( IN VOID *  Buffer,
IN UINTN  BufferSize 
)

Check if buffer is all zero.

Parameters:
[in] Buffer Buffer to be checked.
[in] BufferSize Size of buffer to be checked.
Return values:
TRUE Buffer is all zero.
FALSE Buffer is not all zero.

References TRUE, and UINTN().

EFI_STATUS LogHashEvent ( IN TPML_DIGEST_VALUES *  DigestList,
IN OUT TCG_PCR_EVENT_HDR *  NewEventHdr,
IN UINT8 *  NewEventData 
)

Add a new entry to the Event Log.

Parameters:
[in] DigestList A list of digest.
[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
[in] NewEventData Pointer to the new event data.
Return values:
EFI_SUCCESS The new event log entry was added.
EFI_OUT_OF_RESOURCES No enough memory to log the new event.

References CopyDigestListToBuffer(), EFI_STATUS(), EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2, GetDigestListSize(), gTcgEvent2EntryHobGuid, gTcgEventEntryHobGuid, mTcg2EventInfo, Tpm2GetDigestFromDigestList(), and UINTN().

Referenced by HashLogExtendEvent().

EFI_STATUS MeasureCRTMVersion ( VOID   ) 

Measure CRTM version.

Return values:
EFI_SUCCESS Operation completed successfully.
EFI_OUT_OF_RESOURCES No enough memory to log the new event.
EFI_DEVICE_ERROR The command was unsuccessful.

References HashLogExtendEvent().

Referenced by PeimEntryMP().

EFI_STATUS MeasureFvImage ( IN EFI_PHYSICAL_ADDRESS  FvBase,
IN UINT64  FvLength 
)

Measure FV image. Add it into the measured FV list after the FV is measured successfully.

Parameters:
[in] FvBase Base address of FV image.
[in] FvLength Length of FV image.
Return values:
EFI_SUCCESS Fv image is measured successfully or it has been already measured.
EFI_OUT_OF_RESOURCES No enough memory to log the new event.
EFI_DEVICE_ERROR The command was unsuccessful.

References EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI::Count, EFI_STATUS(), EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI::Fv, EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_FV::FvBase, HashLogExtendEvent(), mMeasuredBaseFvIndex, mMeasuredBaseFvInfo, and UINTN().

Referenced by FirmwareVolmeInfoPpiNotifyCallback(), and MeasureMainBios().

EFI_STATUS MeasureMainBios ( VOID   ) 

Measure main BIOS.

Return values:
EFI_SUCCESS Operation completed successfully.
EFI_OUT_OF_RESOURCES No enough memory to log the new event.
EFI_DEVICE_ERROR The command was unsuccessful.

References EFI_STATUS(), MeasureFvImage(), mFileHandle, PERF_ID_TCG2_PEI, TRUE, and UINTN().

Referenced by PeimEntryMP().

EFI_STATUS EFIAPI PeimEntryMA ( IN EFI_PEI_FILE_HANDLE  FileHandle,
IN CONST EFI_PEI_SERVICES **  PeiServices 
)

Entry point of this module.

Parameters:
[in] FileHandle Handle of the file being invoked.
[in] PeiServices Describes the list of possible PEI Services.
Returns:
Status.

References EFI_STATUS(), gEfiTpmDeviceInstanceNoneGuid, gEfiTpmDeviceInstanceTpm12Guid, gTpmErrorHobGuid, mFileHandle, mImageInMemory, mTpmInitializationDonePpiList, mTpmInitializedPpiList, PeimEntryMP(), SetTpm2HashMask(), Tpm2RequestUseTpm(), Tpm2SelfTest(), Tpm2Startup(), and TRUE.

EFI_STATUS PeimEntryMP ( IN EFI_PEI_SERVICES **  PeiServices  ) 

Do measurement after memory is ready.

Parameters:
[in] PeiServices Describes the list of possible PEI Services.
Return values:
EFI_SUCCESS Operation completed successfully.
EFI_OUT_OF_RESOURCES No enough memory to log the new event.
EFI_DEVICE_ERROR The command was unsuccessful.

References EFI_STATUS(), gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid, MeasureCRTMVersion(), MeasureMainBios(), mMeasuredBaseFvInfo, mMeasuredChildFvInfo, and mNotifyList.

Referenced by PeimEntryMA().

VOID SetTpm2HashMask ( VOID   ) 

Set Tpm2HashMask PCD value accroding to TPM2 PCR bank.

References EFI_STATUS(), IsZeroBuffer(), Tpm2GetCapabilityPcrs(), and UINTN().

Referenced by PeimEntryMA().

EFI_STATUS Tpm2GetDigestFromDigestList ( IN TPMI_ALG_HASH  HashAlg,
IN TPML_DIGEST_VALUES *  DigestList,
IN VOID *  Digest 
)

This function get digest from digest list.

Parameters:
HashAlg digest algorithm
DigestList digest list
Digest digest
Return values:
EFI_SUCCESS Sha1Digest is found and returned.
EFI_NOT_FOUND Sha1Digest is not found.

References GetHashSizeFromAlgo(), and UINTN().


Variable Documentation

EFI_PEI_FILE_HANDLE mFileHandle

Referenced by MeasureMainBios(), and PeimEntryMA().

BOOLEAN mImageInMemory = FALSE

Referenced by PeimEntryMA().

EFI_PLATFORM_FIRMWARE_BLOB* mMeasuredBaseFvInfo

EFI_PLATFORM_FIRMWARE_BLOB* mMeasuredChildFvInfo

EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList[]

Initial value:

 {
  {
    EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
    &gEfiPeiFirmwareVolumeInfoPpiGuid,
    FirmwareVolmeInfoPpiNotifyCallback 
  },
  {
    EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
    &gEfiPeiFirmwareVolumeInfo2PpiGuid,
    FirmwareVolmeInfoPpiNotifyCallback 
  },
  {
    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    &gEfiEndOfPeiSignalPpiGuid,
    EndofPeiSignalNotifyCallBack
  }
}

Referenced by PeimEntryMP().

TCG2_EVENT_INFO_STRUCT mTcg2EventInfo[]

EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList

Initial value:

 {
  EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
  &gPeiTpmInitializationDonePpiGuid,
  NULL
}

EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList

Initial value:

 {
  EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
  &gPeiTpmInitializedPpiGuid,
  NULL
}

Referenced by PeimEntryMA().


Generated on Thu Sep 24 23:44:24 2015 for SecurityPkg[ALL] by  doxygen 1.5.7.1