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 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 malicious 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 callout vulnerability on multiple HP devices allowing a possible attacker to hijack execution flow of a code running in System Management Mode. 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 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 malicious 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 child SW SMI handler registered with GUID 807ca9f6-216c-4cbc-87f7-3cd555887208
and located at offset 0x17C8
in the driver.
The pseudocode for this handler is shown below:
EFI_STATUS __fastcall SmiHandler_17C8(
EFI_HANDLE DispatchHandle,
const void *Context,
CommBufferStruct *CommBuffer,
UINTN *CommBufferSize)
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
if ( CommBuffer )
{
if ( CommBufferSize )
{
Size = *CommBufferSize;
if ( (-(*CommBufferSize != 160) & EFI_INVALID_PARAMETER) == 0 )
{
Res = 0;
if ( Size )
Res = SmmIsBufferOutsideSmmValid(CommBuffer, Size);
if ( (-(Res == 0) & EFI_INVALID_PARAMETER) == 0 )
{
Status = -(CommBuffer->Sig != 'GFCU') & EFI_INVALID_PARAMETER;
if ( CommBuffer->Sig == 'GFCU' )
{
if ( CommBuffer->Case == 16 )
{
if ( !gBufferPtr1 )
{
BufferPtr1 = GetCopy(120, &CommBuffer->BufferPtr1);
BufferSize = CommBuffer->BufferSize;
BufferPtr = CommBuffer->BufferPtr;
gBufferPtr1 = BufferPtr1;
sub_2288(BufferPtr, BufferSize);
// Vulnerability here
PcdProtocol = BsLocatePcdProtocol();
if ( (PcdProtocol->Get8)(0x2C4) == 1 )
HandlerUnregister();
}
}
...
}
...
}
}
}
}
return 0;
}
In this case CommBuffer
has following structure:
00000000 CommBufferStruct struc ; (sizeof=0xA0, mappedto_234)00000000 Sig dd ?00000004 Case dd ?00000008 BufferPtr dq ?00000010 BufferSize dq ?00000018 BufferPtr1 dd ?...00000098 Status dq ?
If CommBuffer->Sig == 0x47464355 && CommBuffer->Case == 16 && !CommBuffer->BufferPtr1
following code will trigger:
BufferPtr1 = GetCopy(120, &CommBuffer->BufferPtr1);
BufferSize = CommBuffer->BufferSize;
BufferPtr = CommBuffer->BufferPtr;
gBufferPtr1 = BufferPtr1;
sub_2288(BufferPtr, BufferSize);
// Vulnerability here
PcdProtocol = BsLocatePcdProtocol();
if ( (PcdProtocol->Get8)(0x2C4) == 1 )
HandlerUnregister();
Below is the pseudocode of the BsLocatePcdProtocol
function:
PCD_PROTOCOL *BsLocatePcdProtocol()
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
result = gPcdProtocol;
// gPcdProtocol equals zero on first call
if ( !gPcdProtocol )
{
// Executed only once
gBS->LocateProtocol(&PCD_PROTOCOL_GUID, 0i64, &gPcdProtocol);
return gPcdProtocol;
}
return result;
}
As we can see from this pseudocode, the LocateProtocol
service from the EFI_BOOT_SERVICES
table is used to get the PCD_PROTOCOL
interface. After this, a function from PcdProtocol
will be called: (PcdProtocol->Get8)(0x2C4)
.
Usage of EFI_BOOT_SERVICES
and EFI_RUNTIME_SERVICES
is unsafe inside a code intended to run in the SMM (from SMRAM), especially in SMI handlers, because an attacker capable of executing code in DXE phase could exploit this vulnerability to escalate privileges to SMM (ring -2).
To exploit this vulnerability it is enough to:
"GFCU"
)EFI_BOOT_SERVICES
table in system memory.LocateProtocol()
service pointer in it with the shellcode address.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