From nobody Sat Feb 7 05:53:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81652+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81652+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1633670494; cv=none; d=zohomail.com; s=zohoarc; b=N/XlkykWegkW2BCu7FaqFit5M61xbGnXcYfzFIzUfMQmxfRUQITYubhqqhsbDEmbFq7k5IDxYoQwPup+2pzafc6eo8wdhkE1DGQ3c7n0aIESZT5+2y80DP1UuWYza3AD9tUQek6rdf7tcHjoMFp+5rmIzFugbCcwuncI6+DL4Hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633670494; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+o4uQmPltCCJnMezULughsTfj8ORNzNzjs48mwUyhWc=; b=HWNgxCh7XZpwydyv+8gdpqj+WyDICYnAo1rFbuvE5qb5UU7osn2NDvlhxePHYuAgj4QrIWJFaVvnTDIBUTnO8EZGsmphBiNW+c3KaODsvpd+lUQwDPklwikIUokD7RIVFEWv/ZfbUzycthSpZQB0jEDl11SgBz3NcETls5dhmsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81652+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633670494579934.43740772151; Thu, 7 Oct 2021 22:21:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IprbYY1788612xr66lN1tJDP; Thu, 07 Oct 2021 22:21:34 -0700 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web10.5168.1633670487432256251 for ; Thu, 07 Oct 2021 22:21:33 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="289934969" X-IronPort-AV: E=Sophos;i="5.85,356,1624345200"; d="scan'208";a="289934969" X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 22:21:33 -0700 X-IronPort-AV: E=Sophos;i="5.85,356,1624345200"; d="scan'208";a="478844444" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.238.4.37]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 22:21:31 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH V2 3/3] SecurityPkg: Support TdProtocol in DxeTpmMeasurementLib Date: Fri, 8 Oct 2021 13:21:14 +0800 Message-Id: <844e9fe333a90c76c923c541e8439716a2d949d5.1633661591.git.min.m.xu@intel.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,min.m.xu@intel.com X-Gm-Message-State: qCkr5TEFo7yQmnoXqhS0v4D9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633670494; bh=mFoqJLxTW1/5uvXkSPjpkQ3LH6ND3sNao9vqlue5HMw=; h=Cc:Date:From:Reply-To:Subject:To; b=tPAVOHJyRyDnAPVxO70blMIE9j3amyc3vH1mK8uDYTT808HxzL31iy8rfAXpiFRU0oJ uTZX1UAJADnC7o9eN0kaG5Ld/StE6047CgXYuTRfMlQqsjGjbERM8rNF1eAcPcW6UFWFY GbxMEDuwf1BQdt2klEjHceGl8t0L1+SDcvM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633671396880100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3625 DxeTpmMeasurementLib supports TPM based measurement in DXE phase. After Td protocol is introduced, TD based measurement needs to be supported in DxeTpmMeasurementLib as well. In TpmMeasureAndLogData, TD based measurement will be first called. If it failed, TPM based measurement will be called sequentially. Currently there is an assumption that TD based measurement and TPM based measurement won't be exist at the same time.If the assumption is not true in the future, we will revisit here then. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Jiewen Yao Cc: Jian J Wang Signed-off-by: Min Xu --- .../DxeTpmMeasurementLib.c | 87 ++++++++++++++++++- .../DxeTpmMeasurementLib.inf | 1 + 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.= c b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c index 061136ee7860..f8cd289ba62c 100644 --- a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c +++ b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c @@ -19,7 +19,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include - +#include =20 =20 /** @@ -149,6 +149,73 @@ Tpm20MeasureAndLogData ( return Status; } =20 +/** + Tdx measure and log data, and extend the measurement result into a + specific TDX RTMR. + + @param[in] PcrIndex PCR Index. + @param[in] EventType Event type. + @param[in] EventLog Measurement event log. + @param[in] LogLen Event log length in bytes. + @param[in] HashData The start of the data buffer to be hashed, = extended. + @param[in] HashDataLen The length, in bytes, of the buffer referen= ced by HashData + + @retval EFI_SUCCESS Operation completed successfully. + @retval EFI_UNSUPPORTED Tdx device not available. + @retval EFI_OUT_OF_RESOURCES Out of memory. + @retval EFI_DEVICE_ERROR The operation was unsuccessful. +**/ +EFI_STATUS +EFIAPI +TdxMeasureAndLogData ( + IN UINT32 PcrIndex, + IN UINT32 EventType, + IN VOID *EventLog, + IN UINT32 LogLen, + IN VOID *HashData, + IN UINT64 HashDataLen + ) +{ + EFI_STATUS Status; + EFI_TD_PROTOCOL *TdProtocol; + EFI_TD_EVENT *TdEvent; + UINT32 MrIndex; + + Status =3D gBS->LocateProtocol (&gEfiTdProtocolGuid, NULL, (VOID **) &Td= Protocol); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D TdProtocol->MapPcrToMrIndex (TdProtocol, PcrIndex, &MrIndex); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + TdEvent =3D (EFI_TD_EVENT *) AllocateZeroPool (LogLen + sizeof (EFI_TD_E= VENT)); + if(TdEvent =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + TdEvent->Size =3D (UINT32) LogLen + sizeof (EFI_TD_EVENT) - sizeof (TdEv= ent->Event); + TdEvent->Header.HeaderSize =3D sizeof (EFI_TD_EVENT_HEADER); + TdEvent->Header.HeaderVersion =3D EFI_TD_EVENT_HEADER_VERSION; + TdEvent->Header.MrIndex =3D MrIndex; + TdEvent->Header.EventType =3D EventType; + CopyMem (&TdEvent->Event[0], EventLog, LogLen); + + Status =3D TdProtocol->HashLogExtendEvent ( + TdProtocol, + 0, + (EFI_PHYSICAL_ADDRESS) (UINTN) HashData, + HashDataLen, + TdEvent + ); + FreePool (TdEvent); + + return Status; +} + + /** Tpm measure and log data, and extend the measurement result into a speci= fic PCR. =20 @@ -178,9 +245,9 @@ TpmMeasureAndLogData ( EFI_STATUS Status; =20 // - // Try to measure using Tpm20 protocol + // Try to measure using Td protocol // - Status =3D Tpm20MeasureAndLogData( + Status =3D TdxMeasureAndLogData ( PcrIndex, EventType, EventLog, @@ -189,6 +256,20 @@ TpmMeasureAndLogData ( HashDataLen ); =20 + if (EFI_ERROR (Status)) { + // + // Try to measure using Tpm20 protocol + // + Status =3D Tpm20MeasureAndLogData( + PcrIndex, + EventType, + EventLog, + LogLen, + HashData, + HashDataLen + ); + } + if (EFI_ERROR (Status)) { // // Try to measure using Tpm1.2 protocol diff --git a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.= inf b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf index 7d41bc41f95d..b919771d5a9e 100644 --- a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf +++ b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf @@ -42,3 +42,4 @@ [Protocols] gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES gEfiTcg2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiTdProtocolGuid ## SOMETIMES_CONSUMES --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81652): https://edk2.groups.io/g/devel/message/81652 Mute This Topic: https://groups.io/mt/86163960/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-