From nobody Mon Feb 9 07:43:49 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+83086+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+83086+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1635821540; cv=none; d=zohomail.com; s=zohoarc; b=RKd4IgWWPR9daxOFVQK+VlUig89lLvq2m9TId/7hVfMX3OMQ/5LLrbMux6aY6QGs0k/WsUpevCaQDMg4l5aSsEYeySkts/E3cmuVEq2L5M48IH3MyQaEzjV2CDwoWocSgCFC+UZQjY5PeFlIYB34mMWzlwy3lzmyKcNQkVs6r5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635821540; 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=yF9zQLdO1Qdhcuwfanzum4b5rz1ji9SxGuuX3RSjmgI=; b=m25A7fCFRbZAf8Pda+sop24CRFV183JeGsriaEVNBsq7rSDi+AzIYwHUyRerGoS/l0EI/Efxshy5ENbC6vq/f2hZEd3gJLfUYHe5BJOBKA4T39QeRIx3cRVdyqdi3ZHCfFfyItcjBR9dFpQrsmwYLUCoRRx7S/xI1aykMq9VRm0= 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+83086+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 1635821540473923.3636438740164; Mon, 1 Nov 2021 19:52:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gzk0YY1788612xcCL5HeGKyP; Mon, 01 Nov 2021 19:52:20 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.4382.1635821537612298890 for ; Mon, 01 Nov 2021 19:52:19 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10155"; a="254777778" X-IronPort-AV: E=Sophos;i="5.87,201,1631602800"; d="scan'208";a="254777778" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2021 19:52:07 -0700 X-IronPort-AV: E=Sophos;i="5.87,201,1631602800"; d="scan'208";a="500318813" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.238.4.37]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2021 19:52:05 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH V4 3/3] SecurityPkg: Support CcMeasurementProtocol in DxeTpmMeasurementLib Date: Tue, 2 Nov 2021 10:50:53 +0800 Message-Id: <44a80d4605e02dcf5fed85c5669aedbff3a283a1.1635818903.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: jeLLEV5BWkBvSWdeDKK256qHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1635821540; bh=L/0O5vMM7gZ7hQ0eb0L3jksEuJawkLe5lIrchwh4HoY=; h=Cc:Date:From:Reply-To:Subject:To; b=TGErbF/fNhnUZZukP5MRbjCTq4eI2p4FjrlkoVlwUC1OtTMUhJQrWZ4UGCqbT5+tPWf B6yLqI6giH2Cvpe/r2L3xQUojWv3rFcsDIALYhDFciXShL91Iz+ILrsJCh+ffSVwMnNJz DdeN23hLaAZlOtNucuySrC87P0BkUhW4zHs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1635821541693100005 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 CcMeasurementProtocol is introduced, CC based measurement needs to be supported in DxeTpmMeasurementLib as well. In TpmMeasureAndLogData, CC based measurement will be first called. If it failed, TPM based measurement will be called sequentially. Currently there is an assumption that CC 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 Cc: Sami Mujawar Cc: Gerd Hoffmann Signed-off-by: Min Xu --- .../DxeTpmMeasurementLib.c | 91 ++++++++++++++++++- .../DxeTpmMeasurementLib.inf | 9 +- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.= c b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c index 061136ee7860..2ddb9033a0d5 100644 --- a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c +++ b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c @@ -1,5 +1,6 @@ /** @file - This library is used by other modules to measure data to TPM. + This library is used by other modules to measure data to TPM and Confide= ntial + Computing (CC) measure registers. =20 Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -19,8 +20,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include - - +#include =20 /** Tpm12 measure and log data, and extend the measurement result into a spe= cific PCR. @@ -149,6 +149,73 @@ Tpm20MeasureAndLogData ( return Status; } =20 +/** + Cc measure and log data, and extend the measurement result into a + specific CC MR. + + @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 +CcMeasureAndLogData ( + IN UINT32 PcrIndex, + IN UINT32 EventType, + IN VOID *EventLog, + IN UINT32 LogLen, + IN VOID *HashData, + IN UINT64 HashDataLen + ) +{ + EFI_STATUS Status; + EFI_CC_MEASUREMENT_PROTOCOL *CcProtocol; + EFI_CC_EVENT *EfiCcEvent; + UINT32 MrIndex; + + Status =3D gBS->LocateProtocol (&gEfiCcMeasurementProtocolGuid, NULL, (V= OID **) &CcProtocol); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D CcProtocol->MapPcrToMrIndex (CcProtocol, PcrIndex, &MrIndex); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + EfiCcEvent =3D (EFI_CC_EVENT *) AllocateZeroPool (LogLen + sizeof (EFI_C= C_EVENT)); + if(EfiCcEvent =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + EfiCcEvent->Size =3D (UINT32) LogLen + sizeof (EFI_CC_EVENT) - sizeof (E= fiCcEvent->Event); + EfiCcEvent->Header.HeaderSize =3D sizeof (EFI_CC_EVENT_HEADER); + EfiCcEvent->Header.HeaderVersion =3D EFI_CC_EVENT_HEADER_VERSION; + EfiCcEvent->Header.MrIndex =3D MrIndex; + EfiCcEvent->Header.EventType =3D EventType; + CopyMem (&EfiCcEvent->Event[0], EventLog, LogLen); + + Status =3D CcProtocol->HashLogExtendEvent ( + CcProtocol, + 0, + (EFI_PHYSICAL_ADDRESS) (UINTN) HashData, + HashDataLen, + EfiCcEvent + ); + FreePool (EfiCcEvent); + + 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 Cc measurement protocol // - Status =3D Tpm20MeasureAndLogData( + Status =3D CcMeasureAndLogData ( 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..3af3d4e33b25 100644 --- a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf +++ b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf @@ -1,5 +1,7 @@ ## @file -# Provides TPM measurement functions for TPM1.2 and TPM 2.0 +# Provides below measurement functions: +# 1. TPM measurement functions for TPM1.2 and TPM 2.0 +# 2. Confidential Computing (CC) measurement functions # # This library provides TpmMeasureAndLogData() to measure and log data, a= nd # extend the measurement result into a specific PCR. @@ -40,5 +42,6 @@ UefiBootServicesTableLib =20 [Protocols] - gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES - gEfiTcg2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES + gEfiTcg2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiCcMeasurementProtocolGuid ## 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 (#83086): https://edk2.groups.io/g/devel/message/83086 Mute This Topic: https://groups.io/mt/86758672/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-