An attacker with high 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.
Binarly REsearch Team has discovered a stack overflow vulnerability that allows a potential attacker to access UEFI DXE driver and execute arbitrary code.
An attacker with high 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.
Let's take Latitude 9520's firmware (version: 0.1.17.0, module sha256: 3d3150a82da8f1e143f85bfe50d894a735886c243b3dd93209b1346ad200c054) as an example.
The following code in the module actually allows to overflow a stack buffer:
gRT->GetVariable()
offset: 0xb2ad
gRT->GetVariable()
offset: 0xb2d5
char sub_B220()
{
__int64 v0; // rbx
char result; // al
char v2; // dl
unsigned __int8 v3; // bl
char v4; // dl
int v5; // ecx
int v6; // edx
int v7; // ecx
unsigned __int8 v8; // bl
char v9; // dl
void *Interface; // [rsp+30h] [rbp-40h] BYREF
__int64 Data; // [rsp+38h] [rbp-38h] BYREF
__int64 v12; // [rsp+40h] [rbp-30h]
char v13[8]; // [rsp+48h] [rbp-28h]
__int64 v14; // [rsp+50h] [rbp-20h] BYREF
__int64 v15; // [rsp+58h] [rbp-18h]
char v16; // [rsp+60h] [rbp-10h]
int v17; // [rsp+90h] [rbp+20h] BYREF
UINTN DataSize; // [rsp+98h] [rbp+28h] BYREF
int v19; // [rsp+A0h] [rbp+30h] BYREF
__int16 v20; // [rsp+A4h] [rbp+34h]
char v21; // [rsp+A6h] [rbp+36h]
void *HeciProtocol; // [rsp+A8h] [rbp+38h] BYREF
Data = 0i64;
v12 = 0i64;
v13[0] = 0;
v14 = 0i64;
v15 = 0i64;
v16 = 0;
v19 = 0;
v20 = 0;
v21 = 0;
v0 = gBS->LocateProtocol(&HECI_PROTOCOL_GUID, 0i64, &Interface);
result = sub_FF2C();
if ( !result && v0 >= 0 )
{
DataSize = 17i64;
gRT->GetVariable( // <= first call (we can rewrite DataSize here)
L"MeSetupStorage",
&ME_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
&Data);
gRT->GetVariable( // <= second call
L"MeBackupStorage",
&ME_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
&v14);
DataSize = 143i64;
gRT->GetVariable(L"MeSetup", &ME_SETUP_VARIABLE_GUID, 0i64, &DataSize, &unk_A0F80);
DataSize = 7i64;
gRT->GetVariable(L"TcgSetup", &EFI_SETUP_VARIABLE_GUID, 0i64, &DataSize, &v19);
if ( BYTE4(v12) != BYTE4(v15) && !byte_A0FAA && BYTE4(v12) == 1 )
sub_F120();
if ( BYTE2(Data) != BYTE2(v14) )
{
byte_A0891 = 1;
if ( BYTE2(Data) )
{
sub_F320();
}
else if ( (gBS->LocateProtocol(&HECI_PROTOCOL_GUID, 0i64, &HeciProtocol) & 0x8000000000000000ui64) == 0i64 )
{
(*(HeciProtocol + 8))(&v17);
if ( v17 != 3 && !sub_FF2C() )
sub_ED6C(6, v2, 0);
}
}
v3 = BYTE1(Data);
if ( BYTE1(Data) != BYTE1(v14) && !sub_FF2C() )
sub_ED6C(7, v4, v3);
if ( Data != v14 )
{
byte_A0891 = 1;
if ( Data == 1 )
{
v5 = 4;
v6 = 0;
}
else
{
v5 = 0;
v6 = 4;
}
sub_F414(v5, v6);
}
v7 = byte_A0891;
v8 = BYTE6(Data);
if ( BYTE5(Data) != BYTE5(v14) )
v7 = 1;
byte_A0891 = v7;
if ( BYTE6(Data) != BYTE6(v14) && v19 == 1 && !sub_FF2C() )
sub_ED6C(47, v9, v8);
LOBYTE(v7) = BYTE2(v12);
if ( BYTE2(v12) != BYTE2(v15) )
{
byte_A0891 = 1;
sub_EF84(SBYTE2(v12));
}
if ( BYTE3(v12) != BYTE3(v15) )
sub_F5C0(BYTE3(v12));
if ( HIBYTE(v12) != HIBYTE(v15) )
sub_FBAC(v7, SHIBYTE(v12));
if ( v13[0] != v16 )
sub_FD30(v7, v13[0]);
return gRT->SetVariable(L"MeBackupStorage", &ME_SETUP_VARIABLE_GUID, 2u, 0x11ui64, &Data);
}
return result;
}
The DataSize
is initialized only once (before the first call to gRT->GetVariable()
service).
If the length of MeSetupStorage
NVRAM variable is greater than 17
, the second call to gRT->GetVariable()
service will overflow a stack buffer, which in turn could lead to arbitrary code execution.
To fix this vulnerability the DataSize
must be re-initialized with the size of MeBackupStorage
before calling gRT->GetVariable()
.
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.
Binarly REsearch Team