From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com []) by mx.groups.io with SMTP id smtpd.web11.14454.1595407023959550656 for ; Wed, 22 Jul 2020 01:37:22 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: guomin.jiang@intel.com) IronPort-SDR: P2btp1yBpCHBjb7qTV2o+0i9/xj9+RP5JykygvScUWmYU/LMD1LS0yVwLBelttGCbBLYXhbAiH mEt0G66f4Cog== X-IronPort-AV: E=McAfee;i="6000,8403,9689"; a="211835225" X-IronPort-AV: E=Sophos;i="5.75,381,1589266800"; d="scan'208";a="211835225" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2020 01:37:22 -0700 IronPort-SDR: DCmZppmabw1r3BL5WTBIvfY95pzKN9R1Dh4B+iQb5Dc5F/LytlwlIs69Zwea/E4lDABYFP4hSH sy1Vmd49Jvvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,381,1589266800"; d="scan'208";a="462380304" Received: from guominji-mobl.ccr.corp.intel.com ([10.238.13.140]) by orsmga005.jf.intel.com with ESMTP; 22 Jul 2020 01:37:20 -0700 From: "Guomin Jiang" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Chao Zhang , Qi Zhang , Rahul Kumar , Zhang Subject: [PATCH v7 09/10] SecurityPkg/TcgPei: Use Migrated FV Info Hob for calculating hash (CVE-2019-11098) Date: Wed, 22 Jul 2020 16:36:56 +0800 Message-Id: <20200722083657.739-10-guomin.jiang@intel.com> X-Mailer: git-send-email 2.25.1.windows.1 In-Reply-To: <20200722083657.739-1-guomin.jiang@intel.com> References: <20200722083657.739-1-guomin.jiang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1614 When we allocate pool to save rebased the PEIMs, the address will change randomly, therefore the hash will change and result PCR0 change as well. To avoid this, we save the raw PEIMs and use it to calculate hash. The TcgPei calculate the hash and it use the Migrated FV Info. Cc: Jiewen Yao Cc: Jian J Wang Cc: Chao Zhang Cc: Qi Zhang Cc: Rahul Kumar Signed-off-by: Guomin Jiang Reviewed-by: Jian J Wang Reviewed-by: Zhang, Qi1 --- SecurityPkg/Tcg/TcgPei/TcgPei.inf | 1 + SecurityPkg/Tcg/TcgPei/TcgPei.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/SecurityPkg/Tcg/TcgPei/TcgPei.inf b/SecurityPkg/Tcg/TcgPei/TcgPei.inf index c0bff6e85e9d..6d1951f8ed65 100644 --- a/SecurityPkg/Tcg/TcgPei/TcgPei.inf +++ b/SecurityPkg/Tcg/TcgPei/TcgPei.inf @@ -58,6 +58,7 @@ [Guids] gTpmErrorHobGuid ## SOMETIMES_PRODUCES ## HOB gMeasuredFvHobGuid ## PRODUCES ## HOB gEfiTpmDeviceInstanceTpm12Guid ## PRODUCES ## GUID # TPM device identifier + gEdkiiMigratedFvInfoGuid ## SOMETIMES_CONSUMES ## HOB [Ppis] gPeiLockPhysicalPresencePpiGuid ## SOMETIMES_CONSUMES ## NOTIFY diff --git a/SecurityPkg/Tcg/TcgPei/TcgPei.c b/SecurityPkg/Tcg/TcgPei/TcgPei.c index a9a808c9ecf3..9701bfe8715b 100644 --- a/SecurityPkg/Tcg/TcgPei/TcgPei.c +++ b/SecurityPkg/Tcg/TcgPei/TcgPei.c @@ -21,6 +21,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include @@ -378,6 +379,10 @@ MeasureFvImage ( EFI_STATUS Status; EFI_PLATFORM_FIRMWARE_BLOB FvBlob; TCG_PCR_EVENT_HDR TcgEventHdr; + EFI_PHYSICAL_ADDRESS FvOrgBase; + EFI_PHYSICAL_ADDRESS FvDataBase; + EFI_PEI_HOB_POINTERS Hob; + EDKII_MIGRATED_FV_INFO *MigratedFvInfo; // // Check if it is in Excluded FV list @@ -401,10 +406,30 @@ MeasureFvImage ( } } + // + // Search the matched migration FV info + // + FvOrgBase = FvBase; + FvDataBase = FvBase; + Hob.Raw = GetFirstGuidHob (&gEdkiiMigratedFvInfoGuid); + while (Hob.Raw != NULL) { + MigratedFvInfo = GET_GUID_HOB_DATA (Hob); + if ((MigratedFvInfo->FvNewBase == (UINT32) FvBase) && (MigratedFvInfo->FvLength == (UINT32) FvLength)) { + // + // Found the migrated FV info + // + FvOrgBase = (EFI_PHYSICAL_ADDRESS) (UINTN) MigratedFvInfo->FvOrgBase; + FvDataBase = (EFI_PHYSICAL_ADDRESS) (UINTN) MigratedFvInfo->FvDataBase; + break; + } + Hob.Raw = GET_NEXT_HOB (Hob); + Hob.Raw = GetNextGuidHob (&gEdkiiMigratedFvInfoGuid, Hob.Raw); + } + // // Measure and record the FV to the TPM // - FvBlob.BlobBase = FvBase; + FvBlob.BlobBase = FvOrgBase; FvBlob.BlobLength = FvLength; DEBUG ((DEBUG_INFO, "The FV which is measured by TcgPei starts at: 0x%x\n", FvBlob.BlobBase)); @@ -416,7 +441,7 @@ MeasureFvImage ( Status = HashLogExtendEvent ( (EFI_PEI_SERVICES **) GetPeiServicesTablePointer(), - (UINT8*) (UINTN) FvBlob.BlobBase, + (UINT8*) (UINTN) FvDataBase, (UINTN) FvBlob.BlobLength, &TcgEventHdr, (UINT8*) &FvBlob -- 2.25.1.windows.1