Hunting and Exploiting Recursive MMIO Flaws in QEMU KVM
Discusses hunting and Exploiting Recursive MMIO Flaws in QEMU KVM and evaluates key implications for security practitioners.
Summary
Overview: Researchers from Harbin Institute of Technology and Zhejiang University reveal a critical class of vulnerabilities in the QEMU/KVM hypervisor termed "recursive MMIO" (Memory-Mapped I/O). The speakers demonstrate how improper isolation between Direct Memory Access (DMA) and MMIO allows a malicious guest operating system to trigger reentrant hardware emulation loops that violate virtual device state machines. By modeling recursive execution paths using CodeQL, the authors uncover multiple exploitable flaws, showcasing a complete virtual machine escape via a Use-After-Free (UAF) condition in an emulated NVMe controller paired with Intel HDA heap feng shui.
Key Topics: - Architecture of QEMU/KVM hypervisor: VM-exits, MMIO interception, and user-space DMA emulation - Root cause of Recursive MMIO: incomplete isolation between DMA target physical addresses and device MMIO regions - Failure modes of recursion: Use-After-Free (UAF), Out-of-Bounds (OOB) memory access, and infinite recursion DoS - Automated path hunting across virtual devices using custom CodeQL AST queries and transitive closure predicates - Exploitation engineering: constructing controllable malloc primitives in Intel HDA to exploit an NVMe UAF and escape the VM
Technical Details: In QEMU/KVM environments, the guest OS executes instructions directly on host CPU cores via KVM until privileged operations trigger VM-exits, which KVM passes to QEMU user space to emulate hardware behavior. Virtual devices implement DMA transfers via user-space memory copies (such as address_space_write, dma_memory_write, and pci_dma_write). However, because virtual devices share an address space encompassing system RAM and other device MMIO regions, a guest can set a device DMA destination address to overlap with MMIO registers. When the DMA write executes, it directly invokes the destination device MMIO write handler, creating recursive execution flows while the initial I/O operation is still active.
These recursive interactions violate internal device state machine invariants. For example, in a direct recursion scenario, an attacker configures a device DMA target to its own reset register; the resulting write executes the reset routine, freeing internal data structures while the parent DMA routine is mid-execution. When control returns, the parent routine accesses the freed structure, triggering a Use-After-Free (UAF). Indirect recursion occurs when device A triggers DMA to device B, which in turn invokes device A MMIO handlers. Other failure modes include Out-of-Bounds (OOB) memory corruption—caused by modifying global transfer size or index variables via MMIO during DMA transfers—or hypervisor crashes caused by unbounded recursive loops.
To automate vulnerability discovery across QEMU vast device codebase, the researchers authored CodeQL queries. They characterized MMIO handlers in MemoryRegionOps structs, Bottom-Half callbacks (qemu_bh_new_guarded), and timer callbacks as sources, and physical memory write APIs as sinks. Using CodeQL pathgraph module and transitive closure predicates, they mapped intersection paths linking MMIO handlers, DMA writes, and device reset functions. To exploit an NVMe controller UAF, the authors required a primitive to reallocate the freed chunk before nvme_enqueue_req_completion executed. They leveraged the Intel HDA sound card emulation, where setting the run bit in stream control registers allocates buffer descriptor list chunks in guest-controlled multiples of 16 bytes via the LVI register, successfully grooming the heap and achieving arbitrary host code execution.
Key Takeaways: Hypervisors must strictly isolate DMA from MMIO address spaces, actively blocking DMA memory copies from targeting emulated device register regions to prevent reentrant state corruption. Static analysis using CodeQL pathgraphs is highly effective for identifying multi-hop reentrancy vulnerabilities across complex hypervisor device drivers. Peripheral device emulations with flexible, user-controlled heap allocations (such as Intel HDA) provide potent heap grooming primitives that turn theoretical hypervisor UAF flaws into practical VM escapes.
(AI summary — Gemini Flash)
Related talks
Black Hat Asia·43 min
Shmuel Cohen
Industry experts analyze emerging threats surrounding The Dark Side of EDR: Repurpose EDR as an Offensive Tool.
Black Hat Asia·43 min
Bart Stump
Presenters detail vulnerability discovery and exploitation in The Black Hat Asia Network Operations Center (NOC) Report.
Black Hat Asia·40 min
Tomer Bar · Shmuel Cohen
Engineers explore architecture and security mechanisms for EDR Reloaded: Erase Data Remotely.


