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

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

June 20, 2024
Severity:
High
CVSS Score
8.2
Public Disclosure Date:
June 19, 2024
CVE ID:
CVE-2023-40238

Summary

BINARLY efiXplorer team has discovered an OOB Write vulnerability in the RLE4 decode routine during BMP file processing in Insyde firmware.

Vendors Affected

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 efiXplorer team has discovered an OOB Write vulnerability in the RLE4 decode routine during BMP file processing in Insyde firmware.

Vulnerability Information

     
  • BINARLY internal vulnerability identifier: BRLY-LOGOFAIL-2023-003  
  • 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 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 DecodeRLE4(
        EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltOutput,
        unsigned __int8 *a2,
        __int64 a3,
        BMP_IMAGE *Image)
{
  unsigned __int64 PixelHeight; // rax
  char v5; // r12
  __int64 v6; // rdi
  __int64 PixelWidth; // rbx
  unsigned __int64 v12; // r11
  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltEntry; // r9
  char v14; // r15
  __int64 v15; // rcx
  unsigned __int8 *v16; // r14
  int v17; // r8d
  unsigned __int64 v18; // rdx
  unsigned __int64 v19; // r8
  __int64 v20; // rcx
  __int64 v21; // rcx
  __int16 v22; // ax
  __int64 v23; // rbx
  unsigned int v24; // eax
  unsigned __int8 v25; // dl
  unsigned __int64 v26; // rcx
  char v28; // [rsp+49h] [rbp+21h]

  PixelHeight = Image->BmpHeader.PixelHeight;
  v5 = 0;
  v6 = 0i64;
  while ( !v5 )
  {
    PixelWidth = Image->BmpHeader.PixelWidth;
    v12 = 0i64;
    BltEntry = &BltOutput[PixelWidth * (PixelHeight - v6 - 1)];
    v14 = 0;
    while ( !v14 )
    {
      v15 = *a2;
      v16 = a2 + 1;
      v17 = a2[1];
      a2 += 2;
      if ( (_BYTE)v15 )
      {
        v18 = (unsigned int)v15;
        v28 = (unsigned __int8)v17 >> 4;
        v19 = 0i64;
        v12 += v15;
        do
        {
          v20 = v19++ & 1;
          v21 = (unsigned __int8)*(&v28 - v20);
          BltEntry->Red = *(_BYTE *)(a3 + 4 * v21 + 2);
          BltEntry->Green = *(_BYTE *)(a3 + 4 * v21 + 1);
          BltEntry->Blue = *(_BYTE *)(a3 + 4 * v21);
          ++BltEntry;
        }
        while ( v19 < v18 );
      }
      else
      {
        if ( (_BYTE)v17 )
        {
          if ( v17 != 1 )
          {
            if ( v17 == 2 )
            {
              v12 += *a2;
              v6 += v16[2];
              a2 = v16 + 3;
              // BRLY-LOGOFAIL-2023-003
              BltEntry = &BltOutput[v12 + (unsigned int)PixelWidth * (Image->BmpHeader.PixelHeight - v6 - 1)];
            }
            else
            {
              v22 = (v17 - 1) / 4 + 1;
              v23 = (unsigned __int16)(2 * v22);
              if ( 2 * v22 )
              {
                do
                {
                  v24 = *a2++;
                  v25 = v24 & 0xF;
                  if ( (_BYTE)v17 )
                  {
                    ++v12;
                    v26 = (unsigned __int64)v24 >> 4;
                    BltEntry->Red = *(_BYTE *)(a3 + 4 * v26 + 2); // arbitrary write
                    BltEntry->Green = *(_BYTE *)(a3 + 4 * v26 + 1); // arbitrary write
                    BltEntry->Blue = *(_BYTE *)(a3 + 4 * v26); // arbitrary write
                    ++BltEntry;
                    LOBYTE(v17) = v17 - 1;
                    if ( (_BYTE)v17 )
                    {
                      ++v12;
                      BltEntry->Red = *(_BYTE *)(a3 + 4i64 * v25 + 2);
                      BltEntry->Green = *(_BYTE *)(a3 + 4i64 * v25 + 1);
                      BltEntry->Blue = *(_BYTE *)(a3 + 4i64 * v25);
                      ++BltEntry;
                      LOBYTE(v17) = v17 - 1;
                    }
                  }
                  --v23;
                }
                while ( v23 );
              }
            }
            goto LABEL_21;
          }
          v5 = 1;
        }
        v14 = 1;
      }
LABEL_21:
      LODWORD(PixelWidth) = Image->BmpHeader.PixelWidth;
      if ( v12 > (unsigned int)PixelWidth )
        break;
    }
    PixelHeight = Image->BmpHeader.PixelHeight;
    if ( ++v6 > PixelHeight )
      return 0i64;
  }
  return 0i64;
}

Where DecodeRLE4 function will be called from the DecodeBMP function:

if ( Image->BmpHeader.CompressionType == 2 )
{
    if ( v18 )
      sub_330(*a3, v18, 0i64);
    DecodeRLE4(v22, v17, (__int64)&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