# CVE-2024-21115: An Oracle VirtualBox LPE Used to Win Pwn2Own

OOB bit-clear in VirtualBox VGA dirty-page bitmap corrupts a critical-section hEvent, enabling a race that yields arbitrary read/write and LPE to WinExec.

- Payout: unconfirmed
- Severity: high
- Program: Oracle
- Found by: Cody Gallagher
- Disclosed: 2024-05-09
- CVE: CVE-2024-21115
- Write-up quality: 9/10
- Original: https://www.zerodayinitiative.com/blog/2024/5/9/cve-2024-21115-an-oracle-virtualbox-lpe-used-to-win-pwn2own
- Library page: https://bugbountylibrary.com/r/blog%3Azerodayinitiative-com-blog-2024-5-9-cve-2024-21115-an-oracle-virtualbox-lpe-used-to-win-pwn2own
- Tags: area:os domain:desktop impact:privesc impact:rce kind:bounty platform:blog sev:high tech:windows technique:chained technique:race-window technique:source-review vuln:memory-corruption vuln:privilege-escalation vuln:race-condition

**Target:** Oracle VirtualBox VGA/VMSVGA device (vgaR3DrawBlank, vbe ioport, VMSVGA scratch region)
**Root cause:** vgaR3DrawBlank multiplies start_addr by 4 when clearing dirty-page bits, so a start_addr up to vram_size clears bits past the end of the dirty-page bitmap on the heap.
**Steps:**
1. Set VBE_DISPI_INDEX_XRES/YRES/BPP/VIRT_WIDTH/VIRT_HEIGHT/ENABLE and X_OFFSET/Y_OFFSET via ioports so start_addr exceeds 64MB (requires vram_size > 64MB).
2. Trigger vgaR3UpdateBasicParams/vgaR3GetOffsets so vbe_start_addr is stored into start_addr, then vgaR3DrawBlank clears the out-of-bounds bit.
3. Choose offsets to zero the hEvent field (offset 0x18) of VGAState's CritSect, changing 0x23 to 0x21 (VMMDev's hEvent).
4. Race two VMMDev requests to prematurely wake a VGA thread waiting on the corrupted critical section.
5. Use the race to bypass the vbe_regs index bounds check in vbe_ioport_write_data: worker thread uses valid vbe_index with a large memset length, racer thread swaps in a bad index after validation.
6. Write 0xf to fFlags at offset 0x14 to set RTCRITSECT_FLAGS_NOP, disabling the VGA critical section entirely.
7. Reuse the vbe_ioport_write race to corrupt cScratchRegion in VMSVGASTATE, giving controlled buffer overread/overflow of au32ScratchRegion.
8. Overread the PDMPCIDEV following VGAState to leak the 'vga' string pointer and derive VBoxDD.dll base.
9. Overflow pfnConfigRead/pfnConfigWrite in PDMPCIDEVINT; set uConfigReg via pciIOPortAddressWrite and trigger via pciIOPortDataWrite.
10. Use the controlled call to build an arbitrary read (arg1+0x2d8 -> arg2), leak kernel32.dll via VBoxDD IAT, resolve WinExec, write 'calc' to heap, call WinExec.
11. Constraints: >=65MB VRAM (128MB used), 4 cores for the race.
**How found:** Noticed the *4 multiplication on start_addr in vgaR3DrawBlank while reading VGA dirty-page code; then inspected CritSect layout, observed hEvent values (VGA 0x23, VMMDev 0x21) assigned sequentially at startup, and hypothesized flipping hEvent would confuse lock wakeups. Discovered SigTrap on NativeThreadOwner mismatch, then found RTCRITSECT_FLAGS_NOP and the vbe_regs bounds-check race to set it.
**Exploitation:** Chain: OOB bit-clear corrupts CritSect hEvent -> race wakes VGA thread early -> bypass vbe_regs bounds check -> set RTCRITSECT_FLAGS_NOP to disable locking -> race corrupts cScratchRegion -> controlled overread/overflow of VGAState -> leak VBoxDD.dll base and overwrite PDMPCIDEVINT function pointers -> controlled indirect call builds arbitrary read -> leak kernel32.dll base via IAT -> resolve WinExec -> execute calc. CFG bypassed by calling legitimate exported functions in other libraries.
**Escalation:** Escalated from a single-bit heap clear to full LPE by chaining critical-section corruption, a bounds-check race, scratch-region corruption, and function-pointer hijack to arbitrary read and code execution.
**Insight:** Sequentially-allocated handle IDs (like hEvent) in adjacent device structs are stable across runs; a single-bit corruption of one handle to match another device's handle creates cross-device lock confusion. Also, a bounds check followed by a controllable-length memset is a wide race window worth targeting.

