From nobody Tue Dec 24 13:45:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511839601430421.3882092130782; Mon, 27 Nov 2017 19:26:41 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9C0392034A771; Mon, 27 Nov 2017 19:22:17 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 08EB62034A763 for ; Mon, 27 Nov 2017 19:22:15 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2017 19:26:37 -0800 Received: from shwde7172.ccr.corp.intel.com ([10.239.9.15]) by orsmga002.jf.intel.com with ESMTP; 27 Nov 2017 19:26:36 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,466,1505804400"; d="scan'208";a="12732493" From: Liming Gao To: edk2-devel@lists.01.org Date: Tue, 28 Nov 2017 11:26:34 +0800 Message-Id: <1511839594-6220-1-git-send-email-liming.gao@intel.com> X-Mailer: git-send-email 2.8.0.windows.1 Subject: [edk2] [Patch] SignedCapsulePkg: Update EdkiiSystemCapsuleLib to check PCD value X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If PCD value is not set, register PcdCallBack to hook PCD value set Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Jiewen Yao --- .../EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c | 86 ++++++++++++++++++= +++- .../EdkiiSystemCapsuleLib.inf | 3 + 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCaps= uleLib.c b/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsul= eLib.c index 62be8eb..876d225 100644 --- a/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c +++ b/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -600,6 +601,10 @@ CapsuleAuthenticateSystemFirmware ( // NOTE: This function need run in an isolated environment. // Do not touch FMP protocol and its private structure. // + if (mImageFmpInfo =3D=3D NULL) { + DEBUG((DEBUG_INFO, "ImageFmpInfo is not set\n")); + return EFI_SECURITY_VIOLATION; + } =20 Result =3D ExtractAuthenticatedImage((VOID *)Image, ImageSize, LastAttem= ptStatus, AuthenticatedImage, AuthenticatedImageSize); if (!Result) { @@ -655,6 +660,53 @@ CapsuleAuthenticateSystemFirmware ( } =20 /** + PcdCallBack gets the real set PCD value + + @param[in] CallBackGuid The PCD token GUID being set. + @param[in] CallBackToken The PCD token number being set. + @param[in, out] TokenData A pointer to the token data being set. + @param[in] TokenDataSize The size, in bytes, of the data being se= t. + +**/ +VOID +EFIAPI +EdkiiSystemCapsuleLibPcdCallBack ( + IN CONST GUID *CallBackGuid, OPTIONAL + IN UINTN CallBackToken, + IN OUT VOID *TokenData, + IN UINTN TokenDataSize + ) +{ + if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) && + CallBackToken =3D=3D PcdToken (PcdEdkiiSystemFirmwareImageDescriptor= )) { + mImageFmpInfoSize =3D TokenDataSize; + mImageFmpInfo =3D AllocateCopyPool (mImageFmpInfoSize, TokenData); + ASSERT(mImageFmpInfo !=3D NULL); + // + // Cancel Callback after get the real set value + // + LibPcdCancelCallback ( + &gEfiSignedCapsulePkgTokenSpaceGuid, + PcdToken (PcdEdkiiSystemFirmwareImageDescriptor), + EdkiiSystemCapsuleLibPcdCallBack + ); + } + + if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) && + CallBackToken =3D=3D PcdToken (PcdEdkiiSystemFirmwareFileGuid)) { + CopyGuid(&mEdkiiSystemFirmwareFileGuid, TokenData); + // + // Cancel Callback after get the real set value + // + LibPcdCancelCallback ( + &gEfiSignedCapsulePkgTokenSpaceGuid, + PcdToken (PcdEdkiiSystemFirmwareFileGuid), + EdkiiSystemCapsuleLibPcdCallBack + ); + } +} + +/** The constructor function. =20 @retval EFI_SUCCESS The constructor successfully . @@ -666,8 +718,38 @@ EdkiiSystemCapsuleLibConstructor ( ) { mImageFmpInfoSize =3D PcdGetSize(PcdEdkiiSystemFirmwareImageDescriptor); - mImageFmpInfo =3D AllocateCopyPool (mImageFmpInfoSize, PcdGetPtr(PcdEdki= iSystemFirmwareImageDescriptor)); - ASSERT(mImageFmpInfo !=3D NULL); + mImageFmpInfo =3D PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor); + // + // Verify Firmware Image Descriptor first + // + if (mImageFmpInfoSize < sizeof (EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR) = || + mImageFmpInfo->Signature !=3D EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR= _SIGNATURE) { + // + // SystemFirmwareImageDescriptor is not set. + // Register PCD set callback to hook PCD value set. + // + mImageFmpInfo =3D NULL; + mImageFmpInfoSize =3D 0; + LibPcdCallbackOnSet ( + &gEfiSignedCapsulePkgTokenSpaceGuid, + PcdToken (PcdEdkiiSystemFirmwareImageDescriptor), + EdkiiSystemCapsuleLibPcdCallBack + ); + } else { + mImageFmpInfo =3D AllocateCopyPool (mImageFmpInfoSize, mImageFmpInfo); + ASSERT(mImageFmpInfo !=3D NULL); + } + CopyGuid(&mEdkiiSystemFirmwareFileGuid, PcdGetPtr(PcdEdkiiSystemFirmware= FileGuid)); + // + // Verify GUID value first + // + if (CompareGuid (&mEdkiiSystemFirmwareFileGuid, &gZeroGuid)) { + LibPcdCallbackOnSet ( + &gEfiSignedCapsulePkgTokenSpaceGuid, + PcdToken (PcdEdkiiSystemFirmwareFileGuid), + EdkiiSystemCapsuleLibPcdCallBack + ); + } return EFI_SUCCESS; } diff --git a/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCaps= uleLib.inf b/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCaps= uleLib.inf index a21e75c..a721619 100644 --- a/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.= inf +++ b/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.= inf @@ -43,6 +43,7 @@ BaseLib BaseMemoryLib DebugLib + PcdLib MemoryAllocationLib FmpAuthenticationLib =20 @@ -58,4 +59,6 @@ gEdkiiSystemFmpCapsuleDriverFvFileGuid ## SOMETIMES_CONSUM= ES ## GUID gEfiCertPkcs7Guid ## SOMETIMES_CONSUM= ES ## GUID gEfiCertTypeRsa2048Sha256Guid ## SOMETIMES_CONSUM= ES ## GUID + gEfiSignedCapsulePkgTokenSpaceGuid ## SOMETIMES_CONSUM= ES ## GUID + gZeroGuid ## SOMETIMES_CONSUM= ES ## GUID =20 --=20 2.8.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel