ovmf: preliminary TPM2 support
v3 cover ovmf: preliminary TPM2 support
From: Marc-André Lureau <[email protected]>
Hi,
The following series adds basic TPM2 support for OVMF-on-QEMU (I haven't tested TPM1, for lack of interest). It links with the modules to initializes the device in PEI phase, and do measurements (both PEI and DXE). The Tcg2Dxe module provides the Tcg2 protocol which allows the guest to access the measurement log and other facilities.
DxeTpm2MeasureBootLib seems to do its job at measuring images that are not measured in PEI phase (such as PCI PXE rom)
Tcg2ConfigDxe is not included due to its integration with edk2 own PPI implementation which conflicts with qemu design. PPI design is still being discussed & experimented at this point.
Linux guests seem to work fine. But windows guest generally complains about the lack of PPI interface (most HLK tests require it, tpm.msc admin interactions too). I haven't done "real" use-cases tests, as I lack experience with TPM usage. Any help appreciated to test the TPM.
I build edk2 with:
$ build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -DMEM_VARSTORE_EMU_ENABLE=FALSE
I test with qemu & swtpm/libtpms (tpm2 branches, swtpm_setup.sh --tpm2 --tpm-state tpmstatedir)
$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock --tpm2 & $ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0
Thanks
Github tree:
https://github.com/elmarco/edk2/tree/tpm2 (tpm2-v2 tag)
Related bug:
https://bugzilla.tianocore.org/show_bug.cgi?id=594
v3: after Laszlo review
- many simplifications to "add customized Tcg2ConfigPei clone" patch
- various move of fdf/dsc sections
- modify Ia32 & Ia32x64 fdf/dsc too
- modify commit messages
- add r-b tags
v2:
- the series can now be applied to master directly, thanks to dropping PeiReadOnlyVariable requirement
- remove the HOB list workaround, the main fix is now upstream. Add a preliminary patch to complete it.
- removed traces of TPM1.2 support
- add own OvmfPkg Tcg2ConfigPei, which performs only TPM2 detection
- make PcdTpmInstanceGuid default all-bits-zero
- drop unneeded Pcd values
- explain why SHA1 is still nice to have (for 1.2 log format)
- drop Tcg2ConfigDxe
- more detailed commit messages, thanks to Laszlo explanations!
- rebased
TODO:
- modify Ia32 and Ia32X64 builds
Marc-André Lureau (7):
SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
OvmfPkg: simplify SecurityStubDxe.inf inclusion
OvmfPkg: add customized Tcg2ConfigPei clone
OvmfPkg: include Tcg2Pei module
OvmfPkg: include Tcg2Dxe module
OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 18 ++-- MdeModulePkg/Core/Pei/Image/Image.c | 4 +- MdeModulePkg/Core/Pei/PeiMain.h | 2 +- MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgIa32.fdf | 9 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgIa32X64.fdf | 9 ++ OvmfPkg/OvmfPkgX64.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgX64.fdf | 9 ++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 53 ++++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 84 +++++++++++++++++++ SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 13 files changed, 312 insertions(+), 26 deletions(-) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
Signature · 1 line
2.16.2.346.g9779355e34
PATCH v3 1/7 SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
From: Marc-André Lureau <[email protected]>
The module doesn't use read-only variable.
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
--- SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 1 file changed, 1 deletion(-)
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf +0 -1
@@ -91,7 +91,6 @@ [Pcd] [Depex] gEfiPeiMasterBootModePpiGuid AND - gEfiPeiReadOnlyVariable2PpiGuid AND gEfiTpmDeviceSelectedGuid [UserExtensions.TianoCore."ExtraFiles"]
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v3 1/7] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
Quoted 18 lines · On 03/09/18 14:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
The module doesn't use read-only variable.
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Laszlo Ersek <[email protected]>--- SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 1 file changed, 1 deletion(-)SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf +0
-0
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf [Pcd] · line 96
Quoted 7 lines
SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf +0
-1@@ -91,7 +91,6 @@ [Pcd] [Depex] gEfiPeiMasterBootModePpiGuid AND - gEfiPeiReadOnlyVariable2PpiGuid AND gEfiTpmDeviceSelectedGuid [UserExtensions.TianoCore."ExtraFiles"]
Any reason you didn't pick up the following R-b from v2?
http://mid.mail-archive.com/74D8A39837DF1E4DA445A8C0B3885C503AAE197C@shsmsx102.ccr.corp.intel.com
Anyway, this patch is identical, so I'll carry Jiewen's R-b forward. (That's important because this is a SecurityPkg patch, and I can only push it if we have an R-b from one of the SecurityPkg maintainers, Chao Zhang or Jiewen.)
Thanks
Laszlo
PATCH v3 2/7 MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
In reply to [email protected]From: Marc-André Lureau <[email protected]>
No functional changes.
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
--- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 18 +++++++++--------- MdeModulePkg/Core/Pei/Image/Image.c | 4 ++-- MdeModulePkg/Core/Pei/PeiMain.h | 2 +- MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +9 -9
@@ -970,7 +970,7 @@ PeiDispatcher (if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode !=BOOT_ON_S3_RESUME ||PcdGetBool (PcdShadowPeimOnS3Boot))) {// // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile -// update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE. +// update the modules' status from PEIM_STATE_REGISTER_FOR_SHADOW to PEIM_STATE_DONE. // SaveCurrentPeimCount = Private->CurrentPeimCount; SaveCurrentFvCount = Private->CurrentPeimFvCount;
@@ -978,7 +978,7 @@ PeiDispatcher (for (Index1 =0 ; Index1 <= SaveCurrentFvCount; Index1++) {for (Index2 =0 ; (Index2 <PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] !=NULL ); Index2++) { -if (Private->Fv[Index1].PeimState[Index2] ==PEIM_STATE_REGISITER_FOR_SHADOW ) { +if (Private->Fv[Index1].PeimState[Index2] ==PEIM_STATE_REGISTER_FOR_SHADOW ) { PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2]; Private->CurrentFileHandle = PeimFileHandle; Private->CurrentPeimFvCount = Index1;
@@ -986,13 +986,13 @@ PeiDispatcher ( Status =PeiLoadImage ( (CONST EFI_PEI_SERVICES **) &Private->Ps, PeimFileHandle, -PEIM_STATE_REGISITER_FOR_SHADOW , +PEIM_STATE_REGISTER_FOR_SHADOW , &EntryPoint, &AuthenticationState );if (Status ==EFI_SUCCESS ) {// -// PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE +// PEIM_STATE_REGISTER_FOR_SHADOW move to PEIM_STATE_DONE // Private->Fv[Index1].PeimState[Index2]++;//
@@ -1165,7 +1165,7 @@ PeiDispatcher (// PeiCheckAndSwitchStack (SecCoreData, Private); -if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] ==PEIM_STATE_REGISITER_FOR_SHADOW ) && \ +if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] ==PEIM_STATE_REGISTER_FOR_SHADOW ) && \ (Private->HobList.HandoffInformationTable->BootMode !=BOOT_ON_S3_RESUME ||PcdGetBool (PcdShadowPeimOnS3Boot))) {// // If memory is available we shadow images by default for performance reasons.
@@ -1179,7 +1179,7 @@ PeiDispatcher ( Status =PeiLoadImage ( PeiServices, PeimFileHandle, -PEIM_STATE_REGISITER_FOR_SHADOW , +PEIM_STATE_REGISTER_FOR_SHADOW , &EntryPoint, &AuthenticationState );
@@ -1192,7 +1192,7 @@ PeiDispatcher (//PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0); // -// PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE +// PEIM_STATE_REGISTER_FOR_SHADOW move to PEIM_STATE_DONE // Private->Fv[FvCount].PeimState[PeimCount]++;
@@ -1356,14 +1356,14 @@ PeiRegisterForShadow (return EFI_NOT_FOUND ; } -if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >=PEIM_STATE_REGISITER_FOR_SHADOW ) { +if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >=PEIM_STATE_REGISTER_FOR_SHADOW ) {// // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started // return EFI_ALREADY_STARTED ; } - Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] =PEIM_STATE_REGISITER_FOR_SHADOW ; + Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] =PEIM_STATE_REGISTER_FOR_SHADOW ;return EFI_SUCCESS ; }
MdeModulePkg/Core/Pei/Image/Image.c +2 -2
@@ -387,7 +387,7 @@ LoadAndRelocatePeCoffImage ( } IsRegisterForShadow = FALSE;if ((Private->CurrentFileHandle == FileHandle) - && (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] ==PEIM_STATE_REGISITER_FOR_SHADOW )) { + && (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] ==PEIM_STATE_REGISTER_FOR_SHADOW )) { IsRegisterForShadow = TRUE; }
@@ -876,7 +876,7 @@ PeiLoadImage (// // The shadowed PEIM must be relocatable. // -if (PeimState ==PEIM_STATE_REGISITER_FOR_SHADOW ) { +if (PeimState ==PEIM_STATE_REGISTER_FOR_SHADOW ) { IsStrip =RelocationIsStrip ((VOID *) (UINTN ) ImageAddress);ASSERT (!IsStrip);if (IsStrip) {
MdeModulePkg/Core/Pei/PeiMain.h +1 -1
@@ -104,7 +104,7 @@ typedef struct {// #define PEIM_STATE_NOT_DISPATCHED 0x00#define PEIM_STATE_DISPATCHED 0x01 -#define PEIM_STATE_REGISITER_FOR_SHADOW 0x02 +#define PEIM_STATE_REGISTER_FOR_SHADOW 0x02#define PEIM_STATE_DONE 0x03 typedef struct {
MdeModulePkg/Core/Pei/PeiMain/PeiMain.c +1 -1
@@ -104,7 +104,7 @@ ShadowPeiCore ( Status =PeiLoadImage (GetPeiServicesTablePointer (), *((EFI_PEI_FILE_HANDLE *)&PeiCoreFileHandle), -PEIM_STATE_REGISITER_FOR_SHADOW , +PEIM_STATE_REGISTER_FOR_SHADOW , &EntryPoint, &AuthenticationState );
Signature · 1 line
2.16.2.346.g9779355e34
PATCH v3 3/7 OvmfPkg: simplify SecurityStubDxe.inf inclusion
In reply to [email protected]From: Marc-André Lureau <[email protected]>
SecurityStubDxe.inf should be included unconditionally.
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
--- OvmfPkg/OvmfPkgIa32.dsc | 6 ++---- OvmfPkg/OvmfPkgIa32X64.dsc | 6 ++---- OvmfPkg/OvmfPkgX64.dsc | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-)
OvmfPkg/OvmfPkgIa32.dsc +2 -4
@@ -611,14 +611,12 @@ [Components] MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf -!if $(SECURE_BOOT_ENABLE) == TRUE MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { <LibraryClasses> +!if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf - } -!else - MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf !endif + } MdeModulePkg/Universal/EbcDxe/EbcDxe.inf PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
OvmfPkg/OvmfPkgIa32X64.dsc +2 -4
@@ -620,14 +620,12 @@ [Components.X64] MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf -!if $(SECURE_BOOT_ENABLE) == TRUE MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { <LibraryClasses> +!if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf - } -!else - MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf !endif + } MdeModulePkg/Universal/EbcDxe/EbcDxe.inf PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
OvmfPkg/OvmfPkgX64.dsc +2 -4
@@ -618,14 +618,12 @@ [Components] MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf -!if $(SECURE_BOOT_ENABLE) == TRUE MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { <LibraryClasses> +!if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf - } -!else - MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf !endif + } MdeModulePkg/Universal/EbcDxe/EbcDxe.inf PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
Signature · 1 line
2.16.2.346.g9779355e34
PATCH v3 4/7 OvmfPkg: add customized Tcg2ConfigPei clone
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The Tcg2ConfigPei module informs the firmware globally about the TPM device type, by setting the PcdTpmInstanceGuid PCD to the appropriate GUID value. The original module under SecurityPkg can perform device detection, or read a cached value from a non-volatile UEFI variable.
OvmfPkg's clone of the module only performs the TPM2 hardware detection.
This is what the module does:
- Check the QEMU hardware for TPM2 availability only
- If found, set the dynamic PCD "PcdTpmInstanceGuid" to &gEfiTpmDeviceInstanceTpm20DtpmGuid. This is what informs the rest of the firmware about the TPM type.
- Install the gEfiTpmDeviceSelectedGuid PPI. This action permits the PEI_CORE to dispatch the Tcg2Pei module, which consumes the above PCD. In effect, the gEfiTpmDeviceSelectedGuid PPI serializes the setting and the consumption of the "TPM type" PCD.
- If no TPM2 was found, install gPeiTpmInitializationDonePpiGuid. (Normally this is performed by Tcg2Pei, but Tcg2Pei doesn't do it if no TPM2 is available. So in that case our Tcg2ConfigPei must do it.)
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
--- OvmfPkg/OvmfPkgIa32.dsc | 17 +++++ OvmfPkg/OvmfPkgIa32.fdf | 4 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 17 +++++ OvmfPkg/OvmfPkgIa32X64.fdf | 4 ++ OvmfPkg/OvmfPkgX64.dsc | 17 +++++ OvmfPkg/OvmfPkgX64.fdf | 4 ++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 53 +++++++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 84 ++++++++++++++++++++++++ 8 files changed, 200 insertions(+) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
OvmfPkg/OvmfPkgIa32.dsc +17 -0
@@ -39,6 +39,7 @@ [Defines] DEFINE HTTP_BOOT_ENABLE = FALSE DEFINE SMM_REQUIRE = FALSE DEFINE TLS_ENABLE = FALSE + DEFINE TPM2_ENABLE = FALSE # # Flash size selection. Setting FD_SIZE_IN_KB on the command line directly to
@@ -203,6 +204,10 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf +!endif + [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -267,6 +272,10 @@ [LibraryClasses.common.PEIM] PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!endif + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
@@ -547,6 +556,10 @@ [PcdsDynamicDefault] gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x00 +!if $(TPM2_ENABLE) == TRUE + gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +!endif + ################################################################################ # # Components Section - list of all EDK II Modules needed by this Platform.
@@ -593,6 +606,10 @@ [Components] !endif UefiCpuPkg/CpuMpPei/CpuMpPei.inf +!if $(TPM2_ENABLE) == TRUE + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif + # # DXE Phase modules #
OvmfPkg/OvmfPkgIa32.fdf +4 -0
@@ -165,6 +165,10 @@ [FV.PEIFV] !endif INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf +!if $(TPM2_ENABLE) == TRUE +INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif + ################################################################################ [FV.DXEFV]
OvmfPkg/OvmfPkgIa32X64.dsc +17 -0
@@ -39,6 +39,7 @@ [Defines] DEFINE HTTP_BOOT_ENABLE = FALSE DEFINE SMM_REQUIRE = FALSE DEFINE TLS_ENABLE = FALSE + DEFINE TPM2_ENABLE = FALSE # # Flash size selection. Setting FD_SIZE_IN_KB on the command line directly to
@@ -208,6 +209,10 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf +!endif + [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -272,6 +277,10 @@ [LibraryClasses.common.PEIM] PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!endif + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
@@ -555,6 +564,10 @@ [PcdsDynamicDefault] gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x00 +!if $(TPM2_ENABLE) == TRUE + gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +!endif + ################################################################################ # # Components Section - list of all EDK II Modules needed by this Platform.
@@ -601,6 +614,10 @@ [Components.IA32] !endif UefiCpuPkg/CpuMpPei/CpuMpPei.inf +!if $(TPM2_ENABLE) == TRUE + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif + [Components.X64] # # DXE Phase modules
OvmfPkg/OvmfPkgIa32X64.fdf +4 -0
@@ -165,6 +165,10 @@ [FV.PEIFV] !endif INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf +!if $(TPM2_ENABLE) == TRUE +INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif + ################################################################################ [FV.DXEFV]
OvmfPkg/OvmfPkgX64.dsc +17 -0
@@ -39,6 +39,7 @@ [Defines] DEFINE HTTP_BOOT_ENABLE = FALSE DEFINE SMM_REQUIRE = FALSE DEFINE TLS_ENABLE = FALSE + DEFINE TPM2_ENABLE = FALSE # # Flash size selection. Setting FD_SIZE_IN_KB on the command line directly to
@@ -208,6 +209,10 @@ [LibraryClasses] OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf +!endif + [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -272,6 +277,10 @@ [LibraryClasses.common.PEIM] PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!endif + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
@@ -554,6 +563,10 @@ [PcdsDynamicDefault] gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x00 +!if $(TPM2_ENABLE) == TRUE + gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +!endif + ################################################################################ # # Components Section - list of all EDK II Modules needed by this Platform.
@@ -600,6 +613,10 @@ [Components] !endif UefiCpuPkg/CpuMpPei/CpuMpPei.inf +!if $(TPM2_ENABLE) == TRUE + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif + # # DXE Phase modules #
OvmfPkg/OvmfPkgX64.fdf +4 -0
@@ -165,6 +165,10 @@ [FV.PEIFV] !endif INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf +!if $(TPM2_ENABLE) == TRUE +INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +!endif + ################################################################################ [FV.DXEFV]
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +53 -0
53 lines not on this page · raw message
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v3 4/7] OvmfPkg: add customized Tcg2ConfigPei clone
Quoted 30 lines · On 03/09/18 14:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
The Tcg2ConfigPei module informs the firmware globally about the TPM device type, by setting the PcdTpmInstanceGuid PCD to the appropriate GUID value. The original module under SecurityPkg can perform device detection, or read a cached value from a non-volatile UEFI variable.
OvmfPkg's clone of the module only performs the TPM2 hardware detection.
This is what the module does:
- Check the QEMU hardware for TPM2 availability only
- If found, set the dynamic PCD "PcdTpmInstanceGuid" to &gEfiTpmDeviceInstanceTpm20DtpmGuid. This is what informs the rest of the firmware about the TPM type.
- Install the gEfiTpmDeviceSelectedGuid PPI. This action permits the
PEI_COREto dispatch the Tcg2Pei module, which consumes the above PCD. In effect, the gEfiTpmDeviceSelectedGuid PPI serializes the setting and the consumption of the "TPM type" PCD.- If no TPM2 was found, install gPeiTpmInitializationDonePpiGuid. (Normally this is performed by Tcg2Pei, but Tcg2Pei doesn't do it if no TPM2 is available. So in that case our Tcg2ConfigPei must do it.)
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>
Quoted 12 lines
--- OvmfPkg/OvmfPkgIa32.dsc | 17 +++++ OvmfPkg/OvmfPkgIa32.fdf | 4 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 17 +++++ OvmfPkg/OvmfPkgIa32X64.fdf | 4 ++ OvmfPkg/OvmfPkgX64.dsc | 17 +++++ OvmfPkg/OvmfPkgX64.fdf | 4 ++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 53 +++++++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 84 ++++++++++++++++++++++++ 8 files changed, 200 insertions(+) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
Nice!
PATCH v3 5/7 OvmfPkg: include Tcg2Pei module
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This module will initialize TPM device, measure reported FVs and BIOS version. We keep both SHA-1 and SHA-256 for the TCG 1.2 log format compatibility, but the SHA-256 measurements and TCG 2 log format are now recommended.
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
--- OvmfPkg/OvmfPkgIa32.dsc | 7 +++++++ OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 7 +++++++ OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 1 + 6 files changed, 24 insertions(+)
OvmfPkg/OvmfPkgIa32.dsc +7 -0
@@ -273,6 +273,7 @@ [LibraryClasses.common.PEIM] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf !if $(TPM2_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif
@@ -608,6 +609,12 @@ [Components] !if $(TPM2_ENABLE) == TRUE OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + <LibraryClasses> + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } !endif #
OvmfPkg/OvmfPkgIa32.fdf +1 -0
@@ -167,6 +167,7 @@ [FV.PEIFV] !if $(TPM2_ENABLE) == TRUE INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf !endif ################################################################################
OvmfPkg/OvmfPkgIa32X64.dsc +7 -0
@@ -278,6 +278,7 @@ [LibraryClasses.common.PEIM] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf !if $(TPM2_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif
@@ -616,6 +617,12 @@ [Components.IA32] !if $(TPM2_ENABLE) == TRUE OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + <LibraryClasses> + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } !endif [Components.X64]
OvmfPkg/OvmfPkgIa32X64.fdf +1 -0
@@ -167,6 +167,7 @@ [FV.PEIFV] !if $(TPM2_ENABLE) == TRUE INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf !endif ################################################################################
OvmfPkg/OvmfPkgX64.dsc +7 -0
@@ -278,6 +278,7 @@ [LibraryClasses.common.PEIM] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf !if $(TPM2_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif
@@ -615,6 +616,12 @@ [Components] !if $(TPM2_ENABLE) == TRUE OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + <LibraryClasses> + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } !endif #
OvmfPkg/OvmfPkgX64.fdf +1 -0
@@ -167,6 +167,7 @@ [FV.PEIFV] !if $(TPM2_ENABLE) == TRUE INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf !endif ################################################################################
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v3 5/7] OvmfPkg: include Tcg2Pei module
Quoted 11 lines · On 03/09/18 14:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
This module will initialize TPM device, measure reported FVs and BIOS version. We keep both SHA-1 and SHA-256 for the TCG 1.2 log format compatibility, but the SHA-256 measurements and TCG 2 log format are now recommended.
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>
Quoted 8 lines
--- OvmfPkg/OvmfPkgIa32.dsc | 7 +++++++ OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 7 +++++++ OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 1 + 6 files changed, 24 insertions(+)
PATCH v3 6/7 OvmfPkg: include Tcg2Dxe module
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This module measures and log the boot environment. It also produces the Tcg2 protocol, which allows for example to read the log from OS.
The linux kernel doesn't yet read the EFI_TCG2_EVENT_LOG_FORMAT_TCG_2, which is required for crypto-agile log. In fact, only upcoming 4.16 adds support EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:
[ 0.000000] efi: EFI v2.70 by EDK II [ 0.000000] efi: SMBIOS=0x3fa1f000 ACPI=0x3fbb6000 ACPI 2.0=0x3fbb6014 MEMATTR=0x3e7d4318 TPMEventLog=0x3db21018
$ python chipsec_util.py tpm parse_log binary_bios_measurements
[CHIPSEC] Version 1.3.5.dev2
[CHIPSEC] API mode: using OS native API (not using CHIPSEC kernel module) [CHIPSEC] Executing command 'tpm' with args ['parse_log', '/tmp/binary_bios_measurements']
PCR: 0 type: EV_S_CRTM_VERSION size: 0x2 digest: 1489f923c4dca729178b3e3233458550d8dddf29
+ version:
PCR: 0 type: EV_EFI_PLATFORM_FIRMWARE_BLOB size: 0x10 digest: fd39ced7c0d2a61f6830c78c7625f94826b05bcc
+ base: 0x820000 length: 0xe0000
PCR: 0 type: EV_EFI_PLATFORM_FIRMWARE_BLOB size: 0x10 digest: 39ebc6783b72bc1e73c7d5bcfeb5f54a3f105d4c
+ base: 0x900000 length: 0xa00000
PCR: 7 type: EV_EFI_VARIABLE_DRIVER_CONFIG size: 0x35 digest: 57cd4dc19442475aa82743484f3b1caa88e142b8
PCR: 7 type: EV_EFI_VARIABLE_DRIVER_CONFIG size: 0x24 digest: 9b1387306ebb7ff8e795e7be77563666bbf4516e
PCR: 7 type: EV_EFI_VARIABLE_DRIVER_CONFIG size: 0x26 digest: 9afa86c507419b8570c62167cb9486d9fc809758
PCR: 7 type: EV_EFI_VARIABLE_DRIVER_CONFIG size: 0x24 digest: 5bf8faa078d40ffbd03317c93398b01229a0e1e0
PCR: 7 type: EV_EFI_VARIABLE_DRIVER_CONFIG size: 0x26 digest: 734424c9fe8fc71716c42096f4b74c88733b175e
PCR: 7 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0x3e digest: 252f8ebb85340290b64f4b06a001742be8e5cab6
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0x6e digest: 22a4f6ee9af6dba01d3528deb64b74b582fc182b
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0x80 digest: b7811d5bf30a7efd4e385c6179fe10d9290bb9e8
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0x84 digest: 425e502c24fc924e231e0a62327b6b7d1f704573
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0x9a digest: 0b5d2c98ac5de6148a4a1490ff9d5df69039f04e
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0xbd digest: 20bd5f402271d57a88ea314fe35c1705956b1f74
PCR: 1 type: EV_EFI_VARIABLE_BOOT size: 0x88 digest: df5d6605cb8f4366d745a8464cfb26c1efdc305c
PCR: 4 type: EV_EFI_ACTION size: 0x28 digest: cd0fdb4531a6ec41be2753ba042637d6e5f7f256
PCR: 0 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
PCR: 1 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
PCR: 2 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
PCR: 3 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
PCR: 4 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
PCR: 5 type: EV_SEPARATOR size: 0x4 digest: 9069ca78e7450a285173431b3e52c5c25299e473
$ tpm2_pcrlist sha1 : 0 : 35bd1786b6909daad610d7598b1d620352d33b8a 1 : ec0511e860206e0af13c31da2f9e943fb6ca353d 2 : b2a83b0ebf2f8374299a5b2bdfc31ea955ad7236 3 : b2a83b0ebf2f8374299a5b2bdfc31ea955ad7236 4 : 45a323382bd933f08e7f0e256bc8249e4095b1ec 5 : d16d7e629fd8d08ca256f9ad3a3a1587c9e6cc1b 6 : b2a83b0ebf2f8374299a5b2bdfc31ea955ad7236 7 : 518bd167271fbb64589c61e43d8c0165861431d8 8 : 0000000000000000000000000000000000000000 9 : 0000000000000000000000000000000000000000 10 : 0000000000000000000000000000000000000000 11 : 0000000000000000000000000000000000000000 12 : 0000000000000000000000000000000000000000 13 : 0000000000000000000000000000000000000000 14 : 0000000000000000000000000000000000000000 15 : 0000000000000000000000000000000000000000 16 : 0000000000000000000000000000000000000000 17 : ffffffffffffffffffffffffffffffffffffffff 18 : ffffffffffffffffffffffffffffffffffffffff 19 : ffffffffffffffffffffffffffffffffffffffff 20 : ffffffffffffffffffffffffffffffffffffffff 21 : ffffffffffffffffffffffffffffffffffffffff 22 : ffffffffffffffffffffffffffffffffffffffff 23 : 0000000000000000000000000000000000000000 sha256 : 0 : 9ae903dbae3357ac00d223660bac19ea5c021499a56201104332ab966631ce2c 1 : acc611d90245cf04e77b0ca94901f90e7fa54770f0426f53c3049b532243d1b8 2 : 3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969 3 : 3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969 4 : 7a94ffe8a7729a566d3d3c577fcb4b6b1e671f31540375f80eae6382ab785e35 5 : a5ceb755d043f32431d63e39f5161464620a3437280494b5850dc1b47cc074e0 6 : 3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969 7 : 65caf8dd1e0ea7a6347b635d2b379c93b9a1351edc2afc3ecda700e534eb3068 8 : 0000000000000000000000000000000000000000000000000000000000000000 9 : 0000000000000000000000000000000000000000000000000000000000000000 10 : 0000000000000000000000000000000000000000000000000000000000000000 11 : 0000000000000000000000000000000000000000000000000000000000000000 12 : 0000000000000000000000000000000000000000000000000000000000000000 13 : 0000000000000000000000000000000000000000000000000000000000000000 14 : 0000000000000000000000000000000000000000000000000000000000000000 15 : 0000000000000000000000000000000000000000000000000000000000000000 16 : 0000000000000000000000000000000000000000000000000000000000000000 17 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 18 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 19 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 20 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 22 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 23 : 0000000000000000000000000000000000000000000000000000000000000000 sha384 :
The PhysicalPresenceLib is required, it sets some variables, but the firmware doesn't act on it yet.
Laszlo Ersek explained on the list why Tpm2DeviceLib has to be resolved differently for DXE_DRIVER modules in general and for "Tcg2Dxe.inf" specifically:
* We have a library class called Tpm2DeviceLib -- this is basically the set of APIs declared in "SecurityPkg/Include/Library/Tpm2DeviceLib.h". Its leading comment says "This library abstract how to access TPM2 hardware device".
There are two *sets* of APIs in "Tpm2DeviceLib.h":
(a) functions that deal with the TPM2 device:
- Tpm2RequestUseTpm(),
- Tpm2SubmitCommand()
This set of APIs is supposed to be used by clients that *consume* the TPM2 device abstraction.
(b) the function Tpm2RegisterTpm2DeviceLib(), which is supposed to be used by *providers* of various TPM2 device abstractions.
* Then, we have two implementations (instances) of the Tpm2DeviceLib class:
(1) SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
(2) SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf
(1) The first library instance ("Tpm2DeviceLibTcg2.inf") implements the APIs listed under (a), and it does not implement (b) -- see EFI_UNSUPPORTED. In other words, this lib instance is strictly meant for drivers that *consume* the TPM2 device abstraction. And, the (a) group of APIs is implemented by forwarding the requests to the TCG2 protocol.
The idea here is that all the drivers that consume the TPM2 abstraction do not have to be statically linked with a large TPM2 device library instance; instead they are only linked (statically) with this "thin" library instance, and all the actual work is delegated to whichever driver that provides the singleton TCG2 protocol.
(2) The second library instance ("Tpm2DeviceLibRouterDxe.inf") is meant for the driver that offers (produces) the TCG2 protocol. This lib instance implements both (a) and (b) API groups.
* Here's how things fit together:
(i) The "SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf" library instance (which has no lib class) is linked into "Tcg2Dxe.inf" via NULL class resolution. This simply means that before the "Tcg2Dxe.inf" entry point function is entered, the constructor function of "Tpm2InstanceLibDTpm.inf" will be called.
(ii) This Tpm2InstanceLibDTpmConstructor() function calls API (b), and registers its own actual TPM2 command implementation with the "Tpm2DeviceLibRouter" library instance (also linked into the Tcg2Dxe driver). This provides the back-end for the API set (a).
TCG2 protocol provider (Tcg2Dxe.inf driver) launches
|
v
NULL class: Tpm2InstanceLibDTpm instance construction
|
v
Tpm2DeviceLib class: Tpm2DeviceLibRouter instance
backend registration for API set (a)
(iii) The Tcg2Dxe driver exposes the TCG2 protocol.
(iv) A TPM2 consumer calls API set (a) via lib instance (1). Such calls land in Tcg2Dxe, via the protocol.
(v) Tcg2Dxe serves the protocol request by forwarding it to API set (a) from lib instance (2).
(vi) Those functions call the "backend" functions registered by Tpm2DeviceLibDTpm in step (ii).
TPM 2 consumer driver
|
v
Tpm2DeviceLib class: Tpm2DeviceLibTcg2 instance
|
v
TCG2 protocol interface
|
v
TCG2 protocol provider: Tcg2Dxe.inf driver
|
v Tpm2DeviceLib class: Tpm2DeviceLibRouter instance
|
v
NULL class: Tpm2InstanceLibDTpm instance
(via earlier registration)
|
v
TPM2 chip (actual hardware)
* So that is the "router" pattern in edk2. Namely,
- Consumers of an abstraction use a thin library instance.
- The thin library instance calls a firmware-global (singleton) service, i.e. a PPI (in the PEI phase) or protocol (in the DXE phase).
- The PEIM providing the PPI, or the DXE driver providing the protocol, don't themselves implement the actual service either. Instead they offer a "registration" service too, and they only connect the incoming "consumer" calls to the earlier registered back-end(s).
- The "registration service", for back-ends to use, may take various forms.
It can be exposed globally to the rest of the firmware, as another member function of the PPI / protocol structure. Then backends can be provided by separate PEIMs / DXE drivers.
Or else, the registration service can be exposed as just another library API. In this case, the backends are provided as NULL class library instances, and a platform DSC file links them into the PEIM / DXE driver via NULL class resolutions. The backend lib instances call the registration service in their own respective constructor functions.
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
--- OvmfPkg/OvmfPkgIa32.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgIa32.fdf | 4 ++++ OvmfPkg/OvmfPkgIa32X64.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgIa32X64.fdf | 4 ++++ OvmfPkg/OvmfPkgX64.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgX64.fdf | 4 ++++ 6 files changed, 60 insertions(+)
OvmfPkg/OvmfPkgIa32.dsc +16 -0
@@ -206,6 +206,8 @@ [LibraryClasses] !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf !endif [LibraryClasses.common]
@@ -356,6 +358,9 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -901,3 +906,14 @@ [Components] NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf } !endif + +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endif
OvmfPkg/OvmfPkgIa32.fdf +4 -0
@@ -385,6 +385,10 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !endif +!if $(TPM2_ENABLE) == TRUE +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!endif + ################################################################################ [FV.FVMAIN_COMPACT]
OvmfPkg/OvmfPkgIa32X64.dsc +16 -0
@@ -211,6 +211,8 @@ [LibraryClasses] !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf !endif [LibraryClasses.common]
@@ -361,6 +363,9 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -911,3 +916,14 @@ [Components.X64] NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf } !endif + +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endif
OvmfPkg/OvmfPkgIa32X64.fdf +4 -0
@@ -392,6 +392,10 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !endif +!if $(TPM2_ENABLE) == TRUE +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!endif + ################################################################################ [FV.FVMAIN_COMPACT]
OvmfPkg/OvmfPkgX64.dsc +16 -0
@@ -211,6 +211,8 @@ [LibraryClasses] !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf !endif [LibraryClasses.common]
@@ -361,6 +363,9 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -909,3 +914,14 @@ [Components] NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf } !endif + +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endif
OvmfPkg/OvmfPkgX64.fdf +4 -0
@@ -392,6 +392,10 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !endif +!if $(TPM2_ENABLE) == TRUE +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!endif + ################################################################################ [FV.FVMAIN_COMPACT]
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v3 6/7] OvmfPkg: include Tcg2Dxe module
Quoted 385 lines · On 03/09/18 14:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
This module measures and log the boot environment. It also produces the Tcg2 protocol, which allows for example to read the log from OS.
The linux kernel doesn't yet read the
EFI_TCG2_EVENT_LOG_FORMAT_TCG_2, which is required for crypto-agile log. In fact, only upcoming 4.16 adds supportEFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:[ 0.000000] efi: EFI v2.70 by EDK II [ 0.000000] efi: SMBIOS=0x3fa1f000 ACPI=0x3fbb6000 ACPI 2.0=0x3fbb6014 MEMATTR=0x3e7d4318 TPMEventLog=0x3db21018$ python chipsec_util.py tpm parse_log binary_bios_measurements[CHIPSEC] Version 1.3.5.dev2
[CHIPSEC] API mode: using OS native API (not using CHIPSEC kernel module) [CHIPSEC] Executing command 'tpm' with args ['parse_log', '/tmp/binary_bios_measurements']PCR: 0 type:
EV_S_CRTM_VERSIONsize:0x2digest:1489f923c4dca729178b3e3233458550d8dddf29
+ version:
PCR: 0 type:EV_EFI_PLATFORM_FIRMWARE_BLOBsize:0x10digest:fd39ced7c0d2a61f6830c78c7625f94826b05bcc
+ base:0x820000length:0xe0000
PCR: 0 type:EV_EFI_PLATFORM_FIRMWARE_BLOBsize:0x10digest:39ebc6783b72bc1e73c7d5bcfeb5f54a3f105d4c
+ base:0x900000length:0xa00000
PCR: 7 type:EV_EFI_VARIABLE_DRIVER_CONFIGsize:0x35digest:57cd4dc19442475aa82743484f3b1caa88e142b8
PCR: 7 type:EV_EFI_VARIABLE_DRIVER_CONFIGsize:0x24digest:9b1387306ebb7ff8e795e7be77563666bbf4516e
PCR: 7 type:EV_EFI_VARIABLE_DRIVER_CONFIGsize:0x26digest:9afa86c507419b8570c62167cb9486d9fc809758
PCR: 7 type:EV_EFI_VARIABLE_DRIVER_CONFIGsize:0x24digest:5bf8faa078d40ffbd03317c93398b01229a0e1e0
PCR: 7 type:EV_EFI_VARIABLE_DRIVER_CONFIGsize:0x26digest:734424c9fe8fc71716c42096f4b74c88733b175e
PCR: 7 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0x3edigest:252f8ebb85340290b64f4b06a001742be8e5cab6
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0x6edigest:22a4f6ee9af6dba01d3528deb64b74b582fc182b
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0x80digest:b7811d5bf30a7efd4e385c6179fe10d9290bb9e8
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0x84digest:425e502c24fc924e231e0a62327b6b7d1f704573
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0x9adigest:0b5d2c98ac5de6148a4a1490ff9d5df69039f04e
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0xbddigest:20bd5f402271d57a88ea314fe35c1705956b1f74
PCR: 1 type:EV_EFI_VARIABLE_BOOTsize:0x88digest:df5d6605cb8f4366d745a8464cfb26c1efdc305c
PCR: 4 type:EV_EFI_ACTIONsize:0x28digest:cd0fdb4531a6ec41be2753ba042637d6e5f7f256
PCR: 0 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473
PCR: 1 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473
PCR: 2 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473
PCR: 3 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473
PCR: 4 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473
PCR: 5 type:EV_SEPARATORsize:0x4digest:9069ca78e7450a285173431b3e52c5c25299e473$ tpm2_pcrlist sha1 : 0 : 35bd1786b6909daad610d7598b1d620352d33b8a 1 : ec0511e860206e0af13c31da2f9e943fb6ca353d 2 : b2a83b0ebf2f8374299a5b2bdfc31ea955ad7236 3 : b2a83b0ebf2f8374299a5b2bdfc31ea955ad7236 4 : 45a323382bd933f08e7f0e256bc8249e4095b1ec 5 : d16d7e629fd8d08ca256f9ad3a3a1587c9e6cc1b 6 : b2a83b0ebf2f8374299a5b2bdfc31ea955ad7236 7 : 518bd167271fbb64589c61e43d8c0165861431d8 8 : 0000000000000000000000000000000000000000 9 : 0000000000000000000000000000000000000000 10 : 0000000000000000000000000000000000000000 11 : 0000000000000000000000000000000000000000 12 : 0000000000000000000000000000000000000000 13 : 0000000000000000000000000000000000000000 14 : 0000000000000000000000000000000000000000 15 : 0000000000000000000000000000000000000000 16 : 0000000000000000000000000000000000000000 17 : ffffffffffffffffffffffffffffffffffffffff 18 : ffffffffffffffffffffffffffffffffffffffff 19 : ffffffffffffffffffffffffffffffffffffffff 20 : ffffffffffffffffffffffffffffffffffffffff 21 : ffffffffffffffffffffffffffffffffffffffff 22 : ffffffffffffffffffffffffffffffffffffffff 23 : 0000000000000000000000000000000000000000 sha256 : 0 : 9ae903dbae3357ac00d223660bac19ea5c021499a56201104332ab966631ce2c 1 : acc611d90245cf04e77b0ca94901f90e7fa54770f0426f53c3049b532243d1b8 2 : 3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969 3 : 3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969 4 : 7a94ffe8a7729a566d3d3c577fcb4b6b1e671f31540375f80eae6382ab785e35 5 : a5ceb755d043f32431d63e39f5161464620a3437280494b5850dc1b47cc074e0 6 : 3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969 7 : 65caf8dd1e0ea7a6347b635d2b379c93b9a1351edc2afc3ecda700e534eb3068 8 : 0000000000000000000000000000000000000000000000000000000000000000 9 : 0000000000000000000000000000000000000000000000000000000000000000 10 : 0000000000000000000000000000000000000000000000000000000000000000 11 : 0000000000000000000000000000000000000000000000000000000000000000 12 : 0000000000000000000000000000000000000000000000000000000000000000 13 : 0000000000000000000000000000000000000000000000000000000000000000 14 : 0000000000000000000000000000000000000000000000000000000000000000 15 : 0000000000000000000000000000000000000000000000000000000000000000 16 : 0000000000000000000000000000000000000000000000000000000000000000 17 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 18 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 19 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 20 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 22 : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 23 : 0000000000000000000000000000000000000000000000000000000000000000 sha384 :The PhysicalPresenceLib is required, it sets some variables, but the firmware doesn't act on it yet.
Laszlo Ersek explained on the list why Tpm2DeviceLib has to be resolved differently for
DXE_DRIVERmodules in general and for "Tcg2Dxe.inf" specifically:* We have a library class called Tpm2DeviceLib -- this is basically the set of APIs declared in "
SecurityPkg/Include/Library/Tpm2DeviceLib.h". Its leading comment says "This library abstract how to access TPM2 hardware device".There are two *sets* of APIs in "
Tpm2DeviceLib.h":(a) functions that deal with the TPM2 device:
-Tpm2RequestUseTpm(),
-Tpm2SubmitCommand()This set of APIs is supposed to be used by clients that *consume* the TPM2 device abstraction.
(b) the function
Tpm2RegisterTpm2DeviceLib(), which is supposed to be used by *providers* of various TPM2 device abstractions.* Then, we have two implementations (instances) of the Tpm2DeviceLib class:
(1) SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
(2) SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf(1) The first library instance ("Tpm2DeviceLibTcg2.inf") implements the APIs listed under (a), and it does not implement (b) -- see
EFI_UNSUPPORTED. In other words, this lib instance is strictly meant for drivers that *consume* the TPM2 device abstraction. And, the (a) group of APIs is implemented by forwarding the requests to the TCG2 protocol.The idea here is that all the drivers that consume the TPM2 abstraction do not have to be statically linked with a large TPM2 device library instance; instead they are only linked (statically) with this "thin" library instance, and all the actual work is delegated to whichever driver that provides the singleton TCG2 protocol.
(2) The second library instance ("Tpm2DeviceLibRouterDxe.inf") is meant for the driver that offers (produces) the TCG2 protocol. This lib instance implements both (a) and (b) API groups.
* Here's how things fit together:
(i) The "SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf" library instance (which has no lib class) is linked into "Tcg2Dxe.inf" via NULL class resolution. This simply means that before the "Tcg2Dxe.inf" entry point function is entered, the constructor function of "Tpm2InstanceLibDTpm.inf" will be called.
(ii) This
Tpm2InstanceLibDTpmConstructor()function calls API (b), and registers its own actual TPM2 command implementation with the "Tpm2DeviceLibRouter" library instance (also linked into the Tcg2Dxe driver). This provides the back-end for the API set (a).TCG2 protocol provider (Tcg2Dxe.inf driver) launches
|
v
NULL class: Tpm2InstanceLibDTpm instance construction
|
v
Tpm2DeviceLib class: Tpm2DeviceLibRouter instance
backend registration for API set (a)(iii) The Tcg2Dxe driver exposes the TCG2 protocol.
(iv) A TPM2 consumer calls API set (a) via lib instance (1). Such calls land in Tcg2Dxe, via the protocol.
(v) Tcg2Dxe serves the protocol request by forwarding it to API set (a) from lib instance (2).
(vi) Those functions call the "backend" functions registered by Tpm2DeviceLibDTpm in step (ii).
TPM 2 consumer driver
|
v
Tpm2DeviceLib class: Tpm2DeviceLibTcg2 instance| v TCG2 protocol interface | v TCG2 protocol provider: Tcg2Dxe.inf driver | vTpm2DeviceLib class: Tpm2DeviceLibRouter instance
|
v
NULL class: Tpm2InstanceLibDTpm instance
(via earlier registration)
|
v
TPM2 chip (actual hardware)* So that is the "router" pattern in edk2. Namely,
- Consumers of an abstraction use a thin library instance.
- The thin library instance calls a firmware-global (singleton) service, i.e. a PPI (in the PEI phase) or protocol (in the DXE phase).
- The PEIM providing the PPI, or the DXE driver providing the protocol, don't themselves implement the actual service either. Instead they offer a "registration" service too, and they only connect the incoming "consumer" calls to the earlier registered back-end(s).
- The "registration service", for back-ends to use, may take various forms.
It can be exposed globally to the rest of the firmware, as another member function of the PPI / protocol structure. Then backends can be provided by separate PEIMs / DXE drivers.
Or else, the registration service can be exposed as just another library API. In this case, the backends are provided as NULL class library instances, and a platform DSC file links them into the PEIM / DXE driver via NULL class resolutions. The backend lib instances call the registration service in their own respective constructor functions.
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>--- OvmfPkg/OvmfPkgIa32.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgIa32.fdf | 4 ++++ OvmfPkg/OvmfPkgIa32X64.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgIa32X64.fdf | 4 ++++ OvmfPkg/OvmfPkgX64.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgX64.fdf | 4 ++++ 6 files changed, 60 insertions(+)OvmfPkg/OvmfPkgIa32.dsc +16
-0@@ -206,6 +206,8 @@ [LibraryClasses] !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf !endif [LibraryClasses.common]@@ -356,6 +358,9 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf@@ -901,3 +906,14 @@ [Components] NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf } !endif + +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endifOvmfPkg/OvmfPkgIa32.fdf +4
-0@@ -385,6 +385,10 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !endif +!if $(TPM2_ENABLE) == TRUE +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!endif + ################################################################################ [FV.FVMAIN_COMPACT]OvmfPkg/OvmfPkgIa32X64.dsc +16
-0@@ -211,6 +211,8 @@ [LibraryClasses] !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf !endif [LibraryClasses.common]@@ -361,6 +363,9 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf@@ -911,3 +916,14 @@ [Components.X64] NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf } !endif + +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endifOvmfPkg/OvmfPkgIa32X64.fdf +4
-0@@ -392,6 +392,10 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !endif +!if $(TPM2_ENABLE) == TRUE +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!endif + ################################################################################ [FV.FVMAIN_COMPACT]OvmfPkg/OvmfPkgX64.dsc +16
-0@@ -211,6 +211,8 @@ [LibraryClasses] !if $(TPM2_ENABLE) == TRUE Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf !endif [LibraryClasses.common]@@ -361,6 +363,9 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(TPM2_ENABLE) == TRUE + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf@@ -909,3 +914,14 @@ [Components] NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf } !endif + +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endifOvmfPkg/OvmfPkgX64.fdf +0
-0
OvmfPkg/OvmfPkgX64.fdf [FV.DXEFV] · line 401
Quoted 10 lines
OvmfPkg/OvmfPkgX64.fdf +4
-0@@ -392,6 +392,10 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !endif +!if $(TPM2_ENABLE) == TRUE +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +!endif + ################################################################################ [FV.FVMAIN_COMPACT]
PATCH v3 7/7 OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The library registers a security management handler, to measure images that are not measure in PEI phase. For example with the qemu PXE rom:
Loading driver at 0x0003E6C2000 EntryPoint=0x0003E6C9076 8086100e.efi
And the following binary_bios_measurements log entry seems to be added:
PCR: 2 type: EV_EFI_BOOT_SERVICES_DRIVER size: 0x4e digest: 70a22475e9f18806d2ed9193b48d80d26779d9a4
The following order of operations ensures that 3rd party UEFI modules, such as PCI option ROMs and other modules possibly loaded from outside of firmware volumes, are measured into the TPM:
(1) Tcg2Dxe is included in DXEFV, therefore it produces the TCG2 protocol sometime in the DXE phase (assuming a TPM2 chip is present, reported via PcdTpmInstanceGuid).
(2) The DXE core finds that no more drivers are left to dispatch from DXEFV, and we enter the BDS phase.
(3) OVMF's PlatformBootManagerLib connects all PCI root bridges non-recursively, producing PciIo instances and discovering PCI oproms.
(4) The dispatching of images that don't originate from FVs is deferred at this point, by "MdeModulePkg/Universal/SecurityStubDxe/Defer3rdPartyImageLoad.c".
(5) OVMF's PlatformBootManagerLib signals EndOfDxe.
(6) OVMF's PlatformBootManagerLib calls EfiBootManagerDispatchDeferredImages() -- the images deferred in step (4) are now dispatched.
(7) Image dispatch invokes the Security / Security2 Arch protocols (produced by SecurityStubDxe). In this patch, we hook DxeTpm2MeasureBootLib into SecurityStubDxe, therefore image dispatch will try to locate the TCG2 protocol, and measure the image into the TPM2 chip with the protocol. Because of step (1), the TCG2 protocol will always be found and used (assuming a TPM2 chip is present).
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
--- OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ 3 files changed, 9 insertions(+)
OvmfPkg/OvmfPkgIa32.dsc +3 -0
@@ -644,6 +644,9 @@ [Components] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM2_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf !endif }
OvmfPkg/OvmfPkgIa32X64.dsc +3 -0
@@ -653,6 +653,9 @@ [Components.X64] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM2_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf !endif }
OvmfPkg/OvmfPkgX64.dsc +3 -0
@@ -651,6 +651,9 @@ [Components] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM2_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf !endif }
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v3 7/7] OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
Quoted 88 lines · On 03/09/18 14:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
The library registers a security management handler, to measure images that are not measure in PEI phase. For example with the qemu PXE rom:
Loading driver at
0x0003E6C2000EntryPoint=0x0003E6C9076 8086100e.efiAnd the following
binary_bios_measurementslog entry seems to be added:PCR: 2 type:
EV_EFI_BOOT_SERVICES_DRIVERsize:0x4edigest:70a22475e9f18806d2ed9193b48d80d26779d9a4The following order of operations ensures that 3rd party UEFI modules, such as PCI option ROMs and other modules possibly loaded from outside of firmware volumes, are measured into the TPM:
(1) Tcg2Dxe is included in DXEFV, therefore it produces the TCG2 protocol sometime in the DXE phase (assuming a TPM2 chip is present, reported via PcdTpmInstanceGuid).
(2) The DXE core finds that no more drivers are left to dispatch from DXEFV, and we enter the BDS phase.
(3) OVMF's PlatformBootManagerLib connects all PCI root bridges non-recursively, producing PciIo instances and discovering PCI oproms.
(4) The dispatching of images that don't originate from FVs is deferred at this point, by "
MdeModulePkg/Universal/SecurityStubDxe/Defer3rdPartyImageLoad.c".(5) OVMF's PlatformBootManagerLib signals EndOfDxe.
(6) OVMF's PlatformBootManagerLib calls
EfiBootManagerDispatchDeferredImages()-- the images deferred in step (4) are now dispatched.(7) Image dispatch invokes the Security / Security2 Arch protocols (produced by SecurityStubDxe). In this patch, we hook DxeTpm2MeasureBootLib into SecurityStubDxe, therefore image dispatch will try to locate the TCG2 protocol, and measure the image into the TPM2 chip with the protocol. Because of step (1), the TCG2 protocol will always be found and used (assuming a TPM2 chip is present).
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>--- OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ 3 files changed, 9 insertions(+)OvmfPkg/OvmfPkgIa32.dsc +3
-0@@ -644,6 +644,9 @@ [Components] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM2_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf !endif }OvmfPkg/OvmfPkgIa32X64.dsc +3
-0@@ -653,6 +653,9 @@ [Components.X64] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM2_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf !endif }OvmfPkg/OvmfPkgX64.dsc +0
-0
OvmfPkg/OvmfPkgX64.dsc [Components] · line 659
Quoted 9 lines
OvmfPkg/OvmfPkgX64.dsc +3
-0@@ -651,6 +651,9 @@ [Components] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM2_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf !endif }
Hi
Quoted 28 lines · On Fri, Mar 9, 2018 at 2:09 PM, <[email protected]> wrote:
From: Marc-André Lureau <[email protected]>
Hi,
The following series adds basic TPM2 support for OVMF-on-QEMU (I haven't tested TPM1, for lack of interest). It links with the modules to initializes the device in PEI phase, and do measurements (both PEI and DXE). The Tcg2Dxe module provides the Tcg2 protocol which allows the guest to access the measurement log and other facilities.
DxeTpm2MeasureBootLib seems to do its job at measuring images that are not measured in PEI phase (such as PCI PXE rom)
Tcg2ConfigDxe is not included due to its integration with edk2 own PPI implementation which conflicts with qemu design. PPI design is still being discussed & experimented at this point.
Linux guests seem to work fine. But windows guest generally complains about the lack of PPI interface (most HLK tests require it, tpm.msc admin interactions too). I haven't done "real" use-cases tests, as I lack experience with TPM usage. Any help appreciated to test the TPM.
I build edk2 with:
$ build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -DMEM_VARSTORE_EMU_ENABLE=FALSEI test with qemu & swtpm/libtpms (tpm2 branches,
swtpm_setup.sh--tpm2 --tpm-state tpmstatedir)
Quoted 7 lines
$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock --tpm2 & $ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0Thanks
Github tree:
https://github.com/elmarco/edk2/tree/tpm2 (tpm2-v2 tag)
I updated the github tree:
https://github.com/elmarco/edk2/tree/tpm2 (tpm2-v3 tag)
Quoted 25 lines
Related bug:
https://bugzilla.tianocore.org/show_bug.cgi?id=594v3: after Laszlo review
- many simplifications to "add customized Tcg2ConfigPei clone" patch
- various move of fdf/dsc sections
- modify Ia32 & Ia32x64 fdf/dsc too
- modify commit messages
- add r-b tagsv2:
- the series can now be applied to master directly, thanks to dropping PeiReadOnlyVariable requirement
- remove the HOB list workaround, the main fix is now upstream. Add a preliminary patch to complete it.
- removed traces of TPM1.2 support
- add own OvmfPkg Tcg2ConfigPei, which performs only TPM2 detection
- make PcdTpmInstanceGuid default all-bits-zero
- drop unneeded Pcd values
- explain why SHA1 is still nice to have (for 1.2 log format)
- drop Tcg2ConfigDxe
- more detailed commit messages, thanks to Laszlo explanations!
- rebased
Quoted 2 lines
TODO:
- modify Ia32 and Ia32X64 builds
This is now done.
thanks
Quoted 34 lines
Marc-André Lureau (7):
SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
OvmfPkg: simplify SecurityStubDxe.inf inclusion
OvmfPkg: add customized Tcg2ConfigPei clone
OvmfPkg: include Tcg2Pei module
OvmfPkg: include Tcg2Dxe module
OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxeMdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 18 ++-- MdeModulePkg/Core/Pei/Image/Image.c | 4 +- MdeModulePkg/Core/Pei/PeiMain.h | 2 +- MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgIa32.fdf | 9 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgIa32X64.fdf | 9 ++ OvmfPkg/OvmfPkgX64.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgX64.fdf | 9 ++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 53 ++++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 84 +++++++++++++++++++ SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 13 files changed, 312 insertions(+), 26 deletions(-) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c--
2.16.2.346.g9779355e34_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel
Signature · 1 line
Marc-André Lureau
Hi Marc-André,
Quoted 72 lines · On 03/09/18 14:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Hi,
The following series adds basic TPM2 support for OVMF-on-QEMU (I haven't tested TPM1, for lack of interest). It links with the modules to initializes the device in PEI phase, and do measurements (both PEI and DXE). The Tcg2Dxe module provides the Tcg2 protocol which allows the guest to access the measurement log and other facilities.
DxeTpm2MeasureBootLib seems to do its job at measuring images that are not measured in PEI phase (such as PCI PXE rom)
Tcg2ConfigDxe is not included due to its integration with edk2 own PPI implementation which conflicts with qemu design. PPI design is still being discussed & experimented at this point.
Linux guests seem to work fine. But windows guest generally complains about the lack of PPI interface (most HLK tests require it, tpm.msc admin interactions too). I haven't done "real" use-cases tests, as I lack experience with TPM usage. Any help appreciated to test the TPM.
I build edk2 with:
$ build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -DMEM_VARSTORE_EMU_ENABLE=FALSEI test with qemu & swtpm/libtpms (tpm2 branches,
swtpm_setup.sh--tpm2 --tpm-state tpmstatedir)$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock --tpm2 & $ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0Thanks
Github tree:
https://github.com/elmarco/edk2/tree/tpm2 (tpm2-v2 tag)Related bug:
https://bugzilla.tianocore.org/show_bug.cgi?id=594v3: after Laszlo review
- many simplifications to "add customized Tcg2ConfigPei clone" patch
- various move of fdf/dsc sections
- modify Ia32 & Ia32x64 fdf/dsc too
- modify commit messages
- add r-b tagsv2:
- the series can now be applied to master directly, thanks to dropping PeiReadOnlyVariable requirement
- remove the HOB list workaround, the main fix is now upstream. Add a preliminary patch to complete it.
- removed traces of TPM1.2 support
- add own OvmfPkg Tcg2ConfigPei, which performs only TPM2 detection
- make PcdTpmInstanceGuid default all-bits-zero
- drop unneeded Pcd values
- explain why SHA1 is still nice to have (for 1.2 log format)
- drop Tcg2ConfigDxe
- more detailed commit messages, thanks to Laszlo explanations!
- rebasedTODO:
- modify Ia32 and Ia32X64 buildsMarc-André Lureau (7):
SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
OvmfPkg: simplify SecurityStubDxe.inf inclusion
OvmfPkg: add customized Tcg2ConfigPei clone
OvmfPkg: include Tcg2Pei module
OvmfPkg: include Tcg2Dxe module
OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
Quoted 17 lines
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 18 ++-- MdeModulePkg/Core/Pei/Image/Image.c | 4 +- MdeModulePkg/Core/Pei/PeiMain.h | 2 +- MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgIa32.fdf | 9 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgIa32X64.fdf | 9 ++ OvmfPkg/OvmfPkgX64.dsc | 49 ++++++++++- OvmfPkg/OvmfPkgX64.fdf | 9 ++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 53 ++++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 84 +++++++++++++++++++ SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 13 files changed, 312 insertions(+), 26 deletions(-) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
huge kudos for this work. I've pushed it now: commit range 7878f706e7eb..d5a002aba0aa.
* For future work, please update your git setting so that you include, in your commit message:
Contributed-under: TianoCore Contribution Agreement 1.1
^^^
The patches in this series vary between 1.0 and 1.1. For now, 1.0 is acceptable as well (see
<https://bugzilla.tianocore.org/show_bug.cgi?id=628> and commit f2d1b866dfd9, "BaseTools/PatchCheck: Support Contribution Agreement 1.1", 2017-08-03).
The difference between 1.0 and 1.1 is basically "docs files" -- please see commit b6538c118ae8 ("edk2: Update to TianoCore Contribution Agreement 1.1", 2017-08-03). You don't touch documentation in this series, just source code, so 1.0 is fine (wherever you used that); in the future 1.1 should be used consistently.
* I did some regression testing too, with this set applied, for both TRUE and FALSE values of TPM2_ENABLE. (Note that I didn't actually set up swtpm, so my regression-testing for TRUE exercised the "detection failed" branch.) Normal boot and S3 suspend/resume continues to work under all the usual circumstances (with or without SMM etc).
* One scenario that I didn't test (and I expect it *not* to work) is TPM2 detection in a SEV guest (CC'ing Brijesh for this, just as a heads-up). In a SEV guest, we currently mark MMIO ranges as decrypted / plaintext in the DXE phase first. This means that Tcg2ConfigPei (which detects the TPM2 chip) and Tcg2Pei (which measures the firmware volumes into TPM2) wouldn't be able to access the TPM2 chip. We might attempt to massage the PTE C-bit in the PEI phase specifically on the TPM2 MMIO range, however that's architecturally impossible in the IA32 and IA32X64 builds (where the PEI phase is 32-bit). And, if we use the X64 build, then the SMM+S3 combination doesn't work (because S3Resume2Pei doesn't support that scenario).
All in all, with all of these seemingly orthogonal features, we unavoidably run into obscure combinations that don't, or even can't, work. This is a hard problem; we should figure it out later. (One dirty hack could be to add an IO-port mapped register block to the TPM2 chip in QEMU, and create adapted variants of the necessary edk2 libs -- IO access is entirely unaffected by SEV.) For now, TPM2_ENABLE defaults to FALSE (a good choice), so no issue for SEV guests. And, Peter and Javier on the RH Bootloader Team can rebuild OVMF with TPM2_ENABLE, for testing their TCG2 protocol client code -- that use case doesn't involve SEV. So I think this is an acceptable state to push to the master branch, for the time being.
Thanks!
Laszlo