summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/CpuDxe/CpuMp.c
diff options
context:
space:
mode:
authorkenlautner <85201046+kenlautner@users.noreply.github.com>2024-11-01 12:00:25 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-11-15 17:50:21 +0000
commit13fad60156f18cf0d2043fb7f05c1dc5e3d91fb7 (patch)
treee922b2c0e2e544488f5339b52926809bb323ab58 /UefiCpuPkg/CpuDxe/CpuMp.c
parent843f0c129ec6e989afee9cf8af36749c8f5b3ffd (diff)
downloadedk2-13fad60156f18cf0d2043fb7f05c1dc5e3d91fb7.tar.gz
UefiCpuPkg: Fix unchecked returns and potential integer overflows
Resolves several issues in UefiCpuPkg related to: 1. Unchecked returns leading to potential NULL or uninitialized access. 2. Potential unchecked integer overflows. 3. Incorrect comparison between integers of different sizes. Co-authored-by: kenlautner <85201046+kenlautner@users.noreply.github.com> Signed-off-by: Chris Fernald <chfernal@microsoft.com>
Diffstat (limited to 'UefiCpuPkg/CpuDxe/CpuMp.c')
-rw-r--r--UefiCpuPkg/CpuDxe/CpuMp.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index e7575d9b80..b90312e863 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -622,8 +622,15 @@ InitializeExceptionStackSwitchHandlers (
{
EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData;
UINTN Index;
+ EFI_STATUS Status;
+
+ Status = MpInitLibWhoAmI (&Index);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "[%a] - Failed to get processor number. The exception stack was not initialized.\n", __func__));
+ return;
+ }
- MpInitLibWhoAmI (&Index);
SwitchStackData = (EXCEPTION_STACK_SWITCH_CONTEXT *)Buffer;
//
@@ -758,25 +765,28 @@ InitializeMpSupport (
Status = MpInitLibInitialize ();
ASSERT_EFI_ERROR (Status);
- MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
- mNumberOfProcessors = NumberOfProcessors;
- DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", mNumberOfProcessors));
+ Status = MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
+ ASSERT_EFI_ERROR (Status);
+ if (!EFI_ERROR (Status)) {
+ mNumberOfProcessors = NumberOfProcessors;
+ DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", mNumberOfProcessors));
- //
- // Initialize special exception handlers for each logic processor.
- //
- InitializeMpExceptionHandlers ();
+ //
+ // Initialize special exception handlers for each logic processor.
+ //
+ InitializeMpExceptionHandlers ();
- //
- // Update CPU healthy information from Guided HOB
- //
- CollectBistDataFromHob ();
-
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mMpServiceHandle,
- &gEfiMpServiceProtocolGuid,
- &mMpServicesTemplate,
- NULL
- );
- ASSERT_EFI_ERROR (Status);
+ //
+ // Update CPU healthy information from Guided HOB
+ //
+ CollectBistDataFromHob ();
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mMpServiceHandle,
+ &gEfiMpServiceProtocolGuid,
+ &mMpServicesTemplate,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
}