An attacker can exploit this vulnerability to elevate privileges from ring 0 to ring -2, execute arbitrary code in System Management Mode - an environment more privileged than operating system (OS) and completely isolated from it. Running arbitrary code in SMM additionally bypasses SMM-based SPI flash protections against modifications, which can help an attacker to install a firmware backdoor/implant into the BIOS. Such a malicious firmware code in the BIOS could persist across operating system re-installs. Additionally, this vulnerability potentially could be used by threat actors to bypass security mechanisms provided by the UEFI firmware (for example, Secure Boot and some types of memory isolation for hypervisors).
Binarly REsearch Team has discovered a SMM memory corruption vulnerability on a BullSequana Edge server allowing a possible attacker to write fixed or predictable data to SMRAM. Exploiting this issue could lead to escalating privileges to SMM.
An attacker can exploit this vulnerability to elevate privileges from ring 0 to ring -2, execute arbitrary code in System Management Mode - an environment more privileged than operating system (OS) and completely isolated from it. Running arbitrary code in SMM additionally bypasses SMM-based SPI flash protections against modifications, which can help an attacker to install a firmware backdoor/implant into the BIOS. Such a malicious firmware code in the BIOS could persist across operating system re-installs. Additionally, this vulnerability potentially could be used by threat actors to bypass security mechanisms provided by the UEFI firmware (for example, Secure Boot and some types of memory isolation for hypervisors).
The vulnerability exists in the SW SMI handler registered with number 0x16
and located at offset 0x3DBC
in the driver:
EFI_STATUS SwSmiHandler(EFI_HANDLE DispatchHandle, const void *Context, void *CommBuffer, UINTN *CommBufferSize)
{
...
input = ReadSaveSate(EFI_SMM_SAVE_STATE_REGISTER_RAX);
counter = 0;
if ( gFuncsArray[0] )
{
offset = 0;
while ( BYTE1(input) != (__int64)SLODWORD(gIndexArray[offset]) )
{
offset = 2 * ++counter;
if ( !gIndexArray[2 * counter + 1] )
goto LABEL_12;
}
v7 = gFuncsArray[2 * counter])(2 * counter, offset * 8, 0x8000000000000003);
...
As we can see, the input for this SW SMI handler is passed using CPU Save State. The contents of RAX
register allows a handler's caller to choose the function for invoking from an array gFuncsArray
:
.data:00000000800113E8 gFuncsArray dq offset Func0
.data:00000000800113F0 dq 1
.data:00000000800113F8 dq offset Func1
.data:0000000080011400 dq 2
.data:0000000080011408 dq offset Func2
Let's look at Func0()
for example located at 0x3848
in the driver:
__int64 Func0()
{
v0 = ReadSaveSate(EFI_SMM_SAVE_STATE_REGISTER_RBX);
ptr = ReadSaveSate(EFI_SMM_SAVE_STATE_REGISTER_RSI);
LOBYTE(v2) = 1;
if ( v0 != sub_80009F6C((__int64)&stru_80011078, v2) + 40 || *(_DWORD *)(ptr + 8) != 'AFMS' )
return 0x8000000000000003ui64;
result = (*(_QWORD *)(gSmmBuffer + 8) + 8))(*(_QWORD *)(gSmmBuffer + 8), *(_QWORD *)(ptr + 0x10), 0, ptr + 0x20, ptr + 0x28);
*(_QWORD *)ptr = result;
return result;
}
Here an additional input is extracted from saved RSI
register - a pointer, which is not validated to point outside of SMRAM. Only a simple signature (SMFA
) comparison is applied, but this is insufficient, because a possible attacker can make this pointer to point directly to this signature in this code or any other suitable location in SMRAM to bypass this check.
This leads to rewriting pointed area with a fixed or predictable data - return's result
. Writing such data into SMRAM could allow a possible attacker to modify SMM code or to corrupt some data in SMRAM. This could lead to gaining arbitrary code execution in SMM.
To exploit this vulnerability it is enough to:
RSI
register to point a desired location in SMRAM to modify (*(_DWORD *)(ptr_1 + 8)
should point to SMFA
signature.0x16
via 0xB2
IO port and providing the function index 0
in RAX
register.To fix this vulnerability, it is essential that all the input pointers (including the nested pointers) for SMI handlers are wrapped with sanity checks to make sure they are not pointing into SMRAM.
This bug is subject to a 90 day disclosure deadline. After 90 days elapsed or a patch has been made broadly available (whichever is earlier), the bug report will become visible to the public.
Binarly REsearch Team