syzbot
WARNING in kvm_dirty_ring_push (2)
Status:
upstream: reported on 2026/11/17 01:26
Subsystems:
kvm
Labels:
prio:low
[Documentation on labels]
Reported-by: syzbot+55eaa971f4924b62c9a5@syzkaller.appspotmail.com
First crash: 10h30m, last: 13m
✨ AI-generated root cause summary:
The KVM dirty ring implementation maps the per-vCPU dirty ring buffer (ring->dirty_gfns) writable into userspace. In kvm_dirty_ring_reset(), KVM iterates over entries marked with KVM_DIRTY_GFN_F_RESET and increments ring->reset_index without verifying that reset_index has not advanced past ring->dirty_index. When userspace sets KVM_DIRTY_GFN_F_RESET on un-dirtied entries, reset_index surpasses dirty_index, causing kvm_dirty_ring_used() (dirty_index - reset_index) to underflow to a large 32-bit unsigned integer (~UINT_MAX). On subsequent guest memory writes, kvm_dirty_ring_push() checks kvm_dirty_ring_full(), observes that the used entry count exceeds ring->size, and triggers the WARN_ON_ONCE(kvm_dirty_ring_full(ring)) assertion.
▶
▼
✨ Full AI root cause analysis
Technical Root Cause Analysis
Involved Subsystems, Files, and Entities
- Subsystem: KVM (Kernel Virtual Machine) Dirty Ring
- Files:
virt/kvm/dirty_ring.c, virt/kvm/kvm_main.c
- Structures & Fields:
struct kvm_dirty_ring:
dirty_index (u32): Index where the next dirty page entry will be pushed by KVM.
reset_index (u32): Index of the next harvested entry to be reset by KVM via KVM_RESET_DIRTY_RINGS.
size (u32): Number of entries in dirty_gfns (always a power of two).
dirty_gfns (struct kvm_dirty_gfn *): Ring buffer mapped shared/writable to userspace.
struct kvm_dirty_gfn:
flags (u32): State of the entry (KVM_DIRTY_GFN_F_DIRTY, KVM_DIRTY_GFN_F_RESET).
- Functions:
Bug Mechanism & Invariant Violation
-
Userspace Ring Access via mmap:
When KVM_CAP_DIRTY_LOG_RING is enabled, the guest vCPU's dirty ring buffer (vcpu->dirty_ring.dirty_gfns) is mapped shared and writable to userspace via mmap(..., vcpu_fd, KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE). Userspace is expected to read entries marked KVM_DIRTY_GFN_F_DIRTY, process the dirtied guest pages, set KVM_DIRTY_GFN_F_RESET on the harvested entries, and invoke the KVM_RESET_DIRTY_RINGS ioctl.
-
Missing Boundary Check in kvm_dirty_ring_reset():
In virt/kvm/dirty_ring.c:134-150, kvm_dirty_ring_reset() processes harvested entries:
while (likely((*nr_entries_reset) < INT_MAX)) {
entry = &ring->dirty_gfns[ring->reset_index & (ring->size - 1)];
if (!kvm_dirty_gfn_harvested(entry))
break;
...
kvm_dirty_gfn_set_invalid(entry);
ring->reset_index++;
(*nr_entries_reset)++;
...
}
Crucially, kvm_dirty_ring_reset() never checks whether ring->reset_index has reached ring->dirty_index (i.e., whether kvm_dirty_ring_used(ring) == 0). It relies solely on !kvm_dirty_gfn_harvested(entry) to terminate the loop.
-
Index Desynchronization and Unsigned Underflow:
Because userspace has writable access to ring->dirty_gfns, userspace can write KVM_DIRTY_GFN_F_RESET into entries that were never marked dirty by KVM (i.e., entries at or ahead of ring->dirty_index). When userspace subsequently calls KVM_RESET_DIRTY_RINGS, kvm_dirty_ring_reset() advances ring->reset_index past ring->dirty_index.
The number of used entries in the ring is calculated as:
static u32 kvm_dirty_ring_used(struct kvm_dirty_ring *ring)
{
return READ_ONCE(ring->dirty_index) - READ_ONCE(ring->reset_index);
}
When reset_index > dirty_index, this u32 subtraction underflows (visible in the crash registers where R15 = 0xfffffffe, i.e., (u32)-2, corresponding to reset_index = dirty_index + 2).
-
Triggering the Warning in kvm_dirty_ring_push():
On a subsequent guest memory write (e.g., EPT violation / TDP MMU page fault invoking make_spte() -> mark_page_dirty_in_slot()), KVM calls kvm_dirty_ring_push():
void kvm_dirty_ring_push(struct kvm_vcpu *vcpu, u32 slot, u64 offset)
{
struct kvm_dirty_ring *ring = &vcpu->dirty_ring;
struct kvm_dirty_gfn *entry;
/* It should never get full */
WARN_ON_ONCE(kvm_dirty_ring_full(ring));
Because kvm_dirty_ring_used(ring) underflowed to ~UINT_MAX, kvm_dirty_ring_full(ring) (used >= ring->size) evaluates to true, directly triggering the assertion:
WARNING: arch/x86/kvm/../../../virt/kvm/dirty_ring.c:225 at kvm_dirty_ring_push+0x2b2/0x5e0 virt/kvm/dirty_ring.c:225
Sample crash report:
------------[ cut here ]------------
kvm_dirty_ring_full(ring)
WARNING: arch/x86/kvm/../../../virt/kvm/dirty_ring.c:225 at kvm_dirty_ring_push+0x2b2/0x5e0 virt/kvm/dirty_ring.c:225, CPU#1: syz.1.192/6355
Modules linked in:
CPU: 1 UID: 0 PID: 6355 Comm: syz.1.192 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
RIP: 0010:kvm_dirty_ring_push+0x2b2/0x5e0 virt/kvm/dirty_ring.c:225
Code: 38 be 08 00 00 00 e8 8d 10 08 01 f0 80 4b 38 08 48 83 c4 18 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc cc e8 cf 84 88 00 90 <0f> 0b 90 e9 f8 fd ff ff e8 c1 84 88 00 90 0f 0b 90 e9 00 ff ff ff
RSP: 0018:ffffc9000cfe72e0 EFLAGS: 00010293
RAX: ffffffff81412d31 RBX: ffff88807cd40000 RCX: ffff888076ed8000
RDX: 0000000000000000 RSI: 0000000000000400 RDI: 00000000fffffffe
RBP: 1ffff1100f9a83a9 R08: 0000000000000000 R09: 1ffff1100b6d4ac6
R10: dffffc0000000000 R11: ffffed100b6d4ac7 R12: ffff88807cd41d50
R13: 1ffff1100f9a83aa R14: 0000000000000400 R15: 00000000fffffffe
FS: 00007fed5a9eb6c0(0000) GS:ffff888123234000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000007a0e2000 CR4: 00000000003526f0
Call Trace:
<TASK>
make_spte+0x71a/0xc80 arch/x86/kvm/mmu/spte.c:296
tdp_mmu_map_handle_target_level arch/x86/kvm/mmu/tdp_mmu.c:1144 [inline]
kvm_tdp_mmu_map+0x140e/0x1f40 arch/x86/kvm/mmu/tdp_mmu.c:1300
kvm_tdp_mmu_page_fault arch/x86/kvm/mmu/mmu.c:5029 [inline]
kvm_tdp_page_fault+0x2f7/0x3a0 arch/x86/kvm/mmu/mmu.c:5042
kvm_mmu_do_page_fault+0x31d/0x640 arch/x86/kvm/mmu/mmu.c:5089
kvm_mmu_page_fault+0x1f8/0xc00 arch/x86/kvm/mmu/mmu.c:6698
vt_handle_exit+0x28/0x160 arch/x86/kvm/vmx/main.c:974
vcpu_enter_guest arch/x86/kvm/x86.c:8540 [inline]
vcpu_run+0x4da1/0x7890 arch/x86/kvm/x86.c:8695
kvm_arch_vcpu_ioctl_run+0xe83/0x18b0 arch/x86/kvm/x86.c:9035
kvm_vcpu_ioctl+0xa61/0xfd0 virt/kvm/kvm_main.c:4595
vfs_ioctl fs/ioctl.c:52 [inline]
__do_sys_ioctl fs/ioctl.c:604 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:590
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x00007fed59ba94d9
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fed5a9eb028 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fed59e25fa0 RCX: 00007fed59ba94d9
RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 0000000000000006
RBP: 00007fed59c38136 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fed59e26038 R14: 00007fed59e25fa0 R15: 00007ffc860013a8
</TASK>
* Struck through repros no longer work on HEAD.