flawopen.com/Teardowns/cve-2024-30051-windows-dwm-privilege-escalation
CVE-2024-30051: Windows DWM Heap Overflow
CVE-2024-30051 is a locally exploitable Windows Desktop Window Manager (DWM) heap overflow. Reverse engineering found that DWM rounded an allocation size down, then copied the original, larger size; Microsoft fixed the flaw in its May 2024 security update.[5], [3], [6]
Imagine reserving space by counting only whole crates, rounding the remainder down, and then loading the entire shipment anyway. The loading plan is smaller than the amount actually moved, so the shipment crosses the space that was reserved. This is the allocation-versus-copy size mismatch described for CVE-2024-30051.[6]
Core Concepts & Subsystem Terms
Desktop Window Manager (DWM)- Windows component that manages desktop composition. Microsoft classifies
CVE-2024-30051as a DWM Core privilege-escalation vulnerability.[4], [6] Allocation/copy size mismatch- The allocation used a rounded-down size, while the copy used the original size, allowing a heap write beyond the allocated buffer.[6]
CWE-122: Heap-based Buffer Overflow- A write exceeds the bounds of a heap-allocated buffer. The advisory maps this CVE to
CWE-122.[5], [1], [2] SYSTEM integrity level- A Windows integrity level associated with highly privileged processes. It is not itself proof that a process runs under the LocalSystem account.[6]
Framework mappings
- CWE reference for the weakness described in this guide: CWE-122
- CISA KEV — added 2024-05-14 — CVE-2024-30051
Root Cause Analysis
Core Security’s reverse engineering identified the affected routine as CCommandBuffer::Initialize. It calculated an allocation as (size / 0x90) * 0x90, using integer division that rounds down to a multiple of 0x90, while a later memcpy used the original size. For some inputs, the copy therefore exceeded the heap allocation. Microsoft fixed CVE-2024-30051 in the May 14, 2024 security update. Core Security describes the resulting DWM process as running at SYSTEM integrity level, which is distinct from saying the process runs as the LocalSystem account. Kaspersky reported finding an exploit in mid-April 2024 and observing it alongside QakBot and other malware; those observations do not establish how the malware first reached a machine.[6], [4], [7]
Step-by-Step Attack Flow
Allocation size is rounded down
Reverse engineering identifies CCommandBuffer::Initialize calculating a buffer allocation in multiples of 0x90.[6]
Source Code: Flaw vs. Secure Implementation
These are representative educational patterns informed by the published analysis, not Microsoft source code or Microsoft’s patch. They do not reproduce the exploit.[6], [4]
// Representative unsafe pattern; not Microsoft source code.
size_t requested = get_command_buffer_size();
size_t allocation_size = (requested / allocation_unit) * allocation_unit;
BYTE *dst = HeapAlloc(heap, flags, allocation_size);
if (dst == NULL) return E_OUTOFMEMORY;
memcpy(dst, source, requested);
// Representative defensive pattern; not Microsoft's patch source.
size_t requested = get_command_buffer_size();
size_t source_len = get_source_length();
if (requested > source_len || requested > MAX_COMMAND_BUFFER_SIZE) return E_INVALIDARG;
BYTE *dst = HeapAlloc(heap, flags, requested);
if (dst == NULL) return E_OUTOFMEMORY;
memcpy(dst, source, requested);
Engineering & System Hardening Checklist
- ✓Install Microsoft’s May 2024 security update or a later cumulative update on affected Windows systems; confirm patch status through the organization’s supported inventory tooling.[3], [4], [8]
- ✓In size-handling code, ensure the exact validated length is used for both allocation and copy; reject inputs above a documented maximum.[6], [2]
- ✓Check multiplication, division, addition, and rounding paths for truncation or overflow; fail closed when a size cannot be represented or validated.[6], [2]
- ✓Add boundary-value tests for sizes around allocation-unit boundaries and use AddressSanitizer where supported in CI; tests and sanitizers supplement, not replace, code review.[9], [2]
Sources
- NVD — CVE-2024-30051
- MITRE CWE-122
- Microsoft — May 2024 Security Updates
- Microsoft Security Update Guide — CVE-2024-30051
- GitHub Advisory — CVE-2024-30051
- Core Security — Technical Analysis of CVE-2024-30051
- Kaspersky Securelist — CVE-2024-30051
- CISA — Known Exploited Vulnerabilities Catalog
- Microsoft Learn — AddressSanitizer