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

[BRLY-LOGOFAIL-2023-020] 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-39538

Summary

BINARLY efiXplorer team has discovered a lack of array index validation leading to OOB Write operations on global data during JPEG file processing in AMI firmware.

Vendors Affected

Affected Products

ThinkCentre M75q Gen 2
,

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 a lack of array index validation leading to OOB Write operations on global data during JPEG file processing in AMI firmware.

Vulnerability Information

     
  • BINARLY internal vulnerability identifier: BRLY-LOGOFAIL-2023-020  
  • AMI PSIRT assigned CVE identifier: CVE-2023-39538  
  • 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
AMITSE b1da0adf-4f77-4070-a88e-bffe1c60529a 439e73d391b7f7540f6faa58afdc2722bda250468d4a4f7f5f84228c1f77ddbe

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 CreateHuffmanTable(WORD *a1, BYTE *a2)
{
  int v2; // ebx
  WORD v3; // r10
  __int64 index; // r8
  BYTE *v5; // rdx
  unsigned __int8 v6; // r11
  BYTE *v7; // rdi
  int v8; // r9d
  __int64 index_plus_1; // r8
  WORD v10; // ax
  __int64 result; // rax

  v2 = 0;
  v3 = 0;
  index = 0i64;
  v5 = a2 + 1;
  v6 = 1;
  v7 = v5;
  do
  {
    v8 = *v5;
    if ( *v5 )
    {
      v2 += v8 + 2 * v8;
      do
      {
        // BRLY-LOGOFAIL-2023-020: index is not checked and can lead to OOB write to the statically-allocated global buffer pointer by a1
        a1[index] = v6;
        --v8;
        index_plus_1 = index + 1;
        a1[index_plus_1++] = v3;
        v10 = v7[16];
        ++v3;
        ++v7;
        a1[index_plus_1] = v10;
        index = index_plus_1 + 1;
      }
      while ( v8 > 0 );
    }
    v3 *= 2;
    ++v5;
    ++v6;
  }
  while ( v6 <= 0x10u );
  result = v2;
  a1[v2] = 17;
  return result;
}

As we can see from the pseudocode, the index variable is used to access the array pointed by a1 without any bounds checking. The attacker indirectly controls index since it is incremented on every iteration of the loop depending on v8 which is read directly from the attacker controlled image. Since this function receives a statically allocated array:

...
v15 = &unk_96580;
result = CreateHuffmanTable(v15, *v13);
...

the attacker can write after the end of this array and corrupt other global data.

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
AMI PSIRT confirmed reported issues 2023-10-05
AMI PSIRT assigned CVE ID 2023-12-01
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