Binarly Advisories

REsearch

Binarly Advisories

[BRLY-2021-010] SMM memory corruption vulnerability in combined DXE/SMM driver on Fujitsu device (SMRAM write)

Summary

BINARLY efiXplorer 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.

Vulnerability Information

Affected Fujitsu firmwares with confirmed impact by BINARLY team

Device name Driver name Driver SHA256 File GUID
Fujitsu LIFEBOOK A3510 NvmExpressDxe B36A7A71C065C1C3307BB86192667C1CB798DB849B1B86BE3408BFA4FBC53868 5BE3BDF4-53CF-46A3-A6A9-73C34A6E5EE3

Potential impact

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).

Vulnerability description

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:

  1. Find 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).
  2. A pointer to a place to write in SMRAM should be specified at offset 0x10 inside gUnknownProtocol.
  3. Communication buffer should be at gUnknownProtocol location, so a pointer to it should be placed into UEFI ACPI table.
  4. Call SW SMI (SwSmi number is specified in UEFI ACPI table) via 0xB2 IO port, prior to it SMI handler GUID 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.

Disclosure timeline

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.

Disclosure Activity Date
Fujitsu PSIRT is notified 2021-09-10
Fujitsu PSIRT is confirmed issue 2021-09-14
CERT/CC created a case 2021-09-27
Insyde PSIRT assigned CVE number 2021-11-01
Insyde PSIRT provide patch release 2021-11-09
BINARLY public disclosure date 2022-02-01

Acknowledgements

BINARLY efiXplorer team

Tag list
Back to overview