Header bannerHeader banner
Advisory ID:
BRLY-LOGOFAIL-2023-002

[BRLY-LOGOFAIL-2023-002] Memory Corruption vulnerability in DXE driver

June 20, 2024
Severity:
High
CVSS Score
8.2
Public Disclosure Date:
June 19, 2024

Summary

Binarly REsearch Team has discovered an OOB Write vulnerability in the RLE8 decode routine during BMP file processing in Insyde firmware.

Vendors Affected

Lenovo
Insyde

Affected Products

Yoga 7 14IAL7

Potential Impact

An attacker with local access can exploit this vulnerability to elevate privileges from ring 3 or ring 0 (depends on the operating system) to a DXE driver and execute arbitrary code. Malicious code installed as a result of this exploitation could survive operating system (OS) boot process and runtime, or modify NVRAM area on the SPI flash storage (to gain persistence). Additionally, threat actors could use this vulnerability to bypass OS security mechanisms (modify privileged memory or runtime variables), influence OS boot process, and in some cases allow an attacker to hook or modify EFI Runtime services.

Summary

Binarly REsearch Team has discovered an OOB Write vulnerability in the RLE8 decode routine during BMP file processing in Insyde firmware.

Vulnerability Information

     
  • BINARLY internal vulnerability identifier: BRLY-LOGOFAIL-2023-002  
  • Insyde PSIRT assigned CVE identifier: CVE-2023-40238  
  • CVSS v3.1: 8.2 High AV:L/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H

Affected modules with confirmed impact by Binarly REsearch Team

Module name Module GUID Module SHA256
BmpDecoderDxe a9f634a5-29f1-4456-a9d5-6e24b88bdb65 02034e3bdc02ef843651611c1f97f8f2a1deb0be78f9085ac40077eba4260128

Potential impact

An attacker with local access can exploit this vulnerability to elevate privileges from ring 3 or ring 0 (depending on the operating system) to a DXE driver and execute arbitrary code. Malicious code installed as a result of this exploitation could survive operating system (OS) boot process and runtime, or modify NVRAM area on the SPI flash storage (to gain persistence). Additionally, threat actors could use this vulnerability to bypass OS security mechanisms (modify privileged memory or runtime variables), influence OS boot process, and in some cases allow an attacker to hook or modify EFI Runtime services.

Vulnerability description

The pseudocode of the vulnerable function is shown below:

__int64 __fastcall DecodeRLE8(
        EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltOutput,
        unsigned __int8 *a2,
        __int64 a3,
        BMP_IMAGE *Image)
{
  unsigned __int64 PixelHeight; // rax
  char v5; // r15
  unsigned __int64 i; // r11
  __int64 PixelWidth; // rbx
  unsigned __int64 v11; // r9
  char v12; // bp
  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltEntry; // r8
  __int64 v14; // rax
  unsigned __int8 *v15; // rsi
  __int64 v16; // r10
  __int64 v17; // rcx
  char v18; // si
  __int64 v19; // rax

  PixelHeight = Image->BmpHeader.PixelHeight;
  v5 = 0;
  for ( i = 0i64; i <= PixelHeight; ++i )
  {
    if ( v5 )
      break;
    PixelWidth = Image->BmpHeader.PixelWidth;
    v11 = 0i64;
    v12 = 0;
    // BRLY-LOGOFAIL-2023-002
    BltEntry = &BltOutput[PixelWidth * (PixelHeight - i - 1)];
    do
    {
      if ( v12 )
        break;
      v14 = *a2;
      v15 = a2 + 1;
      v16 = a2[1];
      a2 += 2;
      if ( (_BYTE)v14 )
      {
        v17 = (unsigned int)v14;
        v11 += v14;
        do
        {
          BltEntry->Red = *(_BYTE *)(a3 + 4 * v16 + 2);// arbitrary write
          BltEntry->Green = *(_BYTE *)(a3 + 4 * v16 + 1);// arbitrary write
          BltEntry->Blue = *(_BYTE *)(a3 + 4 * v16);// arbitrary write
          ++BltEntry;
          --v17;
        }
        while ( v17 );
      }
      else if ( (_BYTE)v16 )
      {
        if ( (_DWORD)v16 == 1 )
        {
          v5 = 1;
          v12 = 1;
        }
        else if ( (_DWORD)v16 == 2 )
        {
          v11 += *a2;
          i += v15[2];
          a2 = v15 + 3;
          BltEntry = &BltOutput[v11 + (unsigned int)PixelWidth * (Image->BmpHeader.PixelHeight - i - 1)];
        }
        else
        {
          v11 += v16;
          v18 = v16;
          do
          {
            v19 = *a2++;
            BltEntry->Red = *(_BYTE *)(a3 + 4 * v19 + 2);
            BltEntry->Green = *(_BYTE *)(a3 + 4i64 * (unsigned int)v19 + 1);
            BltEntry->Blue = *(_BYTE *)(a3 + 4i64 * (unsigned int)v19);
            ++BltEntry;
            --v16;
          }
          while ( v16 );
          if ( (v18 & 1) != 0 )
            ++a2;
        }
      }
      else
      {
        v12 = 1;
      }
      LODWORD(PixelWidth) = Image->BmpHeader.PixelWidth;
    }
    while ( v11 <= (unsigned int)PixelWidth );
    PixelHeight = Image->BmpHeader.PixelHeight;
  }
  return 0i64;
}
Where DecodeRLE8 function will be called from the DecodeBMP function:
if ( Image->BmpHeader.CompressionType == 1 )
{
    if ( v18 )
      sub_330(*a3, v18, 0i64);
    DecodeRLE8(v22, v17, &Image->field_36, Image);
    return 0i64;
}
}

As we can see from the pseudocode, when BmpHeader->PixelHeight (controllable by the attacker) is equal to 0, BltEntry pointer will be located below BltOutput pointer ( (0 - 0 - 1) * BmpHeader->PixelWidth = - BmpHeader->PixelWidth). Thus, by subsequent write operations, a potential attacker can write data to a controllable address (in the physical memory below BltOutput address). This vulnerability could lead to the execution of arbitrary code during the DXE phase.

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 (YYYY-mm-dd)
Lenovo PSIRT is notified 2023-06-21
Lenovo ID (LEN-132940) is assigned 2023-06-22
CERT/CC is notified 2023-07-10
Insyde PSIRT confirmed reported issues 2023-09-10
Insyde PSIRT assigned CVE ID 2023-11-27
Insyde advisory release date 2023-12-06
BINARLY public disclosure date 2024-06-19

Acknowledgements

BINARLY efiXplorer team

Tags
Vulnerability
supply chain
FWHunt
See if you are impacted now with our Firmware Vulnerability Scanner