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 the SMM additionally bypasses the 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 multiple HP devices 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 the SMM additionally bypasses the 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 child the SW SMI handler registered with GUID ca9f989d-ef13-41d6-a5c4-0f380c35dae0
and located at offset 0x168C
in the driver.The pseudocode for this handler is shown below:
EFI_STATUS __fastcall SmiHandler_168C(
EFI_HANDLE DispatchHandle,
const void *Context,
CommBuffer *CommBuffer,
UINTN *CommBufferSize)
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
if ( CommBuffer && CommBufferSize && *CommBufferSize <= 0x2000 )
{
if ( CommBuffer->Case )
{
if ( CommBuffer->Case != 1 )
{
CommBuffer->Result = EFI_INVALID_PARAMETER;
return 0i64;
}
Flag = 1;
}
else
{
Flag = 0;
}
CommBuffer->Result = sub_1738(Flag, CommBuffer->Msg, CommBuffer->MsgLen);
}
return 0i64;
}
In this case the CommBuffer
has the following structure:
00000000 CommBufferStruct struc ; (sizeof=0x20, mappedto_235)
00000000 Case dd ?
00000004 field_4 dd ?
00000008 Result dq ?
00000010 MsgLen dq ?
00000018 Msg dq ?
00000020 CommBufferStruct ends
As we can see the input Communication Buffer is not validated to be outside of the SMRAM since the Communication Buffer size (*CommBufferSize
) is not checked correctly (it may be 0
). If attacker sets *CommBufferSize
to 0
, he will bypass validation implemented in PiSmmCommunicationSmm
before gSmst->SmiManage
call:
CommSize = (UINTN)CommunicateHeader->MessageLength;
if (!SmmIsBufferOutsideSmmValid ((UINTN)&CommunicateHeader->Data[0], CommSize)) {
Status = EFI_SUCCESS;
goto Done;
}
//
// Call dispatch function
//
Status = gSmst->SmiManage (
&CommunicateHeader->HeaderGuid,
NULL,
&CommunicateHeader->Data[0],
&CommSize
);
Keeping this in mind, a possible attacker has limited but still an opportunity to corrupt some SMM memory by pointing Communication Buffer into the SMRAM contents. This leads to rewriting pointed area with a fixed or predictable data - Status code. Writing such data into SMRAM could allow a possible attacker to corrupt some structures at the beginning of this memory (for example, change SMM S3 resume code pointer and hijack execution flow during SMM S3 wake up procedure). This could lead to gaining arbitrary code execution in SMM.
To exploit this vulnerability it is enough to:
SMRAM_BASE - sizeof(EFI_SMM_COMMUNICATE_HEADER)
).0xB2
IO port.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