RFC: ovmf: preliminary TPM2 support
v2 cover RFC: 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
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 (8):
SecurityPkg: also clear HashInterfaceHob.SupportedHashMask SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
MdeModulePkg: fix REGISITER -> REGISTER
ovmf: simplify SecurityStubDxe.inf inclusion
ovmf: add OvmfPkg Tcg2ConfigPei module
ovmf: link with Tcg2Pei module
ovmf: link with Tcg2Dxe module
ovmf: add DxeTpm2MeasureBootLib
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 | 6 +- OvmfPkg/OvmfPkgIa32X64.dsc | 6 +- OvmfPkg/OvmfPkgX64.dsc | 49 ++++++- OvmfPkg/OvmfPkgX64.fdf | 9 ++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 57 ++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 124 ++++++++++++++++++ OvmfPkg/Tcg/Tcg2Config/TpmDetection.c | 46 +++++++ .../HashLibBaseCryptoRouterPei.c | 1 + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 13 files changed, 299 insertions(+), 26 deletions(-) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c create mode 100644 OvmfPkg/Tcg/Tcg2Config/TpmDetection.c
Signature · 1 line
2.16.2.346.g9779355e34
PATCH v2 1/8 SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
From: Marc-André Lureau <[email protected]>
Commit 4cc2b63bd829426b05bad0d8952f1855a10d6ed7 fixed an out of bounds ZeroMem() call. However, as Laszlo Ersek pointed out, the intent was to clear all but the Identifier (to revert the effect of RegisterHashInterfaceLib()). For that, it should clear the SupportedHashMask too.
Cc: Jiewen Yao <[email protected]>
Cc: Chao Zhang <[email protected]>
Cc: Star Zeng <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
--- .../Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c | 1 + 1 file changed, 1 insertion(+)
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +1 -0
@@ -426,6 +426,7 @@ HashLibBaseCryptoRouterPeiConstructor (// ZeroMem (&HashInterfaceHob->HashInterface,sizeof (HashInterfaceHob->HashInterface)); HashInterfaceHob->HashInterfaceCount =0 ; + HashInterfaceHob->SupportedHashMask =0 ; }//
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v2 1/8] SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, March 7, 2018 11:58 PM
To: [email protected]
Cc: [email protected]; Yao, Jiewen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Marc-André Lureau <[email protected]>; Zhang, Chao B <[email protected]>; Zeng, Star <[email protected]>
Subject: [PATCH v2 1/8] SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
From: Marc-André Lureau <[email protected]>
Commit 4cc2b63bd829426b05bad0d8952f1855a10d6ed7 fixed an out of boundsZeroMem() call. However, as Laszlo Ersek pointed out, the intent was to clear all but the Identifier (to revert the effect of RegisterHashInterfaceLib()). For that, it should clear the SupportedHashMask too.
Cc: Jiewen Yao <[email protected]>
Cc: Chao Zhang <[email protected]>
Cc: Star Zeng <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
--- .../Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c | 1 + 1 file changed, 1 insertion(+)
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRoute renamed from SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +0 -0
+++ rPei.c
@@ -426,6 +426,7 @@ HashLibBaseCryptoRouterPeiConstructor (
//
ZeroMem (&HashInterfaceHob->HashInterface, sizeof (HashInterfaceHob->HashInterface));
HashInterfaceHob->HashInterfaceCount = 0;+ HashInterfaceHob->SupportedHashMask = 0;
}
//
--
2.16.2.346.g9779355e34
Re: [Qemu-devel] [PATCH v2 1/8] SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
Thanks,
Star
-----Original Message-----
From: Zhang, Chao B
Sent: Thursday, March 8, 2018 8:35 AM
To: [email protected]; [email protected]
Cc: [email protected]; Yao, Jiewen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Zeng, Star <[email protected]>
Subject: RE: [PATCH v2 1/8] SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, March 7, 2018 11:58 PM
To: [email protected]
Cc: [email protected]; Yao, Jiewen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Marc-André Lureau <[email protected]>; Zhang, Chao B <[email protected]>; Zeng, Star <[email protected]>
Subject: [PATCH v2 1/8] SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
From: Marc-André Lureau <[email protected]>
Commit 4cc2b63bd829426b05bad0d8952f1855a10d6ed7 fixed an out of boundsZeroMem() call. However, as Laszlo Ersek pointed out, the intent was to clear all but the Identifier (to revert the effect of RegisterHashInterfaceLib()). For that, it should clear the SupportedHashMask too.
Cc: Jiewen Yao <[email protected]>
Cc: Chao Zhang <[email protected]>
Cc: Star Zeng <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
--- .../Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c | 1 + 1 file changed, 1 insertion(+)
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRoute renamed from SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +0 -0
+++ rPei.c
@@ -426,6 +426,7 @@ HashLibBaseCryptoRouterPeiConstructor (
//
ZeroMem (&HashInterfaceHob->HashInterface, sizeof (HashInterfaceHob->HashInterface));
HashInterfaceHob->HashInterfaceCount = 0;+ HashInterfaceHob->SupportedHashMask = 0;
}
//
--
2.16.2.346.g9779355e34
Re: [Qemu-devel] [edk2] [PATCH v2 1/8] SecurityPkg: also clear HashInterfaceHob.SupportedHashMask
In reply to [email protected]Quoted 24 lines · On 03/07/18 16:57, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Commit
4cc2b63bd829426b05bad0d8952f1855a10d6ed7fixed an out of boundsZeroMem()call. However, as Laszlo Ersek pointed out, the intent was to clear all but the Identifier (to revert the effect ofRegisterHashInterfaceLib()). For that, it should clear the SupportedHashMask too.Cc: Jiewen Yao <[email protected]>
Cc: Chao Zhang <[email protected]>
Cc: Star Zeng <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1Signed-off-by Marc-André Lureau <[email protected]>--- .../Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c | 1 + 1 file changed, 1 insertion(+)SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +0
-0
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c HashLibBaseCryptoRouterPeiConstructor ( · line 432
Quoted 7 lines
SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +1
-0@@ -426,6 +426,7 @@ HashLibBaseCryptoRouterPeiConstructor (// ZeroMem (&HashInterfaceHob->HashInterface,sizeof (HashInterfaceHob->HashInterface)); HashInterfaceHob->HashInterfaceCount =0 ; + HashInterfaceHob->SupportedHashMask =0 ; }//
Thanks,
Laszlo
PATCH v2 2/8 SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
In reply to [email protected]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 v2 2/8] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
Quoted 36 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, March 7, 2018 11:58 PM
To: [email protected]
Cc: [email protected]; Yao, Jiewen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Marc-André Lureau <[email protected]>
Subject: [PATCH v2 2/8] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from DepexFrom: 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]>--- SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf | 1 - 1 file changed, 1 deletion(-)SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf +0
-2@@ -91,7 +91,6 @@ [Pcd] [Depex] gEfiPeiMasterBootModePpiGuid AND - gEfiPeiReadOnlyVariable2PpiGuid AND gEfiTpmDeviceSelectedGuid [UserExtensions.TianoCore."ExtraFiles"] --2.16.2.346.g9779355e34
Re: [Qemu-devel] [edk2] [PATCH v2 2/8] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
In reply to [email protected]Hi Lureau:
I think we can remove same dependency in TcgPei.
-----Original Message-----
From: edk2-devel [mailto:[email protected]] On Behalf Of [email protected]
Sent: Wednesday, March 7, 2018 11:58 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yao, Jiewen <[email protected]>; [email protected]
Subject: [edk2] [PATCH v2 2/8] 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 · 6 lines
2.16.2.346.g9779355e34 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel
Re: [Qemu-devel] [edk2] [PATCH v2 2/8] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
Hi
Quoted 3 lines · Chao B
Hi Lureau:
I think we can remove same dependency in TcgPei.
Thanks, feel free to explore that as a separate patch. This is out of scope to me.
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [edk2] [PATCH v2 2/8] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
Quoted 11 lines · Marc-André Lureau
Hi
Quoted 3 lines · Chao B
Hi Lureau:
I think we can remove same dependency in TcgPei.Thanks, feel free to explore that as a separate patch. This is out of scope to me.
I'll submit a patch for that later.
Thanks
Laszlo
Re: [Qemu-devel] [edk2] [PATCH v2 2/8] SecurityPkg/Tcg2Pei: drop PeiReadOnlyVariable from Depex
In reply to [email protected]Quoted 17 lines · On 03/07/18 16:57, [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]>--- 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"]
PATCH v2 3/8 MdeModulePkg: fix REGISITER -> REGISTER
In reply to [email protected]From: Marc-André Lureau <[email protected]>
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
Re: [Qemu-devel] [edk2] [PATCH v2 3/8] MdeModulePkg: fix REGISITER -> REGISTER
Quoted 11 lines · On 03/07/18 16:57, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>--- 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(-)
CC'ing Star & Eric (see Maintainers.txt).
I suggest changing te subject like this:
MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
And just so the commit message isn't empty, let's say there, "No functional changes.".
With those updates:
Thanks
Laszlo
Quoted 131 lines
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 );
Re: [Qemu-devel] [edk2] [PATCH v2 3/8] MdeModulePkg: fix REGISITER -> REGISTER
I agree with Laszlo's suggestion.
And it is good observation.
Thanks,
Star
-----Original Message-----
From: Laszlo Ersek [mailto:[email protected]]
Sent: Thursday, March 8, 2018 7:59 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yao, Jiewen <[email protected]>; Zeng, Star <[email protected]>; Dong, Eric <[email protected]>
Subject: Re: [edk2] [PATCH v2 3/8] MdeModulePkg: fix REGISITER -> REGISTER
Quoted 11 lines · On 03/07/18 16:57, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>--- 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(-)
CC'ing Star & Eric (see Maintainers.txt).
I suggest changing te subject like this:
MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
And just so the commit message isn't empty, let's say there, "No functional changes.".
With those updates:
Thanks
Laszlo
Quoted 147 lines
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +3
-2@@ -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,MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +6
-6-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->CurrentPe imCount] >=
PEIM_STATE_REGISITER_FOR_SHADOW) {MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +3
-1+if + (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->Current + PeimCount] >= 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->CurrentPei mCount] =
PEIM_STATE_REGISITER_FOR_SHADOW;MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +3
-0+ + Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentP + eimCount] = PEIM_STATE_REGISTER_FOR_SHADOW;return EFI_SUCCESS ; }MdeModulePkg/Core/Pei/Image/Image.c +4
-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->Current + PeimCount] == 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) {(quoted diff) +0
-0
b/MdeModulePkg/Core/Pei/PeiMain.hindexfef3753e4b3b..a1cdbc15d98a100644MdeModulePkg/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 );
PATCH v2 4/8 ovmf: 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
Re: [Qemu-devel] [edk2] [PATCH v2 4/8] ovmf: simplify SecurityStubDxe.inf inclusion
Quoted 67 lines · On 03/07/18 16:57, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
SecurityStubDxe.inf should be included unconditionally.
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1Signed-off-by Marc-André Lureau <[email protected]>--- 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.infOvmfPkg/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.infOvmfPkg/OvmfPkgX64.dsc +0
-1@@ -618,14 +618,12 @@ [Components] MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf -!if $(SECURE_BOOT_ENABLE) == TRUE MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { <LibraryClasses>
OvmfPkg/OvmfPkgX64.dsc [Components] · line 629
Quoted 10 lines
OvmfPkg/OvmfPkgX64.dsc +2
-3+!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
Please change the subject as follows:
OvmfPkg: simplify SecurityStubDxe.inf inclusion
With that update:
Thanks
Laszlo
PATCH v2 5/8 ovmf: add OvmfPkg Tcg2ConfigPei module
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/OvmfPkgX64.dsc | 17 ++++ OvmfPkg/OvmfPkgX64.fdf | 4 + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 57 +++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 124 +++++++++++++++++++++++ OvmfPkg/Tcg/Tcg2Config/TpmDetection.c | 46 +++++++++ 5 files changed, 248 insertions(+) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c create mode 100644 OvmfPkg/Tcg/Tcg2Config/TpmDetection.c
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) + 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 +57 -0
57 lines not on this page · raw message
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +124 -0
124 lines not on this page · raw message
OvmfPkg/Tcg/Tcg2Config/TpmDetection.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.16.2.346.g9779355e34
Re: [Qemu-devel] [edk2] [PATCH v2 5/8] ovmf: add OvmfPkg Tcg2ConfigPei module
Quoted 30 lines · On 03/07/18 16:57, [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 10 lines
--- OvmfPkg/OvmfPkgX64.dsc | 17 ++++ OvmfPkg/OvmfPkgX64.fdf | 4 + OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 57 +++++++++++ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 124 +++++++++++++++++++++++ OvmfPkg/Tcg/Tcg2Config/TpmDetection.c | 46 +++++++++ 5 files changed, 248 insertions(+) create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf create mode 100644 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c create mode 100644 OvmfPkg/Tcg/Tcg2Config/TpmDetection.c
(1) Please change the subject line to:
OvmfPkg: add customized Tcg2ConfigPei clone
Quoted 24 lines
OvmfPkg/OvmfPkgX64.dsc +5
-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
OvmfPkg/OvmfPkgX64.dsc [LibraryClasses.common.PEIM] · line 280
Quoted 4 lines
OvmfPkg/OvmfPkgX64.dsc +1
-0@@ -272,6 +277,10 @@ [LibraryClasses.common.PEIM] PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf +!if $(TPM2_ENABLE)
(2) Please be consistent with the other "!if" checks for the same define; this should be
!if $(TPM2_ENABLE) == TRUE
Quoted 49 lines
OvmfPkg/OvmfPkgX64.dsc +11
-0+ 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 +0
-0
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 5
Quoted 5 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +5
-0@@ -0,0 +1,57 @@ +## @file +# Set TPM device type +# +# This module initializes TPM device type based on variable and detection. +# This OvmfPkg of SecurityPkg only does TPM2 detection.
(3) Thanks for updating this, relative to SecurityPkg -- can you please clean it up a little? The second sentence looks malformed. I suggest something like:
# In SecurityPkg, this module initializes the TPM device type based on # a UEFI variable and/or hardware detection. In OvmfPkg, the module # only performs TPM2 hardware detection.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 17
Quoted 12 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +12
-0+# +# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR> +# Copyright (C) 2018, Red Hat, Inc. +# +# 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. +# +##
(4) Hmm these lines are a bit too long:
$ wc -L OvmfPkg/Tcg/Tcg2Config/* 96 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf 106 OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c 102 OvmfPkg/Tcg/Tcg2Config/TpmDetection.c 106 total
Can you please rewrap the source files so they don't exceed 80 characters per line?
Well, actually, don't bother with that. If you do that, some of the line breaks might force you to break function calls to multiple lines, and then we'll likely need yet another round of review, because the edk2 "multiline function call" style is pretty idiosyncratic. It goes like this (note the indentation!):
- variant 1:
SmartFunction (
Argument1OnASeparateLine,
Argument2OnASeparateLine,
Argument3OnASeparateLine
); // closing paren on a separate line, aligned exactly like this
- variant 2:
SmartFunction2 (Argument1, Argument2, Argument3, Argument4,
Argument5, Argument6);
So, I guess I'll leave it up to you. :) If you don't feel like messing with this, I can rewrap the source in a separate patchset.
Quoted 17 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +17
-0+ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = Tcg2ConfigPei + FILE_GUID = BF7F2B0C-9F2F-4889-AB5C-12460022BE87 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + ENTRY_POINT = Tcg2ConfigPeimEntryPoint + +[Sources] + Tcg2ConfigPeim.c + TpmDetection.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 44
Quoted 10 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +10
-0+ +[LibraryClasses] + PeimEntryPoint + DebugLib + Tpm2DeviceLib + +[Guids] + ## SOMETIMES_CONSUMES ## Variable:L"TCG2_CONFIGURATION" + ## SOMETIMES_CONSUMES ## Variable:L"TCG2_DEVICE_DETECTION" + gTcg2ConfigFormSetGuid
(5) Can you please drop these three lines? These lines are related to the UEFI variable(s), but we don't use those.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 46
Quoted 2 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +2
-0+ gEfiTpmDeviceSelectedGuid ## PRODUCES ## GUID # Used as a PPI GUID + gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_CONSUMES ## GUID # TPM device identifier
(6) I'll comment more on this later; just a short request here: please drop "gEfiTpmDeviceInstanceNoneGuid".
The dynamic default that you set in the DSC file is gEfiTpmDeviceInstanceNoneGuid (all bits zero), and that's sufficient for us.
(7) On the other hand, please list "gEfiTpmDeviceInstanceTpm20DtpmGuid", as SOMETIMES_CONSUMES.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 53
Quoted 7 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +7
-0+ +[Ppis] + gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES + +[Pcd] + gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## PRODUCES + gEfiSecurityPkgTokenSpaceGuid.PcdTpmAutoDetection ## CONSUMES
(8) Please drop PcdTpmAutoDetection, we never want to set that to FALSE in our DSCs.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 54
Quoted 1 line
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +1
-0+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## SOMETIMES_CONSUMES
(9) Please drop this as well. This module does not *directly* consume this PCD. If one of the library instances pulled into the module consumes the PCD, then it should be spelled out in the INF file of that library instance.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf line 57
Quoted 3 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf new file +3
-0+ +[Depex] + gEfiPeiMasterBootModePpiGuid
(10) Please drop the DEPEX (the entire section). This depex exists in the SecurityPkg original because that module behaves differently (wrt. detection / cached value) according to the boot mode, and so it has a dependency on some other PEIM detecting and exposing the boot mode.
Higher up, you correctly removed the S3_RESUME references, and indeed OVMF's clone of the source ignores the boot mode (also correctly). But that implies we have no dependency on this PPI.
Quoted 19 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +13
-0@@ -0,0 +1,124 @@ +/** @file +The module entry point for Tcg2 configuration module. + +Copyright (c) 2018, Red Hat, Inc. +Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> + +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.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 23
Quoted 10 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +10
-0+ +**/ + + +#include <PiPei.h> + +#include <Guid/TpmInstance.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/PeiServicesLib.h>
(11) Please make sure that
(11a) whatever <Library/...> headers are included in any *.c or *.h file are synched with the [LibraryClasses] section in the INF file,
(11b) ditto for <Guid/...> and [Guids] -- already covered by my remarks
(6) and (7) above
(11c) ditto for <Ppi/...> and [Ppis] -- for example, I think we need to #include <Ppi/TpmInitialized.h> for "gPeiTpmInitializationDonePpiGuid".
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 24
Quoted 1 line
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +1
-0+#include <Tcg/Tcg2Config/Tcg2ConfigNvData.h>
(12) Please drop this, we don't need it.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 26
Quoted 2 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +2
-0+ +TPM_INSTANCE_ID mTpmInstanceId[] =TPM_INSTANCE_ID_LIST ;
(13) Please drop this.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 32
Quoted 6 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +6
-0+ +CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi = { + (EFI_PEI_PPI_DESCRIPTOR_PPI |EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST ), + &gEfiTpmDeviceSelectedGuid, +NULL +};
(14) Can you please rename this to "mTpmSelectedPpiList"?
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 38
Quoted 6 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +6
-0+ +EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = { +EFI_PEI_PPI_DESCRIPTOR_PPI |EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST , + &gPeiTpmInitializationDonePpiGuid, +NULL +};
(15) Please make both of these global variables STATIC CONST.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 50
Quoted 12 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +12
-0+ +/** +This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration. + +@param SetupTpmDevice TpmDevice configuration in setup driver + +@return TpmDevice configuration +**/ +UINT8 +DetectTpmDevice ( + IN UINT8 SetupTpmDevice + );
(16a) Please remove this function declaration,
(16b) Please remove the DetectTpmDevice() function definition, together with the "TpmDetection.c" source file,
(16c) Please fold the contents of DetectTpmDevice() -- basically a call to Tpm2RequestUseTpm() -- into Tcg2ConfigPeimEntryPoint().
Quoted 17 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +17
-0+ +/** +The entry point for Tcg2 configuration driver. + +@param FileHandle Handle of the file being invoked. +@param PeiServices Describes the list of possible PEI Services. + +@retval EFI_SUCCES Convert variable to PCD successfully. +@retval Others Fail to convert variable to PCD. +**/ +EFI_STATUS +EFIAPI +Tcg2ConfigPeimEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 77
Quoted 10 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +10
-0+UINTN Size; +EFI_STATUS Status; +EFI_STATUS Status2; +TCG2_CONFIGURATION Tcg2Configuration; +UINTN Index; +UINT8 TpmDevice; + + Tcg2Configuration.TpmDevice =TPM_DEVICE_2_0_DTPM ; + +DEBUG ((EFI_D_INFO ,"OvmfPkg Tcg2ConfigPeimEntryPoint" ));
Just some side comments here:
(17a) Nowadays we use DEBUG_xxxx macros, not EFI_D_xxx macros. So this should be DEBUG_INFO.
(17b) Please don't forget the terminating "\n" for the debug message.
(17c) No need to print "OvmfPkg".
(17d) The preferred method of printing the containing function name is:
DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));
The "%s" format specifier prints UCS2-encoded wide char strings (arrays of CHAR16 elements), while the "%a" format specifier prints ASCII strings (CHAR8 arrays). __FUNCTION__ is expanded to the latter.
Quoted 18 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +18
-0+ +if (PcdGetBool (PcdTpmAutoDetection)) { + TpmDevice =DetectTpmDevice (Tcg2Configuration.TpmDevice); +DEBUG ((EFI_D_INFO ,"TpmDevice final: %x\n" , TpmDevice)); +if (TpmDevice !=TPM_DEVICE_NULL ) { + Tcg2Configuration.TpmDevice = TpmDevice; + } + }else { + TpmDevice = Tcg2Configuration.TpmDevice; + } + +// +// Convert variable to PCD. +// This is work-around because there is no gurantee DynamicHiiPcd can return correct value in DXE phase. +// Using DynamicPcd instead. +// +// NOTE: Tcg2Configuration variable contains the desired TpmDevice type, +// while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 105
Quoted 10 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +10
-0+// +for (Index =0 ; Index <sizeof (mTpmInstanceId)/sizeof (mTpmInstanceId[0 ]); Index++) { +if (TpmDevice == mTpmInstanceId[Index].TpmDevice) { + Size =sizeof (mTpmInstanceId[Index].TpmInstanceGuid); + Status =PcdSetPtrS (PcdTpmInstanceGuid, &Size, &mTpmInstanceId[Index].TpmInstanceGuid); +ASSERT_EFI_ERROR (Status); +DEBUG ((EFI_D_INFO ,"TpmDevice PCD: %g\n" , &mTpmInstanceId[Index].TpmInstanceGuid)); +break ; + } + }
(18) So basically all this logic should be simplified to:
- call Tpm2RequestUseTpm()
- if Tpm2RequestUseTpm() succeeds:
- set "PcdTpmInstanceGuid" to "gEfiTpmDeviceInstanceTpm20DtpmGuid"
- install "gEfiTpmDeviceSelectedGuid" via "mTpmSelectedPpiList"
- if Tpm2RequestUseTpm() fails:
- don't touch the PCD, our dynamic default from the DSC is fine
- install "gEfiTpmDeviceSelectedGuid" via "mTpmSelectedPpiList"
- install "gPeiTpmInitializationDonePpiGuid" via "mTpmInitializationDonePpiList"
(19) DEBUG messages are nice to keep, just please update EFI_D_xxx to DEBUG_xxx.
(20) I think all of the above "//" comments can be dropped, the resultant code will be simple enough, and our commit message is detailed.
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c line 117
Quoted 12 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +12
-0+ +// +// Selection done +// + Status =PeiServicesInstallPpi (&gTpmSelectedPpi); +ASSERT_EFI_ERROR (Status); + +// +// Even if no TPM is selected or detected, we still need intall TpmInitializationDonePpi. +// Because TcgPei or Tcg2Pei will not run, but we still need a way to notify other driver. +// Other driver can know TPM initialization state by TpmInitializedPpi. +//
(21) This comment block is nice to keep (under the "Tpm2RequestUseTpm() fails" branch); I suggest the following variant:
// If no TPM2 was detected, we still need to install
// TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon // seeing the default (all-bits-zero) contents of PcdTpmInstanceGuid, // thus we have to install the PPI in its place, in order to unblock // any dependent PEIMs.
Thank you!
Laszlo
Quoted 60 lines
OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c new file +7
-0+if (CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid)) { + Status2 =PeiServicesInstallPpi (&mTpmInitializationDonePpiList); +ASSERT_EFI_ERROR (Status2); + } + +return Status; +}OvmfPkg/Tcg/Tcg2Config/TpmDetection.c new file +46
-0@@ -0,0 +1,46 @@ +/** @file +TPM2.0 auto detection. + +Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (C) 2018, Red Hat, Inc. + +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. + +**/ + + +#include <PiPei.h> + +#include <Library/DebugLib.h> +#include <Library/Tpm2DeviceLib.h> +#include <Tcg/Tcg2Config/Tcg2ConfigNvData.h> + +/** +This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration. + +@param SetupTpmDevice TpmDevice configuration in setup driver + +@return TpmDevice configuration +**/ +UINT8 +DetectTpmDevice ( + IN UINT8 SetupTpmDevice + ) +{ +EFI_STATUS Status; + +DEBUG ((EFI_D_INFO ,"DetectTpmDevice:\n" )); + + Status =Tpm2RequestUseTpm (); +if (EFI_ERROR (Status)) { +return TPM_DEVICE_NULL ; + } + +return TPM_DEVICE_2_0_DTPM ; +}
Re: [Qemu-devel] [edk2] [PATCH v2 5/8] ovmf: add OvmfPkg Tcg2ConfigPei module
Quoted 2 lines · Laszlo Ersek
(11a) whatever <Library/...> headers are included in any *.c or *.h file are synched with the [LibraryClasses] section in the INF file,
Small correction / clarification: the "entry point" lib classes in the INF file, such as PeimEntryPoint and UefiDriverEntryPoint, need not be matched with <Library/...> #includes in the source code.
Thanks
Laszlo
PATCH v2 6/8 ovmf: link with 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/OvmfPkgX64.dsc | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 1 + 2 files changed, 8 insertions(+)
OvmfPkg/OvmfPkgX64.dsc +7 -0
@@ -278,6 +278,8 @@ [LibraryClasses.common.PEIM] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf !if $(TPM2_ENABLE) + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif
@@ -615,6 +617,11 @@ [Components] !if $(TPM2_ENABLE) == TRUE OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + <LibraryClasses> + 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] [edk2] [PATCH v2 6/8] ovmf: link with Tcg2Pei module
Quoted 7 lines · On 03/07/18 16:57, [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.
Quoted 8 lines
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/OvmfPkgX64.dsc | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 1 + 2 files changed, 8 insertions(+)
(1) Please change the subject line to:
OvmfPkg: include Tcg2Pei module
OvmfPkg/OvmfPkgX64.dsc [LibraryClasses.common.PEIM] · line 281
Quoted 10 lines
OvmfPkg/OvmfPkgX64.dsc +1
-0@@ -278,6 +278,8 @@ [LibraryClasses.common.PEIM] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf !if $(TPM2_ENABLE) + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
(2) Technically this makes sense, but given the fact that we resolve BaseCryptLib unconditionally for a bunch of other module types, I think we should do that for PEIMs as well.
Quoted 22 lines
OvmfPkg/OvmfPkgX64.dsc +6
-0+ HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif@@ -615,6 +617,11 @@ [Components] !if $(TPM2_ENABLE) == TRUE OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + <LibraryClasses> + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } !endif #OvmfPkg/OvmfPkgX64.fdf +0
-0
OvmfPkg/OvmfPkgX64.fdf [FV.PEIFV] · line 173
Quoted 7 lines
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 ################################################################################
Looks good. (The final version should handle the other DSC / FDF files too.)
Thanks!
Laszlo
Re: [Qemu-devel] [edk2] [PATCH v2 6/8] ovmf: link with Tcg2Pei module
Quoted 29 lines · Laszlo Ersek
Quoted 7 lines · On 03/07/18 16:57, [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.
Quoted 8 lines
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/OvmfPkgX64.dsc | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 1 + 2 files changed, 8 insertions(+)(1) Please change the subject line to:
OvmfPkg: include Tcg2Pei module
Quoted 8 lines
OvmfPkg/OvmfPkgX64.dsc +0
-0@@ -278,6 +278,8 @@ [LibraryClasses.common.PEIM] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
Quoted 8 lines
OvmfPkg/OvmfPkgX64.dsc [LibraryClasses.common.PEIM] · line 281
Quoted 2 lines
OvmfPkg/OvmfPkgX64.dsc +1
-0!if $(TPM2_ENABLE) + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf(2) Technically this makes sense, but given the fact that we resolve BaseCryptLib unconditionally for a bunch of other module types, I think we should do that for PEIMs as well.
Quoted 1 line
OvmfPkg/OvmfPkgX64.dsc +1
-0+ HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf
(3) Actually, can you please move this library resolution under "Tcg2Pei.inf"? Every single PEIM that uses this library instance will need us to spell out the individual hash plugins for it anyway. So I think keeping the "hash router" lib instance together with those NULL-class instances is cleaner.
Thanks
Laszlo
Quoted 34 lines
Quoted 21 lines
OvmfPkg/OvmfPkgX64.dsc +5
-0Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif@@ -615,6 +617,11 @@ [Components] !if $(TPM2_ENABLE) == TRUE OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + <LibraryClasses> + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } !endif #OvmfPkg/OvmfPkgX64.fdf +0
-0OvmfPkg/OvmfPkgX64.fdf [FV.PEIFV] · line 173
Quoted 7 lines
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 ################################################################################Looks good. (The final version should handle the other DSC / FDF files too.)
Thanks!
Laszlo
PATCH v2 7/8 ovmf: link with 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/OvmfPkgX64.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgX64.fdf | 4 ++++ 2 files changed, 20 insertions(+)
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]
@@ -362,6 +364,10 @@ [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) + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -642,6 +648,16 @@ [Components] MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endif + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUE
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] [edk2] [PATCH v2 7/8] ovmf: link with Tcg2Dxe module
Quoted 222 lines · On 03/07/18 16:57, [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.
Quoted 8 lines
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/OvmfPkgX64.dsc | 16 ++++++++++++++++ OvmfPkg/OvmfPkgX64.fdf | 4 ++++ 2 files changed, 20 insertions(+)
(1) Please change the subject line to:
OvmfPkg: include Tcg2Dxe module
Quoted 14 lines
OvmfPkg/OvmfPkgX64.dsc +2
-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]
OvmfPkg/OvmfPkgX64.dsc [LibraryClasses.common.DXE_DRIVER] · line 368
Quoted 5 lines
OvmfPkg/OvmfPkgX64.dsc +2
-0@@ -362,6 +364,10 @@ [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) + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf
(2) Can you move this HashLib resolution under Tcg2Dxe.inf?
Quoted 27 lines
OvmfPkg/OvmfPkgX64.dsc +12
-0+ Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf +!endif [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf@@ -642,6 +648,16 @@ [Components] MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf +!if $(TPM2_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + <LibraryClasses> + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endif + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUEOvmfPkg/OvmfPkgX64.fdf +0
-0
OvmfPkg/OvmfPkgX64.fdf [FV.DXEFV] · line 398
Quoted 7 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 +
(3) In the DSC file, you are adding Tcg2Dxe between RuntimeDxe and SecurityStubDxe; can you please stick with the same in the FDF file? It's easier to read.
Alternatively, you can add Tcg2Dxe after VariableRuntimeDxe too, of course, but then the DSC file should follow suit. Makes no difference functionally, but it's easier to read.
OvmfPkg/OvmfPkgX64.fdf [FV.DXEFV] · line 401
Quoted 4 lines
OvmfPkg/OvmfPkgX64.fdf +0
-0################################################################################ [FV.FVMAIN_COMPACT]
Thanks!
Laszlo
PATCH v2 8/8 ovmf: add DxeTpm2MeasureBootLib
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.
This seems to work 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
Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
--- OvmfPkg/OvmfPkgX64.dsc | 3 +++ 1 file changed, 3 insertions(+)
OvmfPkg/OvmfPkgX64.dsc +3 -0
@@ -662,6 +662,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 v2 8/8] ovmf: add DxeTpm2MeasureBootLib
(Jiewen, below I have a question for you as well; please help with that.)
Quoted 28 lines · On 03/07/18 16:57, [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.
This seems to work 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:70a22475e9f18806d2ed9193b48d80d26779d9a4Cc: Laszlo Ersek <[email protected]>
Cc: Stefan Berger <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0Signed-off-by Marc-André Lureau <[email protected]>--- OvmfPkg/OvmfPkgX64.dsc | 3 +++ 1 file changed, 3 insertions(+)OvmfPkg/OvmfPkgX64.dsc +0
-0
OvmfPkg/OvmfPkgX64.dsc [Components] · line 670
Quoted 9 lines
OvmfPkg/OvmfPkgX64.dsc +3
-0@@ -662,6 +662,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 }
(1) Marc-André, please change the subject line to:
OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
(2) I have a question for Jiewen:
DxeTpm2MeasureBootLib consumes the TCG2 protocol, but it does not depend on it with a DEPEX. Instead, DxeTpm2MeasureBootHandler() tries to locate the protocol on every invocation.
This means that SecurityStubDxe may produce the Security and Security2 Architectural Protocols before measurements into the TPM2 device are possible. Therefore, UEFI_DRIVER modules (which depend on all of the Arch protocols) may be started before they can be measured into the TPM.
Now, this is likely no problem for UEFI_DRIVER modules that are built into the firmware volume(s), because those are measured by Tcg2Pei anyway. However, it would be a problem for UEFI_DRIVER modules / apps that come from external media (disk, network, PCI oprom, etc).
However, such are loaded only in the BDS phase, and BDS is only entered after all of the DXE drivers are dispatched from the firmware volumes. In other words, the ordering between Tcg2Dxe and external UEFI_DRIVER / UEFI_APPLICATION modules is ensured that Tcg2Dxe will be dispatched in the DXE phase, while the latter will only be loaded in BDS.
Is this intentional? Is my understanding correct?
(3) If that's the case, then Marc-André, please add the following to the commit message:
--------
Hooking DxeTpm2MeasureBootLib into SecurityStubDxe ensures that the Security and Security2 Arch protocols will entail, by the time of entering the BDS phase, the measuring of UEFI binaries into the TPM. Thus, external UEFI_DRIVER and UEFI_APPLICATION modules (which are loaded in the BDS phase, from disk, network, PCI oprom, etc) will be measured.
Drivers dispatched in the DXE phase before Tcg2Dxe will not be measured individually; however such drivers come from the firmware volume(s), and those are measured in the PEI phase by Tcg2Pei.
--------
Thanks!
Laszlo
Re: [Qemu-devel] [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib
Quoted 3 lines · Laszlo Ersek
In other words, the ordering between Tcg2Dxe and external
UEFI_DRIVER/UEFI_APPLICATIONmodules is ensured that Tcg2Dxe will be dispatched in the DXE phase, while the latter will only be loaded in BDS.
Sigh, I meant:
The ordering between Tcg2Dxe and external UEFI_DRIVER / UEFI_APPLICATION modules is ensured *by the fact* that Tcg2Dxe will be dispatched in the DXE phase, while the latter will only be loaded in BDS.
Thanks,
Laszlo
Re: [Qemu-devel] [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib
In reply to Laszlo ErsekVery good question.
Comment below:
Quoted 56 lines
-----Original Message-----
From: Laszlo Ersek [mailto:[email protected]]
Sent: Friday, March 9, 2018 3:54 AM
To: [email protected]; [email protected]; Yao, Jiewen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib(Jiewen, below I have a question for you as well; please help with that.)
Quoted 5 lines · On 03/07/18 16:57, [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.
Quoted 8 lines
This seems to work 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:
70a22475e9f18806d2ed9193b48d80d26779d9a4Quoted 14 lines
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/OvmfPkgX64.dsc | 3 +++ 1 file changed, 3 insertions(+)OvmfPkg/OvmfPkgX64.dsc +0
-0OvmfPkg/OvmfPkgX64.dsc [Components] · line 664
Quoted 3 lines
OvmfPkg/OvmfPkgX64.dsc +0
-0@@ -662,6 +662,9 @@ [Components] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUENULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf
OvmfPkg/OvmfPkgX64.dsc [Components]
Quoted 3 lines
OvmfPkg/OvmfPkgX64.dsc +3
-0+!endif +!if $(TPM2_ENABLE) == TRUE +NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.i nf
OvmfPkg/OvmfPkgX64.dsc [Components] · line 670
Quoted 4 lines
OvmfPkg/OvmfPkgX64.dsc +0
-0!endif }(1) Marc-André, please change the subject line to:
Quoted 8 lines
OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
(2) I have a question for Jiewen:
DxeTpm2MeasureBootLib consumes the TCG2 protocol, but it does not depend on it with a DEPEX. Instead,
DxeTpm2MeasureBootHandler()tries to locate the protocol on every invocation.
[Jiewen] Yes.
Quoted 3 lines
This means that SecurityStubDxe may produce the Security and Security2 Architectural Protocols before measurements into the TPM2 device are possible.
[Jiewen] Yes.
Quoted 6 lines
Therefore,
UEFI_DRIVERmodules (which depend on all of the Arch protocols) may be started before they can be measured into the TPM.Now, this is likely no problem for
UEFI_DRIVERmodules that are built into the firmware volume(s), because those are measured by Tcg2Pei anyway.
[Jiewen] That is TRUE.
However, it would be a problem for UEFI_DRIVER modules / apps
Quoted 1 line
that come from external media (disk, network, PCI oprom, etc).
[Jiewen] By design, the 3rd part module should not be invoked before EndOfDxe.
All Arch Protocol Ready is not strong enough. :-)
Please refer to https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/SecurityStubDxe/Defer3rdPartyImageLoad.c
If a non-FV image is loaded before EndOfDxe, it will be queued into mDeferred3rdPartyImage.
We also added EfiBootManagerDispatchDeferredImages() API in https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Include/Library/UefiBootManagerLib.h and implemented in https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
A platform must call EfiBootManagerDispatchDeferredImages(), if the platform supports PCI OROM.
You can find the sample code in https://github.com/tianocore/edk2-platforms/blob/devel-MinPlatform/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c
Quoted 7 lines
However, such are loaded only in the BDS phase, and BDS is only entered after all of the DXE drivers are dispatched from the firmware volumes. In other words, the ordering between Tcg2Dxe and external
UEFI_DRIVER/UEFI_APPLICATIONmodules is ensured that Tcg2Dxe will be dispatched in the DXE phase, while the latter will only be loaded in BDS.Is this intentional? Is my understanding correct?
[Jiewen] Right. The only assumption is: Tcg2Dxe is included in the firmware volume and it is dispatched before EndOfDxe.
Quoted 19 lines
(3) If that's the case, then Marc-André, please add the following to the commit message:
--------
Hooking DxeTpm2MeasureBootLib into SecurityStubDxe ensures that the Security and Security2 Arch protocols will entail, by the time of entering the BDS phase, the measuring of UEFI binaries into the TPM. Thus, externalUEFI_DRIVERandUEFI_APPLICATIONmodules (which are loaded in the BDS phase, from disk, network, PCI oprom, etc) will be measured.Drivers dispatched in the DXE phase before Tcg2Dxe will not be measured individually; however such drivers come from the firmware volume(s), and those are measured in the PEI phase by Tcg2Pei.
--------Thanks!
Laszlo
Re: [Qemu-devel] [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib
Besides the comment below, I should have used the example in OvmfPkg.
Please refer to https://github.com/tianocore/edk2/blob/master/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
The EfiBootManagerDispatchDeferredImages() API call is added just after gEfiDxeSmmReadyToLockProtocolGuid.
So I don’t see any problem in OVMF pkg.
Thank you
Yao Jiewen
Quoted 154 lines
-----Original Message-----
From: edk2-devel [mailto:[email protected]] On Behalf Of Yao, Jiewen
Sent: Friday, March 9, 2018 8:39 AM
To: Laszlo Ersek <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [edk2] [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLibVery good question.
Comment below:Quoted 35 lines
-----Original Message-----
From: Laszlo Ersek [mailto:[email protected]]
Sent: Friday, March 9, 2018 3:54 AM
To: [email protected]; [email protected]; Yao, Jiewen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib(Jiewen, below I have a question for you as well; please help with that.)
Quoted 5 lines · On 03/07/18 16:57, [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.
Quoted 8 lines
This seems to work 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:
70a22475e9f18806d2ed9193b48d80d26779d9a4Quoted 9 lines
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/OvmfPkgX64.dsc | 3 +++ 1 file changed, 3 insertions(+)Quoted 9 lines
OvmfPkg/OvmfPkgX64.dsc [Components] · line 664
Quoted 8 lines
OvmfPkg/OvmfPkgX64.dsc +0
-0@@ -662,6 +662,9 @@ [Components] <LibraryClasses> !if $(SECURE_BOOT_ENABLE) == TRUENULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf
Quoted 4 lines
OvmfPkg/OvmfPkgX64.dsc [Components]
Quoted 3 lines
OvmfPkg/OvmfPkgX64.dsc +3
-0+!endif +!if $(TPM2_ENABLE) == TRUE +NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.i
Quoted 8 lines
nf
OvmfPkg/OvmfPkgX64.dsc [Components] · line 670
Quoted 4 lines
OvmfPkg/OvmfPkgX64.dsc +0
-0!endif }(1) Marc-André, please change the subject line to:
Quoted 8 lines
OvmfPkg: plug DxeTpm2MeasureBootLib into SecurityStubDxe
(2) I have a question for Jiewen:
DxeTpm2MeasureBootLib consumes the TCG2 protocol, but it does not depend on it with a DEPEX. Instead,
DxeTpm2MeasureBootHandler()tries to locate the protocol on every invocation.[Jiewen] Yes.
Quoted 3 lines
This means that SecurityStubDxe may produce the Security and Security2 Architectural Protocols before measurements into the TPM2 device are possible.
[Jiewen] Yes.
Quoted 6 lines
Therefore,
UEFI_DRIVERmodules (which depend on all of the Arch protocols) may be started before they can be measured into the TPM.Now, this is likely no problem for
UEFI_DRIVERmodules that are built into the firmware volume(s), because those are measured by Tcg2Pei anyway.[Jiewen] That is TRUE.
However, it would be a problem for
UEFI_DRIVERmodules / appsQuoted 1 line
that come from external media (disk, network, PCI oprom, etc).
[Jiewen] By design, the 3rd part module should not be invoked before EndOfDxe. All Arch Protocol Ready is not strong enough. :-)
Please refer to
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/SecurityStubDxe/Defer3rdPartyImageLoad.cIf a non-FV image is loaded before EndOfDxe, it will be queued into mDeferred3rdPartyImage.
We also added
EfiBootManagerDispatchDeferredImages()API in
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Include/Library/UefiBootManagerLib.hand implemented in
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
A platform must callEfiBootManagerDispatchDeferredImages(), if the platform supports PCI OROM.You can find the sample code in
https://github.com/tianocore/edk2-platforms/blob/devel-MinPlatform/Platform
/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.cQuoted 7 lines
However, such are loaded only in the BDS phase, and BDS is only entered after all of the DXE drivers are dispatched from the firmware volumes. In other words, the ordering between Tcg2Dxe and external
UEFI_DRIVER/UEFI_APPLICATIONmodules is ensured that Tcg2Dxe will be dispatched in the DXE phase, while the latter will only be loaded in BDS.Is this intentional? Is my understanding correct?
[Jiewen] Right. The only assumption is: Tcg2Dxe is included in the firmware volume and it is dispatched before EndOfDxe.
Quoted 12 lines
(3) If that's the case, then Marc-André, please add the following to the commit message:
--------
Hooking DxeTpm2MeasureBootLib into SecurityStubDxe ensures that the Security and Security2 Arch protocols will entail, by the time of entering the BDS phase, the measuring of UEFI binaries into the TPM. Thus, externalUEFI_DRIVERandUEFI_APPLICATIONmodules (which are loaded in the BDS phase, from disk, network, PCI oprom, etc) will be measured.Quoted 7 lines
Drivers dispatched in the DXE phase before Tcg2Dxe will not be measured individually; however such drivers come from the firmware volume(s), and those are measured in the PEI phase by Tcg2Pei.
--------Thanks!
Laszlo_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [Qemu-devel] [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib
In reply to Yao, JiewenQuoted 15 lines · Jiewen
Very good question.
Comment below:Quoted 11 lines
-----Original Message-----
From: Laszlo Ersek [mailto:[email protected]]
Sent: Friday, March 9, 2018 3:54 AM
To: [email protected]; [email protected]; Yao, Jiewen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLibHowever, it would be a problem for
UEFI_DRIVERmodules / apps that come from external media (disk, network, PCI oprom, etc).
Quoted 7 lines
[Jiewen] By design, the 3rd part module should not be invoked before EndOfDxe. All Arch Protocol Ready is not strong enough. :-) Please refer to
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/SecurityStubDxe/Defer3rdPartyImageLoad.cIf a non-FV image is loaded before EndOfDxe, it will be queued into mDeferred3rdPartyImage.
OK, thank you -- I suspected image deferral was somehow related to this. I remember deferred execution from the OVMF log, even though at present we hook only DxeImageVerificationLib into SecurityStubDxe.
Quoted 6 lines
We also added
EfiBootManagerDispatchDeferredImages()API in
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Include/Library/UefiBootManagerLib.h
and implemented in
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
A platform must callEfiBootManagerDispatchDeferredImages(), if the platform supports PCI OROM.
Yep, OVMF does that already. In "OvmfPkg/Library/PlatformBootManagerLib", we have the following order of operations, in PlatformBootManagerBeforeConsole():
(a) connect all PCI root bridges non-recursively (this produces PciIo instances and discovers the PCI oproms)
(b) kick QEMU so that it generates the ACPI tables that OVMF has to install (this depends on PciIo instances existing, from step (1a)), and actually install those tables
(c) signal End-of-Dxe (this depends on step (1b), because S3 support needs the FACS table coming from step (1b))
(d) write an INFO opcode to the S3 boot script so that the boot script is never empty
(e) install DxeSmmReadyToLock (this may come only after steps (1c) and
(1d))
(f) we call EfiBootManagerDispatchDeferredImages(). This is from Ray's commit 9789894e3ba3 ("OvmfPkg/PlatformBds: Dispatch deferred images after EndOfDxe", 2016-11-10).
(The rest of PlatformBootManagerBeforeConsole() skipped here.)
So, we have all the right operations in place, I just missed that non-FV images loaded before End-of-Dxe (such as PCI oproms) are deferred until step (f), and that the deferral will cover the TPM measurements too.
This is great, because it's an even stronger guarantee than what I would have wished for. I mean the argument I wrote up earlier -- about oproms not being dispatched before entering BDS, at which point Tcg2Dxe will have been dispatched already -- was already good enough, but now I know that PCI oproms are delayed even *within* BDS until after we explicitly end DXE and dispatch the deferred images.
Quoted 12 lines
You can find the sample code in
https://github.com/tianocore/edk2-platforms/blob/devel-MinPlatform/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.cQuoted 7 lines
However, such are loaded only in the BDS phase, and BDS is only entered after all of the DXE drivers are dispatched from the firmware volumes. In other words, the ordering between Tcg2Dxe and external
UEFI_DRIVER/UEFI_APPLICATIONmodules is ensured that Tcg2Dxe will be dispatched in the DXE phase, while the latter will only be loaded in BDS.
Quoted 4 lines
Quoted 1 line
Is this intentional? Is my understanding correct?
[Jiewen] Right. The only assumption is: Tcg2Dxe is included in the firmware volume and it is dispatched before EndOfDxe.
Perfect. Thank you.
So, Marc-André, I would request the following commit message *addition* (not replacement!) then:
--------------
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).
--------------
Jiewen, does this look OK?
Thanks!
Laszlo
Re: [Qemu-devel] [edk2] [PATCH v2 8/8] ovmf: add DxeTpm2MeasureBootLib
Good idea.
The additional message looks great!!!
thank you!
Yao, Jiewen
Quoted 3 lines · 在 2018年3月9日,下午6:26,Laszlo Ersek <[email protected]> 写道:
in
Hi Marcandre,
Quoted 2 lines
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 &
Where is the swtpm_setup.sh? And could you tell how to build & install the swtpm?
Thanks
Steven Shi
Hi
Quoted 6 lines · Steven
Hi Marcandre,
Quoted 2 lines
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 &Where is the
swtpm_setup.sh? And could you tell how to build & install the swtpm?
You need to compile & install libtpms & swtpm :
git clone -b tpm2-preview.rev146.v2 https://github.com/stefanberger/libtpms
cd libtpms
autoreconf -vfi && ./configure --with-tpm2 --with-openssl && make install
git clone -b tpm2-preview.v2 https://github.com/stefanberger/swtpm
cd swtpm
autoreconf -vfi && ./configure --with-openssl && make install
Then you can run:
mkdir tpmstatedirswtpm_setup.sh --tpm2 --tpm-state tpmstatedir
Run the emulator:
swtpm socket --tpmstate dir=tpmstatedir --ctrl
type=unixio,path=tpmemu.sock --tpm2
Run qemu (from git) with ovmf (with this series):
qemu ... -chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 -drive if=pflash,format=raw,file=OVMF_CODE.fd,readonly -drive if=pflash,format=raw,file=OVMF_VARS.fd ..
cheers
Signature · 1 line
Marc-André Lureau
Hi Marcandre,
Thanks for your command steps and I tried them, but my qemu failed to connect the socket tpmemu.sock. When I added the control channel to the TPM, the swtpm socket command stuck there and never exit. Not sure whether it was successful. Below are the command steps running output in my side
Quoted 3 lines
Then you can run:
mkdir tpmstatedirswtpm_setup.sh--tpm2 --tpm-state tpmstatedir
$ swtpm_setup.sh --tpm2 --tpm-state tpmstatedir Starting vTPM manufacturing as jshi19:jshi19 @ 2018年03月09日 星期五 10时28分39秒 TPM is listening on TCP port 47364. Successfully authored TPM state. Ending vTPM manufacturing @ 2018年03月09日 星期五 10时28分39秒
Quoted 2 lines
Run the emulator:
swtpm socket --tpmstate dir=tpmstatedir --ctrl type=unixio,path=tpmemu.sock --tpm2
$ swtpm socket --tpmstate dir=tpmstatedir --ctrl type=unixio,path=tpmemu.sock --tpm2 (the swtpm socket command stuck there and never exit)
Quoted 5 lines
Run qemu (from git) with ovmf (with this series):
qemu ... -chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 -drive if=pflash,format=raw,file=OVMF_CODE.fd,readonly -drive if=pflash,format=raw,file=OVMF_VARS.fd ..
$ qemu-system-x86_64 -serial file:serial.log -m 5120 -hda fat:. -monitor stdio --enable-kvm -smp 4 -bios ../Ovmf3264/NOOPT_GCC5/FV/OVMF.fd -chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 qemu-system-x86_64: -chardev socket,id=chrtpm,path=tpmemu.sock: Failed to connect socket tpmemu.sock: No such file or directory
I use the latest version qemu as below:
$ qemu-system-x86_64 --version QEMU emulator version 2.11.50 (v2.10.0-4184-g930b01138b-dirty) Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
Thanks
Steven Shi
Quoted 18 lines · Steven
Hi Marcandre,
Thanks for your command steps and I tried them, but my qemu failed to connect the socket tpmemu.sock. When I added the control channel to the TPM, the swtpm socket command stuck there and never exit. Not sure whether it was successful. Below are the command steps running output in my sideQuoted 3 lines
Then you can run:
mkdir tpmstatedirswtpm_setup.sh--tpm2 --tpm-state tpmstatedir$ swtpm_setup.sh --tpm2 --tpm-state tpmstatedir Starting vTPM manufacturing as jshi19:jshi19 @ 2018年03月09日 星期五 10时28分39秒 TPM is listening on TCP port 47364. Successfully authored TPM state. Ending vTPM manufacturing @ 2018年03月09日 星期五 10时28分39秒Quoted 2 lines
Run the emulator:
swtpm socket --tpmstate dir=tpmstatedir --ctrl type=unixio,path=tpmemu.sock --tpm2$ swtpm socket --tpmstate dir=tpmstatedir --ctrl type=unixio,path=tpmemu.sock --tpm2 (the swtpm socket command stuck there and never exit)
Quoted 7 lines
Quoted 5 lines
Run qemu (from git) with ovmf (with this series):
qemu ... -chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 -drive if=pflash,format=raw,file=OVMF_CODE.fd,readonly -drive if=pflash,format=raw,file=OVMF_VARS.fd ..$ qemu-system-x86_64 -serial file:serial.log -m 5120 -hda fat:. -monitor stdio --enable-kvm -smp 4 -bios ../Ovmf3264/NOOPT_GCC5/FV/OVMF.fd -chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 qemu-system-x86_64: -chardev socket,id=chrtpm,path=tpmemu.sock: Failed to connect socket tpmemu.sock: No such file or directory
Try giving it both, swtpm and qemu, the full path to the socket.
Quoted 9 lines
I use the latest version qemu as below:
$ qemu-system-x86_64 --version QEMU emulator version 2.11.50 (v2.10.0-4184-g930b01138b-dirty) Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developersThanks
Steven Shi
It works in my side after specify the full path to swtpm tpmemu.sock in qemu command options. Thanks!
Steven Shi
Intel\SSG\STO\UEFI Firmware
Tel: +86 021-61166522
iNet: 821-6522
Quoted 60 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Friday, March 9, 2018 9:54 PM
To: Shi, Steven <[email protected]>; Marc-André Lureau <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Yao, Jiewen <[email protected]>; [email protected]; [email protected]
Subject: Re: [edk2] [PATCH v2 0/8] RFC: ovmf: preliminary TPM2 supportQuoted 2 lines · Steven
Hi Marcandre,
Thanks for your command steps and I tried them, but my qemu failed toconnect the socket tpmemu.sock. When I added the control channel to the TPM, the swtpm socket command stuck there and never exit. Not sure whether it was successful.
Quoted 7 lines
Below are the command steps running output in my side
Quoted 3 lines
Then you can run:
mkdir tpmstatedirswtpm_setup.sh--tpm2 --tpm-state tpmstatedir$ swtpm_setup.sh --tpm2 --tpm-state tpmstatedir Starting vTPM manufacturing as jshi19:jshi19 @ 2018年03月09日 星期五 10时28分39秒
Quoted 3 lines
TPM is listening on TCP port 47364. Successfully authored TPM state.
Ending vTPM manufacturing @ 2018年03月09日 星期五 10时28分39秒
Quoted 3 lines
Quoted 3 lines
Run the emulator:
swtpm socket --tpmstate dir=tpmstatedir --ctrltype=unixio,path=tpmemu.sock --tpm2
Quoted 1 line
$ swtpm socket --tpmstate dir=tpmstatedir --ctrltype=unixio,path=tpmemu.sock --tpm2
Quoted 8 lines
(the swtpm socket command stuck there and never exit)
Quoted 5 lines
Run qemu (from git) with ovmf (with this series):
qemu ... -chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 -drive if=pflash,format=raw,file=OVMF_CODE.fd,readonly -drive if=pflash,format=raw,file=OVMF_VARS.fd ..$ qemu-system-x86_64 -serial file:serial.log -m 5120 -hda fat:. -monitorstdio --enable-kvm -smp 4 -bios ../Ovmf3264/NOOPT_GCC5/FV/OVMF.fd - chardev socket,id=chrtpm,path=tpmemu.sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0
Quoted 1 line
qemu-system-x86_64: -chardev socket,id=chrtpm,path=tpmemu.sock:
Failed to connect socket tpmemu.sock: No such file or directory
Try giving it both, swtpm and qemu, the full path to the socket.
Quoted 9 lines
I use the latest version qemu as below:
$ qemu-system-x86_64 --version QEMU emulator version 2.11.50 (v2.10.0-4184-g930b01138b-dirty) Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developersThanks
Steven Shi