From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (EUR02-HE1-obe.outbound.protection.outlook.com [40.107.1.40]) by mx.groups.io with SMTP id smtpd.web08.6980.1635846312819591560 for ; Tue, 02 Nov 2021 02:45:14 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=0ygd1kux; spf=pass (domain: arm.com, ip: 40.107.1.40, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z5neiW1NR4JZ9TNtpMMhnfNLKpaR6lDTIwcYgMAngvg=; b=0ygd1kuxFmaOzgrNbT3L3vqtjgr1fqriXbzfrwjB4RpwC34ss4dpntepMAnr2voGQAjFkElw4L2vKiHuPt22MsBnTeeVqucQ9PSJCKdTyzlDj/Y2PItPzAkXd2xjolf6SHbk+ZS7qv3sMsyatrWFZfg4f4X4gExoFLgdPtJLrjs= Received: from DB6PR0601CA0035.eurprd06.prod.outlook.com (2603:10a6:4:17::21) by AS8PR08MB6070.eurprd08.prod.outlook.com (2603:10a6:20b:290::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Tue, 2 Nov 2021 09:45:09 +0000 Received: from DB5EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:17:cafe::81) by DB6PR0601CA0035.outlook.office365.com (2603:10a6:4:17::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14 via Frontend Transport; Tue, 2 Nov 2021 09:45:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT033.mail.protection.outlook.com (10.152.20.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14 via Frontend Transport; Tue, 2 Nov 2021 09:45:08 +0000 Received: ("Tessian outbound d49ee2bec50d:v108"); Tue, 02 Nov 2021 09:45:08 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ac1cacfd97f4c19b X-CR-MTA-TID: 64aa7808 Received: from b9bb69fae7c3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CE6528ED-BE41-4E7F-B7D5-DE6239249101.1; Tue, 02 Nov 2021 09:45:02 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b9bb69fae7c3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 02 Nov 2021 09:45:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CAnVnCHwrSqqc/7KWsPE9Pr5U7CxqtTXlrHkqKUKoG2WeshIktdf3uy83b7lUu/TDMJ9067997rPWc0UmQwXQEO0Dn0tpCPj6pcf37IZGNe0HvSiH7EMoHt6SKkiflAf+B7deVzwf+TDqc8CC2E6x42JC5Yh1+FWlBZHGdNinn2nA+izUwmZZAyCJGT4VajZ9NXEHWvW1H2g33ajWTuW3ISK04qnE4Iiwyz+5UfFwvIrHARFhHKbAE1QEHwClAsU69qeB+X9Le7hwkE7Z8u4bxU99OJlJTTk9dEjzzqmutNBuNtE3HQ558YthdQVG+PoO3v0CQmxpGPewerm8JieQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z5neiW1NR4JZ9TNtpMMhnfNLKpaR6lDTIwcYgMAngvg=; b=cuA80N1Td8yde+LmPcNUzpV3MbIHO5eGlnCD+ge52j64hJxKVNmPGJi2CTJPKSk06/+SED/5t1RyAihK95RMBq0gKnA1EevFaeeqht5rP4xtyAPfX3TTOdBNbTOSBacAKphLfANIRleVeVI6sBqTtgexE+OZ6nq6RyzFwcGQBd+eVqWZPj6AjH5zgFj0e2tqO/ep8NWAvRF6s8kEP/zhLdRIoBT5AtBQxuyVUVgrcxWw9VrD5D0DWirvgX5vf7HiRJit0OovGlapRlf/68RdDv0M3Z35udVXIF3qBof8nNtE7SADqrMaaLBN8geV770MuhYOs4EUeZDjzXAT9oFyzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z5neiW1NR4JZ9TNtpMMhnfNLKpaR6lDTIwcYgMAngvg=; b=0ygd1kuxFmaOzgrNbT3L3vqtjgr1fqriXbzfrwjB4RpwC34ss4dpntepMAnr2voGQAjFkElw4L2vKiHuPt22MsBnTeeVqucQ9PSJCKdTyzlDj/Y2PItPzAkXd2xjolf6SHbk+ZS7qv3sMsyatrWFZfg4f4X4gExoFLgdPtJLrjs= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB6813.eurprd08.prod.outlook.com (2603:10a6:102:15f::10) by PAXPR08MB7004.eurprd08.prod.outlook.com (2603:10a6:102:203::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Tue, 2 Nov 2021 09:44:59 +0000 Received: from PAXPR08MB6813.eurprd08.prod.outlook.com ([fe80::c49a:d0cf:237d:7968]) by PAXPR08MB6813.eurprd08.prod.outlook.com ([fe80::c49a:d0cf:237d:7968%5]) with mapi id 15.20.4649.019; Tue, 2 Nov 2021 09:44:59 +0000 Subject: Re: [PATCH V4 3/3] SecurityPkg: Support CcMeasurementProtocol in DxeTpmMeasurementLib To: Min Xu , devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Gerd Hoffmann , nd References: <44a80d4605e02dcf5fed85c5669aedbff3a283a1.1635818903.git.min.m.xu@intel.com> From: "Sami Mujawar" Message-ID: <3f1ba671-cb5f-7849-9439-9af6326de84a@arm.com> Date: Tue, 2 Nov 2021 09:45:03 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 In-Reply-To: <44a80d4605e02dcf5fed85c5669aedbff3a283a1.1635818903.git.min.m.xu@intel.com> X-ClientProxiedBy: LNXP265CA0096.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:76::36) To PAXPR08MB6813.eurprd08.prod.outlook.com (2603:10a6:102:15f::10) MIME-Version: 1.0 Received: from [10.1.196.43] (217.140.106.52) by LNXP265CA0096.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:76::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.17 via Frontend Transport; Tue, 2 Nov 2021 09:44:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b228dca4-0cbf-4705-4c98-08d99de57538 X-MS-TrafficTypeDiagnostic: PAXPR08MB7004:|AS8PR08MB6070: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: S+D230sMQrRC0SWAOA/XnNfWi08hYJwoo09dL1OATBOGRv7zrrSiC9NyB/q4LqhAJJudu2q3ByK0oHuoYQVQn8K9327HkZD96rEBN4/GNuyoB+ULjZmAQM0/j78mFCpyTFJY3neRDJuN7yIY/GGJ9Ci/mYawL6qygVjwU694XmRC7NYbwz+lVkEOX4oEmnVELw9s29YdsaroKQcFnhcgJpx2mbTuVJzcelsdO7McvWdiZGfCUKxcnkoanSX62c5cEFHd4kvBCiTv35uHXxXNtlgJgPvP8GngqIN9uzauAs1woT9aROoUJzYTj+OBKlYlssmZM+wJ+NB/Wn+PeSxec2/6VDDIqWgZ8GsSMDdGznzFEaXuI3wGH85x7aQg0Dtn64Dn5weNFy0wdTmeV1Ykt92pfV7jjUWXg4ebwCo09mf+bGv8U5WKgWwNDFTsZUU0lArTQYJpaefahTT1KfBb9kJRc1GBwwkOgArAGrIbM0ZQEHecBmoYNpXTtKeQh3SVUXWOv5v2og1SYuCqYyiWNAI/HDw9wMu/oZTEy7eAyTz+weXe1vSLVv/lSya0/XctwwTWZlzuY7z0A/qMbpG1hFA92fx71XH6CMtuH/qzi2blueqofGtj1zpHbLyZCz65O2246ikw5MyCjs6Ag817hsbxm6Jm7oPVp57hBU4S4s1cTHLDkxrLdcykrKj6UdMtXxZwhc5h+xdT00BF8nJK3ATHGgi/s4knQD4nwxAFKw79Lbq50gQhJwmUwEub20qrVGNjbbgUlJZnWOopN2W5zdTpnDpK8T+vhDdOvxmLiXVhD/Dd7hM1m67kAOM/p+cKWoSXBrEzowC4T90Jvm7AoZb6GCTCfx1PoiVmCLOIm/Q= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR08MB6813.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(366004)(66556008)(66476007)(33964004)(956004)(44832011)(2616005)(38100700002)(8936002)(166002)(66946007)(6486002)(36756003)(30864003)(966005)(5660300002)(38350700002)(53546011)(52116002)(6666004)(83380400001)(8676002)(31686004)(316002)(31696002)(26005)(186003)(19627235002)(2906002)(4326008)(508600001)(15650500001)(86362001)(16576012)(54906003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7004 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: a9e6f385-7464-4d69-0f03-08d99de56f9e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OBFwKow1iAYDKgvGqcTcBGQO3VoypS0GvVCX61FIH//hfc5Eb9gDrYdalAgmi4S4kQhdQZEnwV5tdBLCR/Ib2Pk4Fp1m7MxEaRGnXRsLYVHfhpFSsb3GOoezuM5Nm4UxPbMHZIGJgx+Dh7eGhJOWzGFJQ9GcU9pYmFbMeV/8FSuv8gu29ZsLQBCkd6SbljIiIcNTaCmMLkevJRaL1tAyZ1tumtE1kU5bYhnqEXI/FIASZttV3k28bNaNyB8QQrKCA7kpSsGE99uqsTI/3/EhrGC+crIe93QyWU38jPBgoJhCHe/oPxUqewGde6rryZ7hxm7dA9/7YZr6ZTovicUA7DpRdau+nftyYsRg9y3H0L42ozGD8Nnau+JCD/+6eJxfsDy++UduC7riB9W71JFHELowW9rNI9ZswKvHzbZkFbe43+mlYGwI9qASs54NUJDpVGKI1zZ1PsXTQyNGHunUuVcKQtktpnqs0Gh7X3zc55PaXsfa+A/d+ewaGMDleMKhBuhBH+UpNP0Xn9EzDJhltnJcb7okfyPwUkN0URA8liIi2eFnYgZP5r3AHij4xL9GGPvpX6mZdK2PtRY6RLVWU7+uj1bjXZWToXNtTaLEDBxY6/qyWlvV2isJS7KF1jWX315+HgQ9tZGgqV2jGQ72n+qoGiUTcwmQD+qiaGjdEPThgTcds0MgNleEC0/hzirYIcUJH3jZu2797g5TRZ87Mus84jt4e2lyVN9COonHZUkX05iXu8hAxwkcYngadafVs8/Nv9pYl77JHraKkSEtIJQM+u4gAQLBMFp/fKO3l8k/6uRoYNCcvNa53W5TiRUJ X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(6029001)(4636009)(36840700001)(46966006)(54906003)(83380400001)(53546011)(956004)(15650500001)(26005)(16576012)(336012)(2616005)(356005)(966005)(6666004)(5660300002)(36860700001)(31686004)(33964004)(31696002)(8676002)(82310400003)(47076005)(19627235002)(81166007)(30864003)(6486002)(36756003)(166002)(8936002)(2906002)(86362001)(316002)(4326008)(44832011)(508600001)(70586007)(70206006)(186003)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2021 09:45:08.9221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b228dca4-0cbf-4705-4c98-08d99de57538 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6070 Content-Type: multipart/alternative; boundary="------------1AC9FDDCC444927053D9569D" Content-Language: en-GB --------------1AC9FDDCC444927053D9569D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Min, Thank you for this patch. Please find my feedback inline marked [SAMI]. Regards, Sami Mujawar On 02/11/2021 02:50 AM, Min Xu wrote: > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3625 > > 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 Confidential > + Computing (CC) measure registers. > > 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 > > #include > #include > - > - > +#include > > /** > Tpm12 measure and log data, and extend the measurement result into a specific PCR. > @@ -149,6 +149,73 @@ Tpm20MeasureAndLogData ( > return Status; > } > > +/** > + 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 referenced 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; [SAMI] Same comment as in patch 2/3. Is it possible to use the typedef for the measurment register index here, please? > + > + Status = gBS->LocateProtocol (&gEfiCcMeasurementProtocolGuid, NULL, (VOID **) &CcProtocol); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + Status = CcProtocol->MapPcrToMrIndex (CcProtocol, PcrIndex, &MrIndex); > + if (EFI_ERROR (Status)) { > + return EFI_INVALID_PARAMETER; [SAMI] Is it possible to return the error code returned by CcProtocol->MapPcrToMrIndex(), please? > + } > + > + EfiCcEvent = (EFI_CC_EVENT *) AllocateZeroPool (LogLen + sizeof (EFI_CC_EVENT)); > + if(EfiCcEvent == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + EfiCcEvent->Size = (UINT32) LogLen + sizeof (EFI_CC_EVENT) - sizeof (EfiCcEvent->Event); > + EfiCcEvent->Header.HeaderSize = sizeof (EFI_CC_EVENT_HEADER); > + EfiCcEvent->Header.HeaderVersion = EFI_CC_EVENT_HEADER_VERSION; > + EfiCcEvent->Header.MrIndex = MrIndex; > + EfiCcEvent->Header.EventType = EventType; > + CopyMem (&EfiCcEvent->Event[0], EventLog, LogLen); > + > + Status = 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 specific PCR. > > @@ -178,9 +245,9 @@ TpmMeasureAndLogData ( > EFI_STATUS Status; > > // > - // Try to measure using Tpm20 protocol > + // Try to measure using Cc measurement protocol > // > - Status = Tpm20MeasureAndLogData( > + Status = CcMeasureAndLogData ( > PcrIndex, > EventType, > EventLog, > @@ -189,6 +256,20 @@ TpmMeasureAndLogData ( > HashDataLen > ); > > + if (EFI_ERROR (Status)) { > + // > + // Try to measure using Tpm20 protocol > + // > + Status = Tpm20MeasureAndLogData( > + PcrIndex, > + EventType, > + EventLog, > + LogLen, > + HashData, > + HashDataLen > + ); > + } [SAMI] Apologies, I missed this in my previous review. I think the behaviour if both the TCG2 and CC measurement protocols are installed would be inconsistent between DxeTpmMeasurementLib and DxeTpm2MeasureBootLib. The main difference being in the later, the TCG2 protocol takes precedence for extending the measurement. I think it would be good to modify DxeTpm2MeasureBootLib so that the CC measurement protocol is used if both protocols are installed. What do you think? There is another subtle difference in this patch. Consider the case where LocateProtocol(gEfiCcMeasurementProtocolGuid, ... ) succeeds but subsequently MapPcrToMrIndex() or HashLogExtendEvent() fail then Tpm20MeasureAndLogData() will be called. This is not the case with DxeTpm2MeasureBootLib. I think it would be good to have a consistent behaviour. [/SAMI] > + > 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, and > # extend the measurement result into a specific PCR. > @@ -40,5 +42,6 @@ > UefiBootServicesTableLib > > [Protocols] > - gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES > - gEfiTcg2ProtocolGuid ## SOMETIMES_CONSUMES > + gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES > + gEfiTcg2ProtocolGuid ## SOMETIMES_CONSUMES > + gEfiCcMeasurementProtocolGuid ## SOMETIMES_CONSUMES --------------1AC9FDDCC444927053D9569D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Min,

Thank you for this patch.

Please find my feedback inline marked [SAMI].

Regards,

Sami Mujawar


On 02/11/2021 02:50 AM, Min Xu wrote:
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3625

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 <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
 .../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 Confidential
+  Computing (CC) measure registers.
 
 Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved. <BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -19,8 +20,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <Guid/Acpi.h>
 #include <IndustryStandard/Acpi.h>
-
-
+#include <Protocol/CcMeasurement.h>
 
 /**
   Tpm12 measure and log data, and extend the measurement result into a specific PCR.
@@ -149,6 +149,73 @@ Tpm20MeasureAndLogData (
   return Status;
 }
 
+/**
+  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 referenced 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;
[SAMI] Same comment as in patch 2/3. Is it possible to use the typedef for the measurment register index here, please?
+
+  Status = gBS->LocateProtocol (&gEfiCcMeasurementProtocolGuid, NULL, (VOID **) &CcProtocol);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = CcProtocol->MapPcrToMrIndex (CcProtocol, PcrIndex, &MrIndex);
+  if (EFI_ERROR (Status)) {
+    return EFI_INVALID_PARAMETER;
[SAMI] Is it possible to return the error code returned by  CcProtocol->MapPcrToMrIndex(), please?
+  }
+
+  EfiCcEvent = (EFI_CC_EVENT *) AllocateZeroPool (LogLen + sizeof (EFI_CC_EVENT));
+  if(EfiCcEvent == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  EfiCcEvent->Size = (UINT32) LogLen + sizeof (EFI_CC_EVENT) - sizeof (EfiCcEvent->Event);
+  EfiCcEvent->Header.HeaderSize    = sizeof (EFI_CC_EVENT_HEADER);
+  EfiCcEvent->Header.HeaderVersion = EFI_CC_EVENT_HEADER_VERSION;
+  EfiCcEvent->Header.MrIndex       = MrIndex;
+  EfiCcEvent->Header.EventType     = EventType;
+  CopyMem (&EfiCcEvent->Event[0], EventLog, LogLen);
+
+  Status = 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 specific PCR.
 
@@ -178,9 +245,9 @@ TpmMeasureAndLogData (
   EFI_STATUS  Status;
 
   //
-  // Try to measure using Tpm20 protocol
+  // Try to measure using Cc measurement protocol
   //
-  Status = Tpm20MeasureAndLogData(
+  Status = CcMeasureAndLogData (
              PcrIndex,
              EventType,
              EventLog,
@@ -189,6 +256,20 @@ TpmMeasureAndLogData (
              HashDataLen
              );
 
+  if (EFI_ERROR (Status)) {
+    //
+    // Try to measure using Tpm20 protocol
+    //
+    Status = Tpm20MeasureAndLogData(
+               PcrIndex,
+               EventType,
+               EventLog,
+               LogLen,
+               HashData,
+               HashDataLen
+               );
+  }
[SAMI] Apologies, I missed this in my previous review. I think the behaviour if both the TCG2 and CC measurement protocols are installed
would be inconsistent between DxeTpmMeasurementLib and DxeTpm2MeasureBootLib. The main difference being in the later, the
TCG2 protocol takes precedence for extending the measurement.
I think it would be good to modify DxeTpm2MeasureBootLib so that the CC measurement protocol is used if both protocols are installed. What do you think?

There is another subtle difference in this patch. Consider the case where LocateProtocol(gEfiCcMeasurementProtocolGuid, ... ) succeeds but subsequently
MapPcrToMrIndex() or HashLogExtendEvent() fail then Tpm20MeasureAndLogData() will be called. This is not the case with DxeTpm2MeasureBootLib.
I think it would be good to have a consistent behaviour.
 [/SAMI]
+
   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, and
 #  extend the measurement result into a specific PCR.
@@ -40,5 +42,6 @@
   UefiBootServicesTableLib
 
 [Protocols]
-  gEfiTcgProtocolGuid           ## SOMETIMES_CONSUMES
-  gEfiTcg2ProtocolGuid          ## SOMETIMES_CONSUMES
+  gEfiTcgProtocolGuid               ## SOMETIMES_CONSUMES
+  gEfiTcg2ProtocolGuid              ## SOMETIMES_CONSUMES
+  gEfiCcMeasurementProtocolGuid     ## SOMETIMES_CONSUMES

--------------1AC9FDDCC444927053D9569D--