From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web12.610.1577086790659406494 for ; Sun, 22 Dec 2019 23:39:50 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: ray.ni@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Dec 2019 23:39:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,346,1571727600"; d="scan'208";a="207184749" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga007.jf.intel.com with ESMTP; 22 Dec 2019 23:39:50 -0800 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 22 Dec 2019 23:39:49 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 22 Dec 2019 23:39:49 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.90]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.222]) with mapi id 14.03.0439.000; Mon, 23 Dec 2019 15:39:47 +0800 From: "Ni, Ray" To: "Dong, Eric" , "devel@edk2.groups.io" CC: Laszlo Ersek Subject: Re: [PATCH v2 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Fix buffer overflow issue. Thread-Topic: [PATCH v2 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Fix buffer overflow issue. Thread-Index: AQHVuVz6dKq+C8qIhE+Q8UHGnA3c7afHVO8g Date: Mon, 23 Dec 2019 07:39:46 +0000 Deferred-Delivery: Mon, 23 Dec 2019 07:38:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C3A8DD9@SHSMSX104.ccr.corp.intel.com> References: <20191223064806.682-1-eric.dong@intel.com> <20191223064806.682-3-eric.dong@intel.com> In-Reply-To: <20191223064806.682-3-eric.dong@intel.com> 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 Reviewed-by: Ray Ni > -----Original Message----- > From: Dong, Eric > Sent: Monday, December 23, 2019 2:48 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Laszlo Ersek > Subject: [PATCH v2 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Fix buffer overflow > issue. >=20 > The size for the array of mSmmMpSyncData->CpuData[] is 0 ~ > mMaxNumberOfCpus -1. But current code may use > mSmmMpSyncData->CpuData[mMaxNumberOfCpus]. >=20 > This patch fixed this issue. >=20 > Cc: Ray Ni > Cc: Laszlo Ersek > Signed-off-by: Eric Dong > --- > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > index 5ad12db980..e5324f8f84 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > @@ -137,7 +137,7 @@ ReleaseAllAPs ( > { >=20 > UINTN Index; >=20 >=20 >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (IsPresentAp (Index)) { >=20 > ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run); >=20 > } >=20 > @@ -170,7 +170,7 @@ AllCpusInSmmWithExceptions ( >=20 >=20 > CpuData =3D mSmmMpSyncData->CpuData; >=20 > ProcessorInfo =3D gSmmCpuPrivate->ProcessorInfo; >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (!(*(CpuData[Index].Present)) && ProcessorInfo[Index].ProcessorId= !=3D > INVALID_APIC_ID) { >=20 > if (((Exceptions & ARRIVAL_EXCEPTION_DELAYED) !=3D 0) && > SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmDelayed) !=3D 0) { >=20 > continue; >=20 > @@ -305,7 +305,7 @@ SmmWaitForApArrival ( > // >=20 > // Send SMI IPIs to bring outside processors in >=20 > // >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && > gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId !=3D INVALID_APIC_ID) { >=20 > SendSmiIpi ((UINT32)gSmmCpuPrivate- > >ProcessorInfo[Index].ProcessorId); >=20 > } >=20 > @@ -361,7 +361,7 @@ WaitForAllAPsNotBusy ( > { >=20 > UINTN Index; >=20 >=20 >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > // >=20 > // Ignore BSP and APs which not call in SMM. >=20 > // >=20 > @@ -619,7 +619,7 @@ BSPHandler ( > // >=20 > while (TRUE) { >=20 > PresentCount =3D 0; >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (*(mSmmMpSyncData->CpuData[Index].Present)) { >=20 > PresentCount ++; >=20 > } >=20 > @@ -1303,7 +1303,7 @@ InternalSmmStartupAllAPs ( > } >=20 >=20 >=20 > CpuCount =3D 0; >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (IsPresentAp (Index)) { >=20 > CpuCount ++; >=20 >=20 >=20 > @@ -1335,13 +1335,13 @@ InternalSmmStartupAllAPs ( > // Here code always use AcquireSpinLock instead of AcquireSpinLockOrFa= il > for not >=20 > // block mode. >=20 > // >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (IsPresentAp (Index)) { >=20 > AcquireSpinLock (mSmmMpSyncData->CpuData[Index].Busy); >=20 > } >=20 > } >=20 >=20 >=20 > - for (Index =3D mMaxNumberOfCpus; Index-- > 0;) { >=20 > + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { >=20 > if (IsPresentAp (Index)) { >=20 > mSmmMpSyncData->CpuData[Index].Procedure =3D > (EFI_AP_PROCEDURE2) Procedure; >=20 > mSmmMpSyncData->CpuData[Index].Parameter =3D ProcedureArguments; >=20 > -- > 2.23.0.windows.1