edk2/UefiCpuPkg/Library/MpInitLibUp
Changyuan Lyu c422b3b97b UefiCpuPkg/MpInitLibUp: Fix #UD exception due to NULL pointer deref
In MpInitLibUp, MpInitLibGetNumberOfProcessors() unconditionally
dereferences the NumberOfProcessors and NumberOfEnabledProcessors
parameters. However, the API specification marks both as OPTIONAL.

When callers (like InitializeExceptionStackSwitchHandlers in
UefiCpuPkg/CpuMpPei/CpuMpPei.c) pass NULL for NumberOfEnabledProcessors,
GCC's Link-Time Optimization (LTO) detects an unconditional NULL pointer
dereference. Since this is Undefined Behavior, GCC emits a 'ud2'
(Invalid Opcode) instruction at the dereference site. This leads to an
unexpected #UD exception during the boot process of uniprocessor guests
like TDX VMs.

This patch fixes the issue by adding appropriate NULL checks before
dereferencing the pointers. It also returns EFI_INVALID_PARAMETER if
both arguments are NULL, ensuring compliance with the MpInitLib
specification.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
2026-03-02 02:05:57 +00:00
..
MpInitLibUp.c UefiCpuPkg/MpInitLibUp: Fix #UD exception due to NULL pointer deref 2026-03-02 02:05:57 +00:00
MpInitLibUp.inf UefiCpuPkg: set EXTENDED_PROCESSOR_INFORMATION to 0 2024-01-09 16:31:57 +00:00
MpInitLibUp.uni UefiCpuPkg/MpInitLibUp: Add uniprocessor MpInitLib 2019-04-30 16:39:34 -07:00