The KVM module emulates a performance-critical subset of the platform in the host kernel, and that code is reachable from the guest. The in-kernel local APIC and I/O APIC, the PIT timer, the coalesced MMIO ring buffer, and the handling of certain MSRs, CPUID, and instruction emulation all process guest-triggered events in kernel context. A flaw there, an out-of-bounds access in APIC register handling, a bad index in the coalesced MMIO ring, a logic error in instruction emulation, is host-kernel code execution or memory corruption, which is strictly more powerful than a user-space monitor escape because it skips the monitor sandbox and lands in ring 0 on the host.
The in-kernel surface#
// a guest reaches in-kernel KVM code by the operations KVM handles without exiting
// to the monitor:
// - APIC: MMIO/x2APIC MSR accesses to the emulated local APIC register page
// - coalesced MMIO: writes to registered regions fill an in-kernel ring the guest
// and host share; a bad first/last index is a classic OOB primitive
// - instruction emulation: KVM's x86 emulator decodes and executes some guest
// instructions in-kernel; operand/memory handling bugs are reachable here
// - MSR/CPUID: handlers for guest reads/writes of model-specific registers
The historically productive spots are the coalesced MMIO ring index handling and the x86 instruction emulator, both of which process rich guest-controlled input in the kernel.
Exploitation notes#
- Landing in the host kernel is the distinguishing feature: unlike a QEMU escape, there is no user-space sandbox to then break out of, so a KVM-module bug is a direct ring-0 host compromise.
- The coalesced MMIO ring is a shared guest/host structure with indices the guest can influence, making index-bounding bugs a recurring OOB source; the instruction emulator is a complex decoder reachable for specific instructions.
- Reaching these paths needs the guest to perform the triggering MMIO/MSR/instruction, which an attacker-controlled guest kernel does directly.
- Version-specific to the running kernel; fingerprint
uname -rand the kvm module, and note nested virtualization widens this surface, see Nested virtualization.