An attacker with high physical 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 (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 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 physical 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 Precision 7X50's firmware (version: 0.1.19.0, module sha256: 9c19c06003311c102b91353d1b88fe23c9d2bd89c57f80afcc82b5fab9c2eab6) as an example.
The following code in the module actually allows leaking memory:
gRT->GetVariable()
offset: 0xdc2
gRT->SetVariable()
offset: 0xdf5
// positive sp value has been detected, the output may be wrong!
__int64 __fastcall sub_D1F(__int64 a1, EFI_GUID *a2, EFI_GUID *VendorGuid, _QWORD *a4)
{
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // r9
__int64 v7; // r8
EFI_RUNTIME_SERVICES *v8; // rax
__int64 v9; // r9
__int64 v10; // r8
EFI_RUNTIME_SERVICES *v11; // rax
_DWORD v13[4]; // [rsp-BC8h] [rbp-BC8h] BYREF
_DWORD v14[750]; // [rsp-BB8h] [rbp-BB8h] BYREF
sub_11E8((__int64)&EFI_ODMEM_GNVS_AREA_PROTOCOL_GUID, (__int64)sub_554, (__int64)VendorGuid, a4, v4);
v14[0] = -1332766721;
v14[1] = 1100211944;
v14[2] = -1637967959;
v14[3] = 853215899;
v13[0] = 1165015025;
v13[1] = 1229172200;
v13[2] = 1681965965;
v13[3] = -2078047118;
sub_1330((int *)(v5 + 752), 0, 0x7ECui64);
*(_QWORD *)(v5 + 2840) = 845i64;
((void (__fastcall *)(const __int16 *, _DWORD *, __int64, __int64, __int64))gRT->GetVariable)(// <= first call (we can rewrite DataSize here)
L"CpuSetup",
v14,
v5 + 2816,
v5 + 2840,
v5 - 96);
v6 = *(_QWORD *)(v5 + 2840);
v7 = *(unsigned int *)(v5 + 2816);
v8 = gRT;
*(_WORD *)(v5 + 125) = 256;
((void (__fastcall *)(const __int16 *, _DWORD *, __int64, __int64, __int64))v8->SetVariable)(// <= second call
L"CpuSetup",
v14,
v7,
v6,
v5 - 96);
*(_QWORD *)(v5 + 2840) = 2028i64;
((void (__fastcall *)(const __int16 *, _DWORD *, __int64, __int64, __int64))gRT->GetVariable)(// <= first call (we can rewrite DataSize here)
L"PchSetup",
v13,
v5 + 2816,
v5 + 2840,
v5 + 752);
v9 = *(_QWORD *)(v5 + 2840);
v10 = *(unsigned int *)(v5 + 2816);
v11 = gRT;
*(_BYTE *)(v5 + 2471) = 0;
*(_BYTE *)(v5 + 762) = 0;
*(_BYTE *)(v5 + 2512) = 0;
((void (__fastcall *)(const __int16 *, _DWORD *, __int64, __int64, __int64))v11->SetVariable)(// <= second call
L"PchSetup",
v13,
v10,
v9,
v5 + 752);
return 0i64;
}
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 CpuSetup
NVRAM variable is greater than 845
.
Thus, a potential attacker can dump X - 845
bytes from the stack (or global memory) into CpuSetup NVRAM variable by setting CpuSetup
NVRAM variable's size to X > 845
.
To fix this vulnerability the DataSize
must be re-initialized with the size of CpuSetup
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