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.
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 Latitude 3120's firmware (version: 0.1.13.1, module sha256: 53c72f110491b5bee302e898da8f9497d8e15ad037590c31fa4d709169158773) as an example.
The following code in the module actually allows leaking memory:
gRT->GetVariable()
offset: 0xfa63
gRT->SetVariable()
offset: 0xfa91
__int64 __fastcall sub_F9AC()
{
char v1[304]; // [rsp+30h] [rbp-D0h] BYREF
char v2[672]; // [rsp+160h] [rbp+60h] BYREF
char v3[1024]; // [rsp+400h] [rbp+300h] BYREF
char v4[1920]; // [rsp+800h] [rbp+700h] BYREF
char Data[3600]; // [rsp+F80h] [rbp+E80h] BYREF
char v6; // [rsp+1DA0h] [rbp+1CA0h] BYREF
char v7; // [rsp+1DA8h] [rbp+1CA8h] BYREF
UINTN DataSize; // [rsp+1DB0h] [rbp+1CB0h] BYREF
DataSize = 3600i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"Setup",
&EFI_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
Data);
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(// <= second call
L"ColdReset",
&EFI_SETUP_VARIABLE_GUID,
2i64,
DataSize,
Data);
DataSize = 1018i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"SaSetup",
&SA_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
v3);
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(// <= second call
L"SaColdReset",
&SA_SETUP_VARIABLE_GUID,
2i64,
DataSize,
v3);
DataSize = 297i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"MeSetup",
&ME_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
v1);
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(// <= second call
L"MeColdReset",
&ME_SETUP_VARIABLE_GUID,
2i64,
DataSize,
v1);
DataSize = 667i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"CpuSetup",
&CPU_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
v2);
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(// <= second call
L"CpuColdReset",
&CPU_SETUP_VARIABLE_GUID,
2i64,
DataSize,
v2);
DataSize = 1919i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"PchSetup",
&PCH_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
v4);
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(// <= second call
L"PchColdReset",
&PCH_SETUP_VARIABLE_GUID,
2i64,
DataSize,
v4);
DataSize = 7i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"SiSetup",
&SI_SETUP_VARIABLE_GUID,
0i64,
&DataSize,
&v7);
((void (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(// <= second call
L"SiColdReset",
&SI_SETUP_VARIABLE_GUID,
2i64,
DataSize,
&v7);
DataSize = 4i64;
((void (__fastcall *)(const __int16 *, EFI_GUID *, _QWORD, UINTN *, char *))gRT_0->GetVariable)(// <= first call (we can rewrite DataSize here)
L"AmiWrapperSetup",
&stru_22D78,
0i64,
&DataSize,
&v6);
return ((__int64 (__fastcall *)(const __int16 *, EFI_GUID *, __int64, UINTN, char *))gRT_0->SetVariable)(
L"AmiWrapperColdReset",
&stru_22D78,
2i64,
DataSize,
&v6);
}
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 SaSetup
NVRAM variable is greater than 1018
.
Thus, a potential attacker can dump X - 1018
bytes from the stack (or global memory) into SaColdReset NVRAM variable by setting SaSetup
NVRAM variable's size to X > 1018
.
To fix this vulnerability the DataSize
must be re-initialized with the size of SaColdReset
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