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 BIOS. Such a malicious firmware code in BIOS could persist across operating system re-installs. Additionally, this vulnerability potentially could be used by malicious actors to bypass security mechanisms provided by UEFI firmware (for example, Secure Boot and some types of memory isolation for hypervisors).
Binarly REsearch Team has discovered SMM memory corruption vulnerability on Intel platforms 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 evironment 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 BIOS. Such a malicious firmware code in BIOS could persist across operating system re-installs. Additionally, this vulnerability potentially could be used by malicious actors to bypass security mechanisms provided by UEFI firmware (for example, Secure Boot and some types of memory isolation for hypervisors).
The vulnerability exists in child SW SMI handler registered with GUID 24249387-8cbf-437c-9a21-d6410a42d7f2
and located at offset 0x18B8
in the binary.The pseudocode for this handler is shown below:
EFI_STATUS __fastcall SmiHandler(
EFI_HANDLE DispatchHandle,
const void *Context,
void *CommBuffer,
UINTN *CommBufferSize)
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
if ( CommBuffer && CommBufferSize )
{
Res = *(_DWORD *)CommBuffer < 8;
Value = *((_BYTE *)CommBuffer + 4);
if ( !Res )
goto _InvalidParameter;
if ( *(_DWORD *)CommBuffer )
{
switch ( *(_DWORD *)CommBuffer )
{
case 1:
goto _Case1;
case 2:
goto _Case2;
case 3:
goto _Case1;
case 4:
goto _Case2;
case 5:
_Case1:
Flag = 0;
_HpPolicy:
status = HpPolicy(&Value, *(_DWORD *)CommBuffer, *((_QWORD *)CommBuffer + 2));
if ( Flag && !status )
*((_BYTE *)CommBuffer + 4) = Value;
goto _Exit;
}
if ( *(_DWORD *)CommBuffer != 6 )
{
if ( *(_DWORD *)CommBuffer == 7 )
goto _Case1;
_InvalidParameter:
status = EFI_INVALID_PARAMETER;
_Exit:
*((_QWORD *)CommBuffer + 1) = status;
return 0;
}
}
_Case2:
Flag = 1;
goto _HpPolicy;
}
return 0;
}
Before SMI handler will be triggered, CommBuffer will be checked for overlap with SMRAM (inside PiSmmCommunicationSmm
module):
EFI_STATUS __fastcall SwSmiHandler(
EFI_HANDLE DispatchHandle,
const void *Context,
void *CommBuffer,
UINTN *CommBufferSize)
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
Status = 0;
CommunicationHeader = *gCommunicationHeader;
if ( *gCommunicationHeader )
{
if ( SmmIsBufferOutsideSmmValid(*gCommunicationHeader, 24) )
{
CommBufferSizea[0] = CommunicationHeader->MessageLength;
if ( SmmIsBufferOutsideSmmValid(CommunicationHeader->Data, CommBufferSizea[0]) )
Status = gSmst->SmiManage(
&CommunicationHeader->HeaderGuid,
0,
CommunicationHeader->Data,
CommBufferSizea);
}
}
return -(Status != 0) & 0xA000000000000000;
}
If CommunicationHeader->MessageLength
is 0
and CommunicationHeader->Data
does not overlap with SMRAM, check will pass.
As we can see from the pseudocode, *CommBufferSize
is not checked (only the CommBufferSize
pointer is compared to NULL). But at the same time there is a primitive for writing 8 fixed bytes at the address CommBuffer + 8:
*((_QWORD *)CommBuffer + 1) = status;
return 0;
This leads to rewriting pointed area with a predictable data - Status code.Writing such data into SMRAM could allow a possible attacker to corrupt some structures in 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.
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