An attacker with high local access can exploit this vulnerability to read the contents of stack memory or global memory. This information could help with exploitation of other vulnerabilities in DXE 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.
Binarly REsearch Team has discovered a memory contents leak / information disclosure vulnerability that allows a potential attacker to dump stack memory or global memory into an NVRAM variable. This in turn could help building a successful attack vector based on exploiting a memory corruption vulnerability.
An attacker with high local access can exploit this vulnerability to read the contents of stack memory or global memory. This information could help with explotation of other vulnerabilities in DXE 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 9420, Latitude 9420's firmware (version: 0.1.16.2, module sha256: 22c8db2e39fa0ad26f38e77f32a2e86d16e50465654ffeb9a0124006d1584fc2) as an example.
The following code in the module actually allows leaking memory:
gRT->GetVariable()
offset: 0x61f
gRT->SetVariable()
offset: 0x754
void __fastcall NotifyFunction(EFI_CAPSULE_HEADER **Event, void *Context)
{
unsigned __int64 i; // rdi
__int64 v4; // r8
__int64 v5; // r8
__int64 v6; // rax
unsigned __int64 v7; // [rsp+40h] [rbp-9h] BYREF
__int64 v8; // [rsp+48h] [rbp-1h] BYREF
__int64 v9; // [rsp+50h] [rbp+7h] BYREF
__int64 v10; // [rsp+58h] [rbp+Fh] BYREF
__int64 v11; // [rsp+60h] [rbp+17h] BYREF
__int64 v12; // [rsp+68h] [rbp+1Fh] BYREF
char *v13; // [rsp+70h] [rbp+27h] BYREF
_BYTE v14[16]; // [rsp+78h] [rbp+2Fh] BYREF
__int64 v15[3]; // [rsp+88h] [rbp+3Fh] BYREF
unsigned __int16 v16; // [rsp+C0h] [rbp+77h] BYREF
int v17; // [rsp+C8h] [rbp+7Fh] BYREF
v12 = 0i64;
v8 = 0i64;
v9 = 0i64;
v10 = 0i64;
v11 = 0i64;
v17 = 0;
if ( ((__int64 (__fastcall *)(__int64, EFI_GUID *, _QWORD, unsigned __int64 *, __int64 *))gBS->LocateHandleBuffer)(
2i64,
&EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID,
0i64,
&v7,
v15) >= 0
&& v7 )
{
v9 = 15i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, __int64 *, _BYTE *))gRT->GetVariable)(// <= first call (we can rewrite DataSize here)
L"MPDTContent",
&NameGuid,
0i64,
&v9,
v14);
for ( i = 0i64; i < v7; ++i )
{
if ( ((__int64 (__fastcall *)(_QWORD, EFI_GUID *, __int64 *))gBS->HandleProtocol)(
*(_QWORD *)(v15[0] + 8 * i),
&EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID,
&v11) < 0 )
goto LABEL_18;
LOBYTE(v4) = 25;
if ( (*(__int64 (__fastcall **)(__int64, EFI_GUID *, __int64, _QWORD, __int64 *, __int64 *, int *))(v11 + 24))(
v11,
&NameGuid,
v4,
0i64,
&v12,
&v8,
&v17) >= 0 )
{
((void (__fastcall *)(__int64, __int64, __int64 *))gBS->AllocatePool)(4i64, v8, &v10);
v10 = v12;
v13 = 0i64;
v16 = 0;
if ( v12 )
{
v6 = sub_C58(v14[1], v12, v8, &v16, (unsigned int **)&v13, v12);
if ( v6 >= 0 )
{
if ( v13 )
v6 = sub_EF8(v13, v16);
else
v6 = 0x8000000000000002ui64;
}
v5 = v6;
if ( v6 >= 0 )
continue;
}
else
{
v5 = 0x8000000000000015ui64;
}
sub_4E0((__int64)v14, 129, v5);
}
}
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, __int64, _BYTE *))gRT->SetVariable)(
L"MPDTContent",
&NameGuid,
7i64,
v9,
v14);
if ( i >= v7 )
((void (__fastcall *)(EFI_CAPSULE_HEADER **))gBS->CloseEvent)(Event);
((void (__fastcall *)(__int64))gBS->FreePool)(v10);
}
LABEL_18:
((void (__fastcall *)(EFI_CAPSULE_HEADER **))gBS->CloseEvent)(Event);
}
The gRT->SetVariable()
service is called with the DataSize
as an argument, which will be overwritten inside the gRT->GetVariable()
service if the length of MPDTContent
NVRAM variable is greater than 15
.
Thus, a potential attacker can dump X - 15
bytes from the stack (or global memory) into MPDTContent NVRAM variable by setting MPDTContent
NVRAM variable's size to X > 15
.
To fix this vulnerability the DataSize
must be re-initialized with the size of MPDTContent
before calling gRT->SetVariable()
.
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