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 could potentially be used by threat 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 a SMM memory corruption vulnerability in a Fujitsu device 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 could potentially be used by threat actors to bypass security mechanisms provided by UEFI firmware (for example, Secure Boot and some types of memory isolation for hypervisors).
First, let's look at a routine located at offset 0x29C8
in the NvmExpressDxe
driver. Its DXE branch (code intended to be executed during DXE phase) allocates a buffer for a protocol in the system memory:
if ( IsSmstFound() )
{
// SMM branch
...
}
else
{
// DXE branch
result = gEfiBootServices->AllocatePool(EfiReservedMemoryType, 0x38, &gBuffer);
if ( result >= 0 )
{
gCommBuffer = gBuffer;
gCommSize = 0x38;
ZeroMemory((char *)gBuffer, 0x38);
...
gUnknownProtocol = (char *)gCommBuffer + 0x18;
...
v6 = sub_80002FE8(0x38ui64);
gCommBuffer_plus10_val = v6;
if ( !v6 )
return 0x8000000000000009;
*((_QWORD *)v6 + 2) = 'IPVN';
...
gEfiBootServices->InstallProtocolInterface((EFI_HANDLE *)&UnknownProtocolEffb22f6, &gUnknownProtocolGuid, EFI_NATIVE_INTERFACE, gUnknownProtocol);
...
}
The SMM branch (code intended to be executed in System Management Mode) of this function extracts the pointer to the buffer and registers a child software System Management Interrupt (SWSMI) handler with GUID 52c78312-8edc-4233-98f2-1a1aa5e388a5
, which contains the actual vulnerability:
if ( IsSmstFound() )
{
// SMM branch
gEfiBootServices->LocateProtocol(&gUnknownProtocolGuid, 0i64, &gUnknownProtocol);
v7 = 0;
gSmst->SmiHandlerRegister(SmiHandler, &gSmiHandlerGuid, &v7);
}
else
{
// DXE branch
...
}
The SMI handler itself is located at offset 0x2F90
in the driver:
EFI_STATUS SmiHandler(EFI_HANDLE DispatchHandle, void *Context, void *CommBuffer, UINTN *CommBufferSize)
{
if ( gUnknownProtocol == CommBuffer && *CommBufferSize == 0x20 && CommBuffer )
{
gCommBuffer_plus10_val = *((_QWORD *)CommBuffer + 2);
if ( *(_QWORD *)CommBuffer == 1 )
{
result = sub_8000358C();
if ( (result & 0x8000000000000000) != 0 )
return result;
}
else
{
if ( *(_QWORD *)CommBuffer != 3 )
return 0x8000000000000003;
sub_80003484();
}
}
return 0;
}
Obviously, an attacker can craft the Communication Buffer contents to enter the sub_8000358C()
routine that starts with the following code:
for ( ptr = ReadQword(gCommBuffer_plus10_val); ; ptr = ReadQword2(gCommBuffer_plus10_val, ptr_1) )
{
if ( Compare(gCommBuffer_plus10_val, ptr) )
break;
v2 = *(_QWORD *)(ptr - 16);
if ( !*(_BYTE *)(ptr - 8) )
{
*(_QWORD *)(ptr - 0x1D0) = 04;
if ( *(_BYTE *)(*(_QWORD *)(v2 + 192) + 256) & 1 )
{
*(_QWORD *)(ptr - 208) = sub_80004F70;
*(_QWORD *)(ptr - 200) = sub_800050FC;
...
ReadQword()
routine is used to dereference the input pointer.
As we can see, some ptr
is set in a loop from a buffer pointed by gCommBuffer_plus10_val
(which was previously retrieved from Communication Buffer), and if a simple validation is successful some data will be written into a location relative to ptr
. There is no pointer validation carried out (to ensure ptr
and any other Communication Buffer nested contents are not pointing to SMRAM contents).
Since this buffer is placed in the system memory a possible attacker can find it and control its contents. Writing fixed data into SMRAM could allow a possible attacker to corrupt some data inside this memory (for example, change SMI handler's code or modify Smram Map structures to break input pointer validation for other SMI handlers, hence to completely make this mitigation inefficient). This could lead to gaining arbitrary code execution in SMM.
To exploit this vulnerability it is enough to:
gUnknownProtocol
in system memory (with NVPI
signature or by dumping & analyzing physical memory from exactly the same device model with exactly the same firmware version).gUnknownProtocol
.gUnknownProtocol
location, so a pointer to it should be placed into UEFI ACPI table.52c78312-8edc-4233-98f2-1a1aa5e388a5
and Communication Buffer size 0x20
should be specified in Communication Buffer.To fix this vulnerability, it is essential to wrap all the input pointers (including the nested pointers) for SMI handlers 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