From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53867+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53867+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998777325396.67781970598014; Thu, 6 Feb 2020 06:19:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kxKcYY1788612x6UBc2MO8bl; Thu, 06 Feb 2020 06:19:36 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:36 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160662" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:35 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang Subject: [edk2-devel] [PATCH 1/9] SecurityPkg/DxeImageVerificationLib: Fix memory leaks(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:25 +0800 Message-Id: <20200206141933.356-2-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: HsjdtMXFNxXIAOx5BiSulWLJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998776; bh=9WnF6YE/G6ZLkhyzY08qOY5ltiDdhQyqANXd4pnuvu0=; h=Cc:Date:From:Reply-To:Subject:To; b=qzpBoDc+ALmc361Ulu2dSQrA1Dez6xqjkw23vNfzz7qiBX22imtz8DY0x57NfZa9Rhn gtxH8fMRjStkyUeRv4WRsrjaPqYsKy3imEXi1m1Eft2eghjvQPTLNFvnTQMbWMx6zzawZ gGK4b0f0iIr+4knBzQKlDvOeJWoAeB4td6U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 Pointer HashCtx used in IsCertHashFoundInDatabase() is not freed inside the while-loop, if it will run more than once. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Reviewed-by: Jiewen Yao Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index dbfbfcb4fb..74dbffa122 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -908,6 +908,9 @@ IsCertHashFoundInDatabase ( goto Done; } =20 + FreePool (HashCtx); + HashCtx =3D NULL; + SiglistHeaderSize =3D sizeof (EFI_SIGNATURE_LIST) + DbxList->Signature= HeaderSize; CertHash =3D (EFI_SIGNATURE_DATA *) ((UINT8 *) DbxList + Sigl= istHeaderSize); CertHashCount =3D (DbxList->SignatureListSize - SiglistHeaderSize)= / DbxList->SignatureSize; --=20 2.24.0.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 (#53867): https://edk2.groups.io/g/devel/message/53867 Mute This Topic: https://groups.io/mt/71023417/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53868+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53868+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998778298885.7024843717884; Thu, 6 Feb 2020 06:19:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Fbc8YY1788612xBRNhHp2mrZ; Thu, 06 Feb 2020 06:19:37 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:37 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160666" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:35 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang , Laszlo Ersek Subject: [edk2-devel] [PATCH 2/9] SecurityPkg/DxeImageVerificationLib: reject CertStack.CertNumber==0 per DBX(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:26 +0800 Message-Id: <20200206141933.356-3-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: ljjaMv60u6iojvjHlrzqx93xx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998777; bh=ceLtPIVrDoPfyfy/My+uCR/0PxT/crw6sxxN38zv57Q=; h=Cc:Date:From:Reply-To:Subject:To; b=sPsVmfgKjaKyrIMC9095xKQfK9h8VKmqkt3mM/+LnMmpD0ayLa1X7G6tZJJNIu6FN2S 35XgFl3cpEnaLwcUQxrz0GcbAFC8lum+CRcLYruUCf4dUGE6gjLRhrzp2PXJWZXgyHpqY aZmsGx53uRo/p99PC6JjQ4UiNqtuCuxFgf8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In case the signers' certificate stack, retrieved from the PE/COFF image's Authenticode blob, has zero elements (=3D there are zero signer certificate= s), then we should consider the image forbidden by DBX, not accepted by DBX. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Reviewed-by: Laszlo Ersek Reviewed-by: Jiewen Yao --- .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index 74dbffa122..5dcd6efed5 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1326,7 +1326,7 @@ IsForbiddenByDbx ( // UINT8 Certn[]; // Pkcs7GetSigners (AuthData, AuthDataSize, &CertBuffer, &BufferLength, &Tr= ustedCert, &TrustedCertLength); - if ((BufferLength =3D=3D 0) || (CertBuffer =3D=3D NULL)) { + if ((BufferLength =3D=3D 0) || (CertBuffer =3D=3D NULL) || (*CertBuffer)= =3D=3D 0) { IsForbidden =3D TRUE; goto Done; } --=20 2.24.0.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 (#53868): https://edk2.groups.io/g/devel/message/53868 Mute This Topic: https://groups.io/mt/71023418/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53869+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53869+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998778792818.1428696140101; Thu, 6 Feb 2020 06:19:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id c6POYY1788612xEyu2RmiJeS; Thu, 06 Feb 2020 06:19:38 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:38 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160672" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:36 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang Subject: [edk2-devel] [PATCH 3/9] SecurityPkg/DxeImageVerificationLib: fix wrong fetching dbx in IsAllowedByDb(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:27 +0800 Message-Id: <20200206141933.356-4-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: 6xuHvlZ1z2ziHSWsJ7VkcuSkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998778; bh=3Gye1IeWG8BBdVoS+4vs/st4HhLi3IfKm0MlrlrMRp0=; h=Cc:Date:From:Reply-To:Subject:To; b=SoVTxd5iQV4uyvP+Q/59pgC/Rpdc5JVAx65XrlX3Tr1oc5UUI2cHFZ6TX25U2qE9eMa 6nQ3NnPcHIwn/afmbT/m8ITGDMBWdXqHs/1slTBrV1WDoOu9mFjJcaaPhi2uv4jg6DPSL ZoizQ9wYXOmuBJvzcXn7HjbzBBpfh0oH2P8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 Normally two times of calling gRT->GetVariable() are needed to get the data of a variable: get the variable size by passing zero variable size, and then allocate enough memory and pass the correct variable size and buffer. But in the inner loop in IsAllowedByDb(), the DbxDataSize was not initialized to zero before calling gRT->GetVariable(). It won't cause problem if dbx does not exist. But it will give wrong result if dbx exists and the DbxDataSize happens to be a small enough value. In this situation, EFI_BUFFER_TOO_SMALL will be returned. Then the result check code followed will jump to 'Done', which is not correct because it's actually the value expected. if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { goto Done; } Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Reviewed-by: Jiewen Yao --- .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index 5dcd6efed5..1efb2f96cd 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1456,8 +1456,9 @@ IsAllowedByDb ( // // Here We still need to check if this RootCert's Hash is revo= ked // + DbxDataSize =3D 0; Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &= gEfiImageSecurityDatabaseGuid, NULL, &DbxDataSize, NULL); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { + if (Status !=3D EFI_BUFFER_TOO_SMALL) { goto Done; } DbxData =3D (UINT8 *) AllocateZeroPool (DbxDataSize); --=20 2.24.0.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 (#53869): https://edk2.groups.io/g/devel/message/53869 Mute This Topic: https://groups.io/mt/71023420/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53870+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53870+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998780113620.4921556484414; Thu, 6 Feb 2020 06:19:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id YnKrYY1788612xrKCwh4EJQY; Thu, 06 Feb 2020 06:19:39 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:38 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160679" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:37 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang Subject: [edk2-devel] [PATCH 4/9] SecurityPkg/DxeImageVerificationLib: avoid bypass in fetching dbx in IsAllowedByDb(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:28 +0800 Message-Id: <20200206141933.356-5-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: 1DdEaCNK9QJXREVz5X68CzPux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998779; bh=AEJ1vhnMjuxRXW8uLZpv54GtlfSoD6+IWBYfLl10x7U=; h=Cc:Date:From:Reply-To:Subject:To; b=t/Dx4zH2UgGMTy1s2Xxe0x3QMGK6Omp1g1Ti3DJpIE30KNOWFxAecgNerwQabTTN+2q YLz3mFPxemR0SBNwF8G6PqOT3ePnkmc1TPdOi1cq7mm3GVTvHlYvseU6upLS5YDyaT0tO 3ksFekckg9G9aFH86b75d+JtdtHVl7Rkruo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 In timestamp check after the cert is found in db, the original code jumps to 'Done' if any error happens in fetching dbx variable. At any of the jump, VerifyStatus equals to TRUE, which means allowed-by-db. This should not be allowed except to EFI_NOT_FOUND case (meaning dbx doesn't exist), because it could be used to bypass timestamp check. This patch add code to change VerifyStatus to FALSE in the case of memory allocation failure and dbx fetching failure to avoid potential bypass issue. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Reviewed-by: Jiewen Yao --- .../DxeImageVerificationLib/DxeImageVerificationLib.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index 1efb2f96cd..ed5dbf26b0 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1459,15 +1459,26 @@ IsAllowedByDb ( DbxDataSize =3D 0; Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &= gEfiImageSecurityDatabaseGuid, NULL, &DbxDataSize, NULL); if (Status !=3D EFI_BUFFER_TOO_SMALL) { + if (Status !=3D EFI_NOT_FOUND) { + VerifyStatus =3D FALSE; + } goto Done; } DbxData =3D (UINT8 *) AllocateZeroPool (DbxDataSize); if (DbxData =3D=3D NULL) { + // + // Force not-allowed-by-db to avoid bypass + // + VerifyStatus =3D FALSE; goto Done; } =20 Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &gE= fiImageSecurityDatabaseGuid, NULL, &DbxDataSize, (VOID *) DbxData); if (EFI_ERROR (Status)) { + // + // Force not-allowed-by-db to avoid bypass + // + VerifyStatus =3D FALSE; goto Done; } =20 --=20 2.24.0.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 (#53870): https://edk2.groups.io/g/devel/message/53870 Mute This Topic: https://groups.io/mt/71023421/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53871+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53871+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15809987807122.6278887804064652; Thu, 6 Feb 2020 06:19:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id p3WbYY1788612xc1wbr9KNmq; Thu, 06 Feb 2020 06:19:40 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:39 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160683" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:38 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang Subject: [edk2-devel] [PATCH 5/9] SecurityPkg/DxeImageVerificationLib: refactor db/dbx fetching code in IsAllowedByDb(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:29 +0800 Message-Id: <20200206141933.356-6-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: 2H1WpTof5vEWKHTAlvYizbiBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998780; bh=zCYF4MO9kY8FQ1L80B7+LtMFPk6nTFfivYQvmVs+pWA=; h=Cc:Date:From:Reply-To:Subject:To; b=q0Ne9XL6P2hQ1zP1F00eSidoPS4V7S6ErsZ5Y9mSGXwKwY/KeOC68EsLEwJi8SdZX3u 4n5dA0NPfaqku8HozPqQikw9erE3DwXEkbPTjKMJFZFnBPqs/7fVXrY1s+aeV4DmEnR2R 42Jy5K5oORB6s6s5Qa4YhSFYw9m0azvVB6o= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 The dbx fetching code inside the while/for-loop causes code hard to understand. Since there's no need to get dbx more than once, this patch simplify the code logic by moving related code to be outside the while- loop. db fetching code is also refined accordingly to reduce the indent level of code. More comments are also added or refined to explain more details. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Reviewed-by: Jiewen Yao --- .../DxeImageVerificationLib.c | 144 ++++++++++-------- 1 file changed, 83 insertions(+), 61 deletions(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index ed5dbf26b0..8739d1fa29 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1412,76 +1412,92 @@ IsAllowedByDb ( RootCertSize =3D 0; VerifyStatus =3D FALSE; =20 + // + // Fetch 'db' content. If 'db' doesn't exist or encounters problem to ge= t the + // data, return not-allowed-by-db (FALSE). + // DataSize =3D 0; Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSe= curityDatabaseGuid, NULL, &DataSize, NULL); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - Data =3D (UINT8 *) AllocateZeroPool (DataSize); - if (Data =3D=3D NULL) { - return VerifyStatus; + ASSERT (EFI_ERROR (Status)); + if (Status !=3D EFI_BUFFER_TOO_SMALL) { + return VerifyStatus; + } + + Data =3D (UINT8 *) AllocateZeroPool (DataSize); + if (Data =3D=3D NULL) { + return VerifyStatus; + } + + Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecu= rityDatabaseGuid, NULL, &DataSize, (VOID *) Data); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Fetch 'dbx' content. If 'dbx' doesn't exist, continue to check 'db'. + // If any other errors occured, no need to check 'db' but just return + // not-allowed-by-db (FALSE) to avoid bypass. + // + DbxDataSize =3D 0; + Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &gEfiIma= geSecurityDatabaseGuid, NULL, &DbxDataSize, NULL); + ASSERT (EFI_ERROR (Status)); + if (Status !=3D EFI_BUFFER_TOO_SMALL) { + if (Status !=3D EFI_NOT_FOUND) { + goto Done; + } + // + // 'dbx' does not exist. Continue to check 'db'. + // + } else { + // + // 'dbx' exists. Get its content. + // + DbxData =3D (UINT8 *) AllocateZeroPool (DbxDataSize); + if (DbxData =3D=3D NULL) { + goto Done; } =20 - Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSe= curityDatabaseGuid, NULL, &DataSize, (VOID *) Data); + Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageS= ecurityDatabaseGuid, NULL, &DbxDataSize, (VOID *) DbxData); if (EFI_ERROR (Status)) { goto Done; } + } =20 - // - // Find X509 certificate in Signature List to verify the signature in = pkcs7 signed data. - // - CertList =3D (EFI_SIGNATURE_LIST *) Data; - while ((DataSize > 0) && (DataSize >=3D CertList->SignatureListSize)) { - if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) { - CertData =3D (EFI_SIGNATURE_DATA *) ((UINT8 *) CertList + sizeof = (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize); - CertCount =3D (CertList->SignatureListSize - sizeof (EFI_SIGNATURE= _LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize; + // + // Find X509 certificate in Signature List to verify the signature in pk= cs7 signed data. + // + CertList =3D (EFI_SIGNATURE_LIST *) Data; + while ((DataSize > 0) && (DataSize >=3D CertList->SignatureListSize)) { + if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) { + CertData =3D (EFI_SIGNATURE_DATA *) ((UINT8 *) CertList + sizeof (E= FI_SIGNATURE_LIST) + CertList->SignatureHeaderSize); + CertCount =3D (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_L= IST) - CertList->SignatureHeaderSize) / CertList->SignatureSize; =20 - for (Index =3D 0; Index < CertCount; Index++) { - // - // Iterate each Signature Data Node within this CertList for ver= ify. - // - RootCert =3D CertData->SignatureData; - RootCertSize =3D CertList->SignatureSize - sizeof (EFI_GUID); + for (Index =3D 0; Index < CertCount; Index++) { + // + // Iterate each Signature Data Node within this CertList for verif= y. + // + RootCert =3D CertData->SignatureData; + RootCertSize =3D CertList->SignatureSize - sizeof (EFI_GUID); =20 + // + // Call AuthenticodeVerify library to Verify Authenticode struct. + // + VerifyStatus =3D AuthenticodeVerify ( + AuthData, + AuthDataSize, + RootCert, + RootCertSize, + mImageDigest, + mImageDigestSize + ); + if (VerifyStatus) { // - // Call AuthenticodeVerify library to Verify Authenticode struct. + // The image is signed and its signature is found in 'db'. // - VerifyStatus =3D AuthenticodeVerify ( - AuthData, - AuthDataSize, - RootCert, - RootCertSize, - mImageDigest, - mImageDigestSize - ); - if (VerifyStatus) { + if (DbxData !=3D NULL) { // // Here We still need to check if this RootCert's Hash is revo= ked // - DbxDataSize =3D 0; - Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &= gEfiImageSecurityDatabaseGuid, NULL, &DbxDataSize, NULL); - if (Status !=3D EFI_BUFFER_TOO_SMALL) { - if (Status !=3D EFI_NOT_FOUND) { - VerifyStatus =3D FALSE; - } - goto Done; - } - DbxData =3D (UINT8 *) AllocateZeroPool (DbxDataSize); - if (DbxData =3D=3D NULL) { - // - // Force not-allowed-by-db to avoid bypass - // - VerifyStatus =3D FALSE; - goto Done; - } - - Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &gE= fiImageSecurityDatabaseGuid, NULL, &DbxDataSize, (VOID *) DbxData); - if (EFI_ERROR (Status)) { - // - // Force not-allowed-by-db to avoid bypass - // - VerifyStatus =3D FALSE; - goto Done; - } - if (IsCertHashFoundInDatabase (RootCert, RootCertSize, (EFI_SI= GNATURE_LIST *)DbxData, DbxDataSize, &RevocationTime)) { // // Check the timestamp signature and signing time to determi= ne if the RootCert can be trusted. @@ -1491,17 +1507,23 @@ IsAllowedByDb ( DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is sig= ned and signature is accepted by DB, but its root cert failed the timestamp= check.\n")); } } - - goto Done; } =20 - CertData =3D (EFI_SIGNATURE_DATA *) ((UINT8 *) CertData + CertLi= st->SignatureSize); + // + // There's no 'dbx' to check revocation time against (must-be pa= ss), + // or, there's revocation time found in 'dbx' and checked againt= 'dbt' + // (maybe pass or fail, depending on timestamp compare result). = Either + // way the verification job has been completed at this point. + // + goto Done; } - } =20 - DataSize -=3D CertList->SignatureListSize; - CertList =3D (EFI_SIGNATURE_LIST *) ((UINT8 *) CertList + CertList->= SignatureListSize); + CertData =3D (EFI_SIGNATURE_DATA *) ((UINT8 *) CertData + CertList= ->SignatureSize); + } } + + DataSize -=3D CertList->SignatureListSize; + CertList =3D (EFI_SIGNATURE_LIST *) ((UINT8 *) CertList + CertList->Si= gnatureListSize); } =20 Done: --=20 2.24.0.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 (#53871): https://edk2.groups.io/g/devel/message/53871 Mute This Topic: https://groups.io/mt/71023422/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53872+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53872+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998781641226.4889816411545; Thu, 6 Feb 2020 06:19:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id nLKIYY1788612xrKIqnvFxjh; Thu, 06 Feb 2020 06:19:41 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:40 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160689" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:39 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang , Laszlo Ersek Subject: [edk2-devel] [PATCH 6/9] SecurityPkg/DxeImageVerificationLib: Differentiate error and search result in IsCertHashFoundInDatabase(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:30 +0800 Message-Id: <20200206141933.356-7-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: JWpB8Y2PBzX2AnK9boicXsM1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998781; bh=xXtbhP05GE3cP0UopnahDz0HgpRP0HhkqbnYAnLtVh4=; h=Cc:Date:From:Reply-To:Subject:To; b=Xc6PrkFtwT6mfpTeIWFkkb7ye6KSVv2KW5PBC9w72B6P8IpCGARZcUl5xD4sNHszjFS +hKVgg3vyPJ9n0riBsqc4ZK2nWyAiVPh4rQG8HAfFDGFcpXEyQnO2ZJtttcXOppuuzPbw bmme86QyUkeRibyrWefgpzXezbxWxuZw2I8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 To avoid false-negative issue in check hash against dbx, both error condition (as return value) and check result (as out parameter) of IsCertHashFoundInDatabase() are added. So the caller of this function will know exactly if a failure is caused by a black list hit or other error happening, and enforce a more secure operation to prevent secure boot from being bypassed. For a white list check (db), there's no such necessity. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Signed-off-by: Laszlo Ersek --- .../DxeImageVerificationLib.c | 68 +++++++++++-------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index 8739d1fa29..a5dfee0f8e 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -822,22 +822,23 @@ AddImageExeInfo ( @param[in] SignatureList Pointer to the Signature List in forbidden= database. @param[in] SignatureListSize Size of Signature List. @param[out] RevocationTime Return the time that the certificate was r= evoked. + @param[out] IsFound Search result. Only valid if EFI_SUCCESS r= eturned. =20 - @return TRUE The certificate hash is found in the forbidden database. - @return FALSE The certificate hash is not found in the forbidden databa= se. + @retval EFI_SUCCESS Finished the search without any error. + @retval Others Error occurred in the search of database. =20 **/ -BOOLEAN +EFI_STATUS IsCertHashFoundInDatabase ( IN UINT8 *Certificate, IN UINTN CertSize, IN EFI_SIGNATURE_LIST *SignatureList, IN UINTN SignatureListSize, - OUT EFI_TIME *RevocationTime + OUT EFI_TIME *RevocationTime, + OUT BOOLEAN *IsFound ) { - BOOLEAN IsFound; - BOOLEAN Status; + EFI_STATUS Status; EFI_SIGNATURE_LIST *DbxList; UINTN DbxSize; EFI_SIGNATURE_DATA *CertHash; @@ -851,21 +852,22 @@ IsCertHashFoundInDatabase ( UINT8 *TBSCert; UINTN TBSCertSize; =20 - IsFound =3D FALSE; + Status =3D EFI_ABORTED; + *IsFound =3D FALSE; DbxList =3D SignatureList; DbxSize =3D SignatureListSize; HashCtx =3D NULL; HashAlg =3D HASHALG_MAX; =20 if ((RevocationTime =3D=3D NULL) || (DbxList =3D=3D NULL)) { - return FALSE; + return EFI_INVALID_PARAMETER; } =20 // // Retrieve the TBSCertificate from the X.509 Certificate. // if (!X509GetTBSCert (Certificate, CertSize, &TBSCert, &TBSCertSize)) { - return FALSE; + return Status; } =20 while ((DbxSize > 0) && (SignatureListSize >=3D DbxList->SignatureListSi= ze)) { @@ -895,16 +897,13 @@ IsCertHashFoundInDatabase ( if (HashCtx =3D=3D NULL) { goto Done; } - Status =3D mHash[HashAlg].HashInit (HashCtx); - if (!Status) { + if (!mHash[HashAlg].HashInit (HashCtx)) { goto Done; } - Status =3D mHash[HashAlg].HashUpdate (HashCtx, TBSCert, TBSCertSize); - if (!Status) { + if (!mHash[HashAlg].HashUpdate (HashCtx, TBSCert, TBSCertSize)) { goto Done; } - Status =3D mHash[HashAlg].HashFinal (HashCtx, CertDigest); - if (!Status) { + if (!mHash[HashAlg].HashFinal (HashCtx, CertDigest)) { goto Done; } =20 @@ -923,7 +922,8 @@ IsCertHashFoundInDatabase ( // // Hash of Certificate is found in forbidden database. // - IsFound =3D TRUE; + Status =3D EFI_SUCCESS; + *IsFound =3D TRUE; =20 // // Return the revocation time. @@ -938,12 +938,14 @@ IsCertHashFoundInDatabase ( DbxList =3D (EFI_SIGNATURE_LIST *) ((UINT8 *) DbxList + DbxList->Sign= atureListSize); } =20 + Status =3D EFI_SUCCESS; + Done: if (HashCtx !=3D NULL) { FreePool (HashCtx); } =20 - return IsFound; + return Status; } =20 /** @@ -1216,6 +1218,7 @@ IsForbiddenByDbx ( { EFI_STATUS Status; BOOLEAN IsForbidden; + BOOLEAN IsFound; UINT8 *Data; UINTN DataSize; EFI_SIGNATURE_LIST *CertList; @@ -1344,12 +1347,13 @@ IsForbiddenByDbx ( // CertPtr =3D CertPtr + sizeof (UINT32) + CertSize; =20 - if (IsCertHashFoundInDatabase (Cert, CertSize, (EFI_SIGNATURE_LIST *)D= ata, DataSize, &RevocationTime)) { + Status =3D IsCertHashFoundInDatabase (Cert, CertSize, (EFI_SIGNATURE_L= IST *)Data, DataSize, &RevocationTime, &IsFound); + if (EFI_ERROR (Status) || IsFound) { // // Check the timestamp signature and signing time to determine if th= e image can be trusted. // IsForbidden =3D TRUE; - if (PassTimestampCheck (AuthData, AuthDataSize, &RevocationTime)) { + if (!EFI_ERROR (Status) && PassTimestampCheck (AuthData, AuthDataSiz= e, &RevocationTime)) { IsForbidden =3D FALSE; // // Pass DBT check. Continue to check other certs in image signer's= cert list against DBX, DBT @@ -1392,6 +1396,7 @@ IsAllowedByDb ( { EFI_STATUS Status; BOOLEAN VerifyStatus; + BOOLEAN IsFound; EFI_SIGNATURE_LIST *CertList; EFI_SIGNATURE_DATA *CertData; UINTN DataSize; @@ -1495,17 +1500,26 @@ IsAllowedByDb ( // The image is signed and its signature is found in 'db'. // if (DbxData !=3D NULL) { + VerifyStatus =3D FALSE; // // Here We still need to check if this RootCert's Hash is revo= ked // - if (IsCertHashFoundInDatabase (RootCert, RootCertSize, (EFI_SI= GNATURE_LIST *)DbxData, DbxDataSize, &RevocationTime)) { - // - // Check the timestamp signature and signing time to determi= ne if the RootCert can be trusted. - // - VerifyStatus =3D PassTimestampCheck (AuthData, AuthDataSize,= &RevocationTime); - if (!VerifyStatus) { - DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is sig= ned and signature is accepted by DB, but its root cert failed the timestamp= check.\n")); - } + Status =3D IsCertHashFoundInDatabase (RootCert, RootCertSize, = (EFI_SIGNATURE_LIST *)DbxData, DbxDataSize, &RevocationTime, &IsFound); + if (EFI_ERROR (Status)) { + goto Done; + } + + if (!IsFound) { + VerifyStatus =3D TRUE; + goto Done; + } + + // + // Check the timestamp signature and signing time to determine= if the RootCert can be trusted. + // + VerifyStatus =3D PassTimestampCheck (AuthData, AuthDataSize, &= RevocationTime); + if (!VerifyStatus) { + DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is signe= d and signature is accepted by DB, but its root cert failed the timestamp c= heck.\n")); } } =20 --=20 2.24.0.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 (#53872): https://edk2.groups.io/g/devel/message/53872 Mute This Topic: https://groups.io/mt/71023424/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53873+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53873+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998785184818.3637418900644; Thu, 6 Feb 2020 06:19:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id QyRcYY1788612xaRc5FSDlH9; Thu, 06 Feb 2020 06:19:42 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:41 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160693" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:40 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang , Laszlo Ersek Subject: [edk2-devel] [PATCH 7/9] SecurityPkg/DxeImageVerificationLib: tighten default result of IsForbiddenByDbx()(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:31 +0800 Message-Id: <20200206141933.356-8-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: qqmIeDX9t3rtOsUIQmVsa1ADx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998782; bh=ETZiLbwt4Y+vby7+e7LqPq+CcDqvNHT+t0bCryYzdj0=; h=Cc:Date:From:Reply-To:Subject:To; b=clN5HFP1Sz1lCFWtgyVF1DWnnI16hKJY4v95cPHjlaM7Ql2nyU01kJ3EeqiJDvoGVvR o4WB67eSq0FUEnVryws4V2LLtLxredL+crFHjFCWt+DSjvSNEwAeE3HrLzT5aCItc6wUY XF/bBjTgNjVL8n99kAwlgfM2dU9mWKWPKVI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 All intermediate results inside this function will be checked and returned immediately upon any failure or error, like out-of-resource, hash calculation error or certificate retrieval failure. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Signed-off-by: Laszlo Ersek Reviewed-by: Jiewen Yao --- .../DxeImageVerificationLib/DxeImageVerificationLib.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index a5dfee0f8e..2236ce98ce 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1240,7 +1240,7 @@ IsForbiddenByDbx ( // // Variable Initialization // - IsForbidden =3D FALSE; + IsForbidden =3D TRUE; Data =3D NULL; CertList =3D NULL; CertData =3D NULL; @@ -1257,7 +1257,14 @@ IsForbiddenByDbx ( // DataSize =3D 0; Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageS= ecurityDatabaseGuid, NULL, &DataSize, NULL); + ASSERT (EFI_ERROR (Status)); if (Status !=3D EFI_BUFFER_TOO_SMALL) { + if (Status =3D=3D EFI_NOT_FOUND) { + // + // Evidently not in dbx if the database doesn't exist. + // + IsForbidden =3D FALSE; + } return IsForbidden; } Data =3D (UINT8 *) AllocateZeroPool (DataSize); @@ -1366,6 +1373,8 @@ IsForbiddenByDbx ( =20 } =20 + IsForbidden =3D FALSE; + Done: if (Data !=3D NULL) { FreePool (Data); --=20 2.24.0.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 (#53873): https://edk2.groups.io/g/devel/message/53873 Mute This Topic: https://groups.io/mt/71023425/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53874+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53874+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998783547939.8889698148167; Thu, 6 Feb 2020 06:19:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id p55lYY1788612xnMf7AC56bB; Thu, 06 Feb 2020 06:19:43 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:42 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160701" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:41 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Laszlo Ersek , Jiewen Yao , Chao Zhang Subject: [edk2-devel] [PATCH 8/9] SecurityPkg/DxeImageVerificationLib: plug Data leak in IsForbiddenByDbx()(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:32 +0800 Message-Id: <20200206141933.356-9-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: L5jW6jB3BNrKFeyIOpWRK6CNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998783; bh=QcKkghMPiYlvO81t0KLL29FS434p4RqqJjlwBync/QE=; h=Cc:Date:From:Reply-To:Subject:To; b=f9NDjI5cgkGQ8gbT8ORXN3BZMBfSRx03nY1L0vvKpFkv3gteFCGW7Q4fTzyq6TAbv7h 84wMaKHwOYaoUpDGVd0Kwx/8JSA4UkdFArf0hAttElTlIk9Gmuuk5dvaijG0z6wFPREtF +UK80K5d7+UVmFqT/Okl/xY7+OL3b1U378s= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Laszlo Ersek REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 If the second GetVariable() call for "dbx" fails, in IsForbiddenByDbx(), we have to free Data. Jump to "Done" for that. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Laszlo Ersek Reviewed-by: Jiewen Yao Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index 2236ce98ce..5b7a67f811 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1274,7 +1274,7 @@ IsForbiddenByDbx ( =20 Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSec= urityDatabaseGuid, NULL, &DataSize, (VOID *) Data); if (EFI_ERROR (Status)) { - return IsForbidden; + goto Done; } =20 // --=20 2.24.0.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 (#53874): https://edk2.groups.io/g/devel/message/53874 Mute This Topic: https://groups.io/mt/71023426/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- From nobody Tue Nov 26 11:58:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53875+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53875+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580998784643585.9656377912642; Thu, 6 Feb 2020 06:19:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id zOoOYY1788612xecHUtUoKO8; Thu, 06 Feb 2020 06:19:44 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web11.12696.1580998775768725774 for ; Thu, 06 Feb 2020 06:19:43 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 06:19:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="226160707" X-Received: from shwdeopensfp777.ccr.corp.intel.com ([10.239.158.78]) by fmsmga008.fm.intel.com with ESMTP; 06 Feb 2020 06:19:42 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Jiewen Yao , Chao Zhang Subject: [edk2-devel] [PATCH 9/9] SecurityPkg/DxeImageVerificationLib: Differentiate error and search result in IsSignatureFoundInDatabase(CVE-2019-14575) Date: Thu, 6 Feb 2020 22:19:33 +0800 Message-Id: <20200206141933.356-10-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-1-jian.j.wang@intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: DDfIkJCrw7LldOJ2Hb6HrwGrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580998784; bh=xOOK52d+JiJ9tgH2mr3QWsL+NQjSAqK70IR4L/Q2/10=; h=Cc:Date:From:Reply-To:Subject:To; b=rw8vJ36OWUAPVpD26y7yrCbzRousRd5MsdMyURu1nb+pxYpHhPYZNeFatyQsKlWHntp +lQ229rsCwMqm/WQQF/reT8gC4m8ZzofRLLWNaO6EyVgMzxa2CQ4ZcdTGmxRlheXF6QJ3 w1Xj7QlSupjUZ1TtcrnoZ3ckcdv1jXoYJQg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 To avoid false-negative issue in check hash against dbx, both error condition (as return value) and check result (as out parameter) of IsSignatureFoundInDatabase() are added. So the caller of this function will know exactly if a failure is caused by a black list hit or other error happening, and enforce a more secure operation to prevent secure boot from being bypassed. For a white list check (db), there's no such necessity. All intermediate results inside this function will be checked and returned immediately upon any failure or error, like out-of-resource, hash calculation error or certificate retrieval failure. Cc: Jiewen Yao Cc: Chao Zhang Signed-off-by: Jian J Wang Reviewed-by: Jiewen Yao --- .../DxeImageVerificationLib.c | 77 ++++++++++++++----- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificati= onLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationL= ib.c index 5b7a67f811..8e599ca0be 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -955,17 +955,19 @@ Done: @param[in] Signature Pointer to signature that is searched fo= r. @param[in] CertType Pointer to hash algorithm. @param[in] SignatureSize Size of Signature. + @param[out] IsFound Search result. Only valid if EFI_SUCCESS= returned =20 - @return TRUE Found the signature in the variable data= base. - @return FALSE Not found the signature in the variable = database. + @retval EFI_SUCCESS Finished the search without any error. + @retval Others Error occurred in the search of database. =20 **/ -BOOLEAN +EFI_STATUS IsSignatureFoundInDatabase ( - IN CHAR16 *VariableName, - IN UINT8 *Signature, - IN EFI_GUID *CertType, - IN UINTN SignatureSize + IN CHAR16 *VariableName, + IN UINT8 *Signature, + IN EFI_GUID *CertType, + IN UINTN SignatureSize, + OUT BOOLEAN *IsFound ) { EFI_STATUS Status; @@ -975,22 +977,28 @@ IsSignatureFoundInDatabase ( UINT8 *Data; UINTN Index; UINTN CertCount; - BOOLEAN IsFound; =20 // // Read signature database variable. // - IsFound =3D FALSE; + *IsFound =3D FALSE; Data =3D NULL; DataSize =3D 0; Status =3D gRT->GetVariable (VariableName, &gEfiImageSecurityDatabase= Guid, NULL, &DataSize, NULL); if (Status !=3D EFI_BUFFER_TOO_SMALL) { - return FALSE; + if (Status =3D=3D EFI_NOT_FOUND) { + // + // No database, no need to search. + // + Status =3D EFI_SUCCESS; + } + + return Status; } =20 Data =3D (UINT8 *) AllocateZeroPool (DataSize); if (Data =3D=3D NULL) { - return FALSE; + return EFI_OUT_OF_RESOURCES; } =20 Status =3D gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGui= d, NULL, &DataSize, Data); @@ -1010,7 +1018,7 @@ IsSignatureFoundInDatabase ( // // Find the signature in database. // - IsFound =3D TRUE; + *IsFound =3D TRUE; // // Entries in UEFI_IMAGE_SECURITY_DATABASE that are used to vali= date image should be measured // @@ -1023,7 +1031,7 @@ IsSignatureFoundInDatabase ( Cert =3D (EFI_SIGNATURE_DATA *) ((UINT8 *) Cert + CertList->Signat= ureSize); } =20 - if (IsFound) { + if (*IsFound) { break; } } @@ -1037,7 +1045,7 @@ Done: FreePool (Data); } =20 - return IsFound; + return Status; } =20 /** @@ -1642,6 +1650,8 @@ DxeImageVerificationHandler ( CHAR16 *NameStr; RETURN_STATUS PeCoffStatus; EFI_STATUS HashStatus; + EFI_STATUS DbStatus; + BOOLEAN IsFound; =20 SignatureList =3D NULL; SignatureListSize =3D 0; @@ -1650,7 +1660,7 @@ DxeImageVerificationHandler ( PkcsCertData =3D NULL; Action =3D EFI_IMAGE_EXECUTION_AUTH_UNTESTED; IsVerified =3D FALSE; - + IsFound =3D FALSE; =20 // // Check the image type and get policy setting. @@ -1792,7 +1802,14 @@ DxeImageVerificationHandler ( goto Failed; } =20 - if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDi= gest, &mCertType, mImageDigestSize)) { + DbStatus =3D IsSignatureFoundInDatabase ( + EFI_IMAGE_SECURITY_DATABASE1, + mImageDigest, + &mCertType, + mImageDigestSize, + &IsFound + ); + if (EFI_ERROR (DbStatus) || IsFound) { // // Image Hash is in forbidden database (DBX). // @@ -1800,7 +1817,14 @@ DxeImageVerificationHandler ( goto Failed; } =20 - if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageDig= est, &mCertType, mImageDigestSize)) { + DbStatus =3D IsSignatureFoundInDatabase ( + EFI_IMAGE_SECURITY_DATABASE, + mImageDigest, + &mCertType, + mImageDigestSize, + &IsFound + ); + if (!EFI_ERROR (DbStatus) && IsFound) { // // Image Hash is in allowed database (DB). // @@ -1888,14 +1912,29 @@ DxeImageVerificationHandler ( // // Check the image's hash value. // - if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDi= gest, &mCertType, mImageDigestSize)) { + DbStatus =3D IsSignatureFoundInDatabase ( + EFI_IMAGE_SECURITY_DATABASE1, + mImageDigest, + &mCertType, + mImageDigestSize, + &IsFound + ); + if (EFI_ERROR (DbStatus) || IsFound) { Action =3D EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND; DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is signed but %s= hash of image is found in DBX.\n", mHashTypeStr)); IsVerified =3D FALSE; break; } + if (!IsVerified) { - if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageD= igest, &mCertType, mImageDigestSize)) { + DbStatus =3D IsSignatureFoundInDatabase ( + EFI_IMAGE_SECURITY_DATABASE, + mImageDigest, + &mCertType, + mImageDigestSize, + &IsFound + ); + if (!EFI_ERROR (DbStatus) && IsFound) { IsVerified =3D TRUE; } else { DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is signed but = signature is not allowed by DB and %s hash of image is not found in DB/DBX.= \n", mHashTypeStr)); --=20 2.24.0.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 (#53875): https://edk2.groups.io/g/devel/message/53875 Mute This Topic: https://groups.io/mt/71023427/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-