Skip to content

Commit

Permalink
UefiCpuPkg/PiSmmCpuDxeSmm: Fix buffer overflow issue.
Browse files Browse the repository at this point in the history
The size for the array of mSmmMpSyncData->CpuData[] is 0 ~
mMaxNumberOfCpus -1. But current code may use
mSmmMpSyncData->CpuData[mMaxNumberOfCpus].

This patch fixed this issue.

Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Eric Dong <eric.dong@intel.com>
  • Loading branch information
ydong10 authored and mergify[bot] committed Dec 24, 2019
1 parent a457823 commit 123b720
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ ReleaseAllAPs (
{
UINTN Index;

for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (IsPresentAp (Index)) {
ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ AllCpusInSmmWithExceptions (

CpuData = mSmmMpSyncData->CpuData;
ProcessorInfo = gSmmCpuPrivate->ProcessorInfo;
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (!(*(CpuData[Index].Present)) && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {
if (((Exceptions & ARRIVAL_EXCEPTION_DELAYED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmDelayed) != 0) {
continue;
Expand Down Expand Up @@ -305,7 +305,7 @@ SmmWaitForApArrival (
//
// Send SMI IPIs to bring outside processors in
//
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {
SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId);
}
Expand Down Expand Up @@ -361,7 +361,7 @@ WaitForAllAPsNotBusy (
{
UINTN Index;

for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
//
// Ignore BSP and APs which not call in SMM.
//
Expand Down Expand Up @@ -617,7 +617,7 @@ BSPHandler (
//
while (TRUE) {
PresentCount = 0;
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (*(mSmmMpSyncData->CpuData[Index].Present)) {
PresentCount ++;
}
Expand Down Expand Up @@ -1301,7 +1301,7 @@ InternalSmmStartupAllAPs (
}

CpuCount = 0;
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (IsPresentAp (Index)) {
CpuCount ++;

Expand Down Expand Up @@ -1333,13 +1333,13 @@ InternalSmmStartupAllAPs (
// Here code always use AcquireSpinLock instead of AcquireSpinLockOrFail for not
// block mode.
//
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (IsPresentAp (Index)) {
AcquireSpinLock (mSmmMpSyncData->CpuData[Index].Busy);
}
}

for (Index = mMaxNumberOfCpus; Index-- > 0;) {
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
if (IsPresentAp (Index)) {
mSmmMpSyncData->CpuData[Index].Procedure = (EFI_AP_PROCEDURE2) Procedure;
mSmmMpSyncData->CpuData[Index].Parameter = ProcedureArguments;
Expand Down

0 comments on commit 123b720

Please sign in to comment.