From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mx.groups.io with SMTP id smtpd.web12.8234.1582725778589380058 for ; Wed, 26 Feb 2020 06:02:58 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: linux.ibm.com, ip: 148.163.156.1, mailfrom: stefanb@linux.ibm.com) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01QDxJOm073772; Wed, 26 Feb 2020 09:02:58 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ydkf96grs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Feb 2020 09:02:57 -0500 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 01QDxYFn075020; Wed, 26 Feb 2020 09:02:57 -0500 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ydkf96gqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Feb 2020 09:02:57 -0500 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 01QDtbot008947; Wed, 26 Feb 2020 14:02:56 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma02wdc.us.ibm.com with ESMTP id 2ydcmknp85-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Feb 2020 14:02:56 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01QE2tYS58196332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Feb 2020 14:02:55 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6105AC605B; Wed, 26 Feb 2020 14:02:55 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF547C605A; Wed, 26 Feb 2020 14:02:54 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 26 Feb 2020 14:02:54 +0000 (GMT) Subject: Re: [PATCH v3 2/6] OvmfPkg: detect TPM 1.2 in Tcg2ConfigPei To: marcandre.lureau@redhat.com, devel@edk2.groups.io Cc: lersek@redhat.com, simon.hardy@itdev.co.uk References: <20200226093459.1131530-1-marcandre.lureau@redhat.com> <20200226093459.1131530-3-marcandre.lureau@redhat.com> From: "Stefan Berger" Message-ID: Date: Wed, 26 Feb 2020 09:02:54 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <20200226093459.1131530-3-marcandre.lureau@redhat.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-26_04:2020-02-26,2020-02-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 bulkscore=0 adultscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002260104 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id 01QDxJOm073772 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 2/26/20 4:34 AM, marcandre.lureau@redhat.com wrote: > From: Marc-Andr=C3=A9 Lureau > > Complement commit 6cf1880fb5b ("OvmfPkg: add customized Tcg2ConfigPei > clone", 2018-03-09) by detecting TPM 1.2 devices. > > Since Tpm12RequestUseTpm() returns success on any TPM interface, > (including FIFO & CRB which are TPM 2.0), try to send a GetTicks TPM > 1.2 command to probe the version. In case of failure, fallback on TPM > 2.0 path. > > Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger > --- > OvmfPkg/OvmfPkgIa32.dsc | 2 + > OvmfPkg/OvmfPkgIa32X64.dsc | 2 + > OvmfPkg/OvmfPkgX64.dsc | 2 + > OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 3 + > OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 81 +++++++++++++++++++----= - > 5 files changed, 75 insertions(+), 15 deletions(-) > > diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc > index 38b013ad9543..293e95a2ae81 100644 > --- a/OvmfPkg/OvmfPkgIa32.dsc > +++ b/OvmfPkg/OvmfPkgIa32.dsc > @@ -206,6 +206,7 @@ > XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf > =20 > !if $(TPM_ENABLE) =3D=3D TRUE > + Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.= inf > Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.in= f > Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu= /DxeTcg2PhysicalPresenceLib.inf > Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendo= rLibNull.inf > @@ -281,6 +282,7 @@ > =20 > !if $(TPM_ENABLE) =3D=3D TRUE > BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > + Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLib= DTpm.inf > Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDT= pm.inf > !endif > =20 > diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc > index e075f0766935..5cfa3fc849fe 100644 > --- a/OvmfPkg/OvmfPkgIa32X64.dsc > +++ b/OvmfPkg/OvmfPkgIa32X64.dsc > @@ -211,6 +211,7 @@ > XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf > =20 > !if $(TPM_ENABLE) =3D=3D TRUE > + Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.= inf > Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.in= f > Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu= /DxeTcg2PhysicalPresenceLib.inf > Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendo= rLibNull.inf > @@ -286,6 +287,7 @@ > =20 > !if $(TPM_ENABLE) =3D=3D TRUE > BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > + Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLib= DTpm.inf > Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDT= pm.inf > !endif > =20 > diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc > index 3b1ebf123b51..78481a62e021 100644 > --- a/OvmfPkg/OvmfPkgX64.dsc > +++ b/OvmfPkg/OvmfPkgX64.dsc > @@ -211,6 +211,7 @@ > XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf > =20 > !if $(TPM_ENABLE) =3D=3D TRUE > + Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.= inf > Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.in= f > Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu= /DxeTcg2PhysicalPresenceLib.inf > Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendo= rLibNull.inf > @@ -286,6 +287,7 @@ > =20 > !if $(TPM_ENABLE) =3D=3D TRUE > BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > + Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLib= DTpm.inf > Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDT= pm.inf > !endif > =20 > diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf b/OvmfPkg/Tcg/Tcg= 2Config/Tcg2ConfigPei.inf > index e34cd6210611..f380b86b5d89 100644 > --- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf > +++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf > @@ -31,11 +31,14 @@ > PeimEntryPoint > DebugLib > PeiServicesLib > + Tpm12CommandLib > + Tpm12DeviceLib > Tpm2DeviceLib > =20 > [Guids] > gEfiTpmDeviceSelectedGuid ## PRODUCES ## GUID # Used as a= PPI GUID > gEfiTpmDeviceInstanceTpm20DtpmGuid ## SOMETIMES_CONSUMES > + gEfiTpmDeviceInstanceTpm12Guid ## SOMETIMES_CONSUMES > =20 > [Ppis] > gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES > diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c b/OvmfPkg/Tcg/Tcg2= Config/Tcg2ConfigPeim.c > index 99d571d9fa6d..770229ed9912 100644 > --- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c > +++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c > @@ -18,6 +18,8 @@ > #include > #include > #include > +#include > +#include > #include > =20 > STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi =3D { > @@ -32,6 +34,43 @@ STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializat= ionDonePpiList =3D { > NULL > }; > =20 > +#pragma pack(1) > + > +typedef struct { > + TPM_RSP_COMMAND_HDR Hdr; > + TPM_CURRENT_TICKS CurrentTicks; > +} TPM_RSP_GET_TICKS; > + > +#pragma pack() > + > +/** > + Probe for the TPM for 1.2 version, by sending TPM1.2 GetTicks > + > + Sending a TPM1.2 command to a TPM2 should return a TPM1.2 > + header (tag =3D 0xc4) and error code (TPM_BADTAG =3D 0x1e) > +**/ > +static EFI_STATUS > +TestTpm12 ( > + ) > +{ > + EFI_STATUS Status; > + TPM_RQU_COMMAND_HDR Command; > + TPM_RSP_GET_TICKS Response; > + UINT32 Length; > + > + Command.tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND); > + Command.paramSize =3D SwapBytes32 (sizeof (Command)); > + Command.ordinal =3D SwapBytes32 (TPM_ORD_GetTicks); > + > + Length =3D sizeof (Response); > + Status =3D Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, = &Length, (UINT8 *)&Response); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + return EFI_SUCCESS; > +} > + > /** > The entry point for Tcg2 configuration driver. > =20 > @@ -50,27 +89,39 @@ Tcg2ConfigPeimEntryPoint ( > =20 > DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__)); > =20 > - Status =3D Tpm2RequestUseTpm (); > - if (!EFI_ERROR (Status)) { > - DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__)); > - Size =3D sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid); > + Status =3D Tpm12RequestUseTpm (); > + if (!EFI_ERROR (Status) && TestTpm12 () =3D=3D EFI_SUCCESS) { > + DEBUG ((DEBUG_INFO, "%a: TPM1.2 detected\n", __FUNCTION__)); > + Size =3D sizeof (gEfiTpmDeviceInstanceTpm12Guid); > Status =3D PcdSetPtrS ( > PcdTpmInstanceGuid, > &Size, > - &gEfiTpmDeviceInstanceTpm20DtpmGuid > + &gEfiTpmDeviceInstanceTpm12Guid > ); > ASSERT_EFI_ERROR (Status); > } else { > - DEBUG ((DEBUG_INFO, "%a: no TPM2 detected\n", __FUNCTION__)); > - // > - // 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, thu= s we have > - // to install the PPI in its place, in order to unblock any depend= ent > - // PEIMs. > - // > - Status =3D PeiServicesInstallPpi (&mTpmInitializationDonePpiList); > - ASSERT_EFI_ERROR (Status); > + Status =3D Tpm2RequestUseTpm (); > + if (!EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__)); > + Size =3D sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid); > + Status =3D PcdSetPtrS ( > + PcdTpmInstanceGuid, > + &Size, > + &gEfiTpmDeviceInstanceTpm20DtpmGuid > + ); > + ASSERT_EFI_ERROR (Status); > + } else { > + DEBUG ((DEBUG_INFO, "%a: no TPM detected\n", __FUNCTION__)); > + // > + // If no TPM2 was detected, we still need to install > + // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upo= n seeing > + // the default (all-bits-zero) contents of PcdTpmInstanceGuid, t= hus we have > + // to install the PPI in its place, in order to unblock any depe= ndent > + // PEIMs. > + // > + Status =3D PeiServicesInstallPpi (&mTpmInitializationDonePpiList= ); > + ASSERT_EFI_ERROR (Status); > + } > } > =20 > //