From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: ray.ni@intel.com) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by groups.io with SMTP; Tue, 25 Jun 2019 18:57:34 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jun 2019 18:57:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,418,1557212400"; d="scan'208";a="337052024" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga005.jf.intel.com with ESMTP; 25 Jun 2019 18:57:32 -0700 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 25 Jun 2019 18:57:33 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 25 Jun 2019 18:57:33 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.185]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.104]) with mapi id 14.03.0439.000; Wed, 26 Jun 2019 09:57:30 +0800 From: "Ni, Ray" To: "Dong, Eric" , "Gao, Zhichao" , "devel@edk2.groups.io" CC: Laszlo Ersek , "Gao, Liming" Subject: Re: [PATCH V2] UefiCpuPkg/MpInitLib: MicrocodeDetect: Ensure checked range is valid Thread-Topic: [PATCH V2] UefiCpuPkg/MpInitLib: MicrocodeDetect: Ensure checked range is valid Thread-Index: AQHVK2jjYhG7nW5IV0y7iwF4+gx54qaslLOAgACXwJA= Date: Wed, 26 Jun 2019 01:57:30 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C1F0A34@SHSMSX104.ccr.corp.intel.com> References: <20190625151541.28632-1-zhichao.gao@intel.com> In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: ray.ni@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > > @@ -170,6 +170,7 @@ MicrocodeDetect ( > > /// Check overflow and whether TotalSize is aligned with 4 bytes. > > /// > > if ( ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd || > > + ((UINTN)MicrocodeEntryPoint + TotalSize) < (UINTN) > > + CpuMpData->MicrocodePatchAddress || How about below check? First comparison hits when the sum of MicrocodeEntryPoint and TotalSize ove= rflows. Second comparison hits when the sum crosses the boundary of the whole micro= code buffer boundary If (((UINTN) MicrocodeEntryPoint > MAX_UINTN - TotalSize) || ((UINTN)Microc= odeEntryPoint + TotalSize) > MicrocodeEnd) > > (TotalSize & 0x3) !=3D 0 > > ) { > > MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) > > MicrocodeEntryPoint) + SIZE_1KB); > > -- > > 2.21.0.windows.1