From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.4077.1581586685740115003 for ; Thu, 13 Feb 2020 01:38:05 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: jiewen.yao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2020 01:38:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,436,1574150400"; d="scan'208";a="227179739" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga008.jf.intel.com with ESMTP; 13 Feb 2020 01:38:05 -0800 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 13 Feb 2020 01:38:05 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 13 Feb 2020 01:38:04 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.126]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.225]) with mapi id 14.03.0439.000; Thu, 13 Feb 2020 17:38:03 +0800 From: "Yao, Jiewen" To: "Wang, Jian J" , "devel@edk2.groups.io" CC: "Zhang, Chao B" Subject: Re: [PATCH 3/9] SecurityPkg/DxeImageVerificationLib: fix wrong fetching dbx in IsAllowedByDb(CVE-2019-14575) Thread-Topic: [PATCH 3/9] SecurityPkg/DxeImageVerificationLib: fix wrong fetching dbx in IsAllowedByDb(CVE-2019-14575) Thread-Index: AQHV3Ph6IzsNkx0NwEq9bl3H9eueEqgY6G8w Date: Thu, 13 Feb 2020 09:38:02 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503F92CB8F@shsmsx102.ccr.corp.intel.com> References: <20200206141933.356-1-jian.j.wang@intel.com> <20200206141933.356-4-jian.j.wang@intel.com> In-Reply-To: <20200206141933.356-4-jian.j.wang@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: jiewen.yao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen Yao > -----Original Message----- > From: Wang, Jian J > Sent: Thursday, February 6, 2020 10:19 PM > To: devel@edk2.groups.io > Cc: Yao, Jiewen ; Zhang, Chao B > > Subject: [PATCH 3/9] SecurityPkg/DxeImageVerificationLib: fix wrong fetch= ing > dbx in IsAllowedByDb(CVE-2019-14575) >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1608 >=20 > 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. >=20 > 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. >=20 > if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { > goto Done; > } >=20 > Cc: Jiewen Yao > Cc: Chao Zhang > Signed-off-by: Jian J Wang > --- > .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git > a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c > b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c > index 5dcd6efed5..1efb2f96cd 100644 > --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib= .c > +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib= .c > @@ -1456,8 +1456,9 @@ IsAllowedByDb ( > // >=20 > // Here We still need to check if this RootCert's Hash is re= voked >=20 > // >=20 > + DbxDataSize =3D 0; >=20 > Status =3D gRT->GetVariable (EFI_IMAGE_SECURITY_DATABASE1, > &gEfiImageSecurityDatabaseGuid, NULL, &DbxDataSize, NULL); >=20 > - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { >=20 > + if (Status !=3D EFI_BUFFER_TOO_SMALL) { >=20 > goto Done; >=20 > } >=20 > DbxData =3D (UINT8 *) AllocateZeroPool (DbxDataSize); >=20 > -- > 2.24.0.windows.2