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

[BRLY-LOGOFAIL-2023-005] Out-of-bounds Read in DXE driver

June 20, 2024
Severity:
Low
CVSS Score
3.2
Public Disclosure Date:
June 19, 2024

Summary

Binarly REsearch Team has discovered a OOB Read vulnerability in Insyde firmware resulting from weak index checking during GIF file processing.
Vendors Affected Icon

Vendors Affected

Lenovo
Insyde
Affected Products icon

Affected Products

Yoga 7 14IAL7

Potential Impact

This vulnerability will not lead to exploitation, however, it may lead to unexpected behaviour during GIF file processing.

Summary

Binarly REsearch Team has discovered a OOB Read vulnerability in Insyde firmware resulting from weak index checking during GIF file processing.

Vulnerability Information

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

Affected modules with confirmed impact by Binarly REsearch Team

Module name Module GUID Module SHA256
GifDecoderDxe 1353de63-b74a-4bef-80fd-2c5cfa83040b 9d8b18a89f6b83d3e7b7ea68587415fce6d9f4f4f819ab0f2f068e48e68f7924

Potential impact

This vulnerability will not lead to exploitation, however, it may lead to unexpected behaviour during GIF file processing.

Vulnerability description

The pseudocode of the vulnerable function is shown below:

__int64 __fastcall DecodeLZW(
        char *Image,
        unsigned __int64 ImageSize,
        char a3,
        __int64 a4,
        unsigned __int16 a5,
        unsigned __int16 a6,
        __int64 a7)
{
  HeapStruct *v7; // r13
  char Value; // cl
  char *Image1; // r11
  unsigned __int16 Bound; // bx
  unsigned __int8 Total; // r9
  __int16 v13; // di
  unsigned __int16 v14; // r12
  unsigned __int8 v15; // si
  unsigned int v16; // r10d
  unsigned __int16 v17; // r15
  unsigned __int16 v18; // r8
  unsigned __int16 Index; // cx
  HeapStruct *HeapArrayEntry; // rax
  unsigned __int16 v21; // bp
  _BYTE *v22; // r14
  unsigned __int64 v23; // rax
  char v24; // cl
  unsigned __int16 v25; // r11
  __int16 v26; // r9
  unsigned __int16 v27; // ax
  unsigned __int16 v28; // ax
  __int64 v29; // rdx
  __int64 v30; // rax
  __int64 v31; // rdx
  char v33; // [rsp+0h] [rbp-68h]
  unsigned __int8 v34; // [rsp+1h] [rbp-67h]
  unsigned __int16 v35; // [rsp+2h] [rbp-66h]
  __int16 v36; // [rsp+4h] [rbp-64h]
  __int16 v37; // [rsp+6h] [rbp-62h]
  unsigned __int16 v38; // [rsp+8h] [rbp-60h]
  unsigned __int16 v39; // [rsp+10h] [rbp-58h]
  char *v40; // [rsp+70h] [rbp+8h]

  v7 = HeapArray;
  Value = *Image;
  Image1 = Image + 1;
  Bound = 1 << Value;
  v40 = Image1;
  v39 = Bound;
  Total = Value + 1;
  v36 = -1;
  v37 = (1 << Value) + 1;
  v13 = -1;
  v34 = Value + 1;
  v38 = (1 << Value) + 2;
  v14 = v38;
  v35 = v38;
  v15 = Value + 1;
  v33 = Value + 1;
  v16 = 0;
  v17 = 0;
  v18 = 0;
  Index = 0;
  if ( Bound )
  {
    HeapArrayEntry = HeapArray;
    do
    {
      HeapArrayEntry->field_2 = Index++;
      HeapArrayEntry->field_0 = -1;
      HeapArrayEntry = (HeapArrayEntry + 4);
    }
    while ( Index < Bound );
    v7 = HeapArray;
  }
  // BRLY-LOGOFAIL-2023-005: Weak index checking leads to OOB Read
  if ( Total >> 3 <= ImageSize )
  {
    v21 = a6;
    v22 = qword_1D50;
    do
    {
      v23 = v16 >> 3;
      v24 = v16 & 7;
      v16 += v15;
      v25 = ((1 << v15) - 1) & (*&Image1[v23] >> v24);
      if ( v25 == v37 )
        return v16;
      if ( v25 == Bound )
      {
        v14 = v38;
        v15 = Total;
        v35 = v38;
        v13 = Bound;
        v33 = Total;
        v36 = Bound;
        goto LABEL_40;
      }
      if ( v18 == v21 )
        return v16;
      v26 = -1;
      if ( v25 >= v14 )
      {
        if ( v13 == Bound )
          goto LABEL_44;
        v26 = 0;
        v28 = v13;
        if ( v13 != -1 )
        {
          do
          {
            v22[++v26] = *(&v7->field_2 + 4 * v28);
            v28 = *(&v7->field_0 + 2 * v28);
          }
          while ( v28 != 0xFFFF );
          v15 = v33;
          v21 = a6;
        }
        *v22 = v22[v26];
      }
      else
      {
        v27 = v25;
        if ( v25 != 0xFFFF )
        {
          do
          {
            v22[++v26] = *(&v7->field_2 + 4 * v27);
            v27 = *(&v7->field_0 + 2 * v27);
          }
          while ( v27 != 0xFFFF );
          v21 = a6;
        }
        if ( v13 == Bound )
          goto LABEL_23;
      }
      v29 = v14++;
      v35 = v14;
      *(&v7->field_0 + 2 * v29) = v13;
      *(&v7->field_2 + 4 * v29) = v22[v26];
LABEL_23:
      if ( v26 >= 0 )
      {
        do
        {
          v30 = v26--;
          v31 = v22[v30];
          LODWORD(v30) = v17++;
          *(a7 + 4i64 * (v30 + a5 * v18)) = *(a4 + 4 * v31);
          if ( v17 == a5 )
          {
            if ( a3 )
            {
              if ( (v18 & 7) != 0 )
              {
                if ( (v18 & 3) != 0 )
                {
                  if ( (v18 & 1) != 0 )
                  {
                    v18 += 2;
                  }
                  else
                  {
                    v18 += 4;
                    if ( v18 >= v21 )
                      v18 = 1;
                  }
                }
                else
                {
                  v18 += 8;
                  if ( v18 >= v21 )
                    v18 = 2;
                }
              }
              else
              {
                v18 += 8;
                if ( v18 >= v21 )
                  v18 = 4;
              }
            }
            else
            {
              ++v18;
            }
            v17 = 0;
            if ( v18 == v21 )
              break;
          }
        }
        while ( v26 >= 0 );
        Bound = v39;
        v13 = v36;
        v15 = v33;
        v14 = v35;
        v7 = HeapArray;
      }
LABEL_40:
      if ( v14 < 1 << v15 )
        goto LABEL_43;
      if ( v15 < 0xCu )
      {
        v33 = ++v15;
LABEL_43:
        v13 = v25;
        v36 = v25;
      }
LABEL_44:
      Total = v34;
      Image1 = v40;
    }
    while ( (v16 + v15) >> 3 <= ImageSize );
  }
  return v16;
}

The check Total >> 3 <= ImageSize is incomplete since 4 bytes will be obtained from Image + Total / 8. Therefore, the last iteration of the loop will always lead to read operation outside of the allocated Image buffer.

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