WARNING in __nested_vmx_vmexit

Status: upstream: reported C repro on 2026/11/19 22:07
Subsystems: kvm-x86
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+483ee9b97423483ca602@syzkaller.appspotmail.com
First crash: 10d, last: 10d
✨ AI-generated root cause summary:

When an L1 vCPU encounters a hardware VM-Fail on VM-Entry, vmx_handle_exit() processes the failure and returns KVM_EXIT_FAIL_ENTRY to userspace without clearing the vmx->fail flag. If userspace then calls KVM_SET_NESTED_STATE with KVM_STATE_NESTED_GUEST_MODE set, the vCPU enters guest mode without resetting vmx->fail. If the VM is subsequently torn down without another KVM_RUN, vmx_leave_nested() synthesizes a nested VM-exit where __nested_vmx_vmexit() observes the stale vmx->fail == 1 and reads VM_INSTRUCTION_ERROR from vmcs02 (which was never launched), triggering a WARN_ON_ONCE because VM_INSTRUCTION_ERROR is not VMXERR_ENTRY_INVALID_CONTROL_FIELD.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 7475ea8b5861:

Technical Explanation of Root Cause

1. Functions, Structs, Fields, and Files Involved

  • struct vcpu_vmx: Contains the boolean field fail, which indicates whether the last VM-Entry (__vmx_vcpu_run()) resulted in a hardware VM-Fail.
  • vmx_handle_exit() (arch/x86/kvm/vmx/vmx.c): Handles exits from guest execution when the vCPU is not in guest mode (!is_guest_mode(vcpu)).
  • vmx_set_nested_state() and nested_vmx_enter_non_root_mode() (arch/x86/kvm/vmx/nested.c): Handles restoring nested virtualization state via ioctl(KVM_SET_NESTED_STATE).
  • vmx_leave_nested() and __nested_vmx_vmexit() (arch/x86/kvm/vmx/nested.c, arch/x86/kvm/vmx/nested.h): Cleans up nested state when leaving nested mode or when tearing down the vCPU (nested_vmx_free_vcpu()).

2. Vulnerability Mechanism and Trigger Sequence

  1. L1 Hardware VM-Entry Failure:

    • A vCPU running in non-guest (L1) mode attempts VM-Entry via __vmx_vcpu_run(). Due to invalid guest/host configuration, the entry fails at hardware level.
    • __vmx_vcpu_run() returns 1, and vmx_vcpu_enter_exit() records this via:
      vmx->fail = __vmx_vcpu_run(vmx, flags);
      
    • In vmx_handle_exit() (arch/x86/kvm/vmx/vmx.c), the failure is caught:
      if (unlikely(vmx->fail)) {
          dump_vmcs(vcpu);
          vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
          vcpu->run->fail_entry.hardware_entry_failure_reason
              = vmcs_read32(VM_INSTRUCTION_ERROR);
          vcpu->run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu;
          return 0;
      }
      
    • Crucially, vmx_handle_exit() returns 0 to userspace without resetting vmx->fail to 0.
  2. Transitioning into Nested Guest Mode (is_guest_mode):

    • Userspace issues ioctl(vcpu, KVM_SET_NESTED_STATE) with valid nested VMX state and KVM_STATE_NESTED_GUEST_MODE set in flags.
    • vmx_set_nested_state() restores the state and calls nested_vmx_enter_non_root_mode(vcpu, false).
    • nested_vmx_enter_non_root_mode() switches the active VMCS to vmcs02 and transitions the vCPU to guest mode (enter_guest_mode(vcpu)).
    • Neither vmx_set_nested_state() nor nested_vmx_enter_non_root_mode() clears vmx->fail. Thus, vmx->fail remains 1 (stale from the earlier L1 failure).
  3. VM Destruction and Nested VM-Exit Warning:

    • The VM process closes its file descriptors without executing another KVM_RUN (which would have overwritten or cleared vmx->fail).
    • During vCPU destruction (kvm_arch_vcpu_destroy() -> vmx_vcpu_free() -> nested_vmx_free_vcpu()), KVM calls vmx_leave_nested().
    • Because is_guest_mode(vcpu) is true, vmx_leave_nested() synthesizes a nested VM-exit by calling:
      nested_vmx_vmexit(vcpu, -1, 0, 0);
      
    • In __nested_vmx_vmexit() (arch/x86/kvm/vmx/nested.c), KVM checks:
      if (likely(!vmx->fail)) {
          ...
      } else {
          WARN_ON_ONCE(vmcs_read32(VM_INSTRUCTION_ERROR) !=
                       VMXERR_ENTRY_INVALID_CONTROL_FIELD);
          ...
      }
      
    • Since vmx->fail is still 1, execution takes the else branch (intended for late nested VM-Fails).
    • Because vmcs02 is active and has never actually executed hardware VM-Entry, its VM_INSTRUCTION_ERROR field contains 0 (or undefined state) rather than VMXERR_ENTRY_INVALID_CONTROL_FIELD (7), triggering the WARN_ON_ONCE at nested.c:5149.
▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
dd453e9c assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ WARNING in __nested_vmx_vmexit 2026/11/09 21:16 2026/11/09 21:16 2026/11/09 21:53 5cecaf1f
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [kvm-x86?] WARNING in __nested_vmx_vmexit 0 (1) 2026/11/19 22:07

Sample crash report:
kvm_intel: set kvm_intel.dump_invalid_vmcs=1 to dump internal KVM state.
------------[ cut here ]------------
vmcs_read32(VM_INSTRUCTION_ERROR) != VMXERR_ENTRY_INVALID_CONTROL_FIELD
WARNING: arch/x86/kvm/vmx/nested.c:5149 at __nested_vmx_vmexit+0x2734/0x4000 arch/x86/kvm/vmx/nested.c:5149, CPU#1: syz.0.17/6007
Modules linked in:
CPU: 1 UID: 0 PID: 6007 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__nested_vmx_vmexit+0x2734/0x4000 arch/x86/kvm/vmx/nested.c:5149
Code: ff ff e8 0f a0 67 00 90 bf 0e 44 00 00 e8 c4 ed f8 ff 90 31 db e9 01 ec ff ff e8 f7 9f 67 00 e8 f2 1b 48 0a e8 ed 9f 67 00 90 <0f> 0b 90 e9 6a ff ff ff e8 df 9f 67 00 90 bf 00 44 00 00 e8 94 ed
RSP: 0018:ffffc9000338f960 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff88802c514b00 RSI: ffffffff81a6e113 RDI: 0000000000000005
RBP: ffffc9000338fac0 R08: 0000000000000007 R09: 0000000000000000
R10: ffff888035f7003f R11: 0000000000000000 R12: 0000000000000001
R13: ffff8880382442ec R14: 0000000000000000 R15: ffff888035f70000
FS:  00005555645d0500(0000) GS:ffff8880d4571000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055b5cc929ff0 CR3: 000000003db67000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 nested_vmx_vmexit arch/x86/kvm/vmx/nested.h:46 [inline]
 vmx_leave_nested arch/x86/kvm/vmx/nested.c:6895 [inline]
 nested_vmx_free_vcpu+0xb3/0xd0 arch/x86/kvm/vmx/nested.c:389
 vmx_vcpu_free+0x94/0x340 arch/x86/kvm/vmx/vmx.c:7519
 kvm_arch_vcpu_destroy+0x159/0x3e0 arch/x86/kvm/x86.c:9558
 kvm_vcpu_destroy virt/kvm/kvm_main.c:477 [inline]
 kvm_destroy_vcpus+0x24e/0x3c0 virt/kvm/kvm_main.c:497
 kvm_arch_destroy_vm+0xc7/0x230 arch/x86/kvm/x86.c:10129
 kvm_destroy_vm virt/kvm/kvm_main.c:1313 [inline]
 kvm_put_kvm+0x556/0xc00 virt/kvm/kvm_main.c:1350
 kvm_vm_release+0x65/0x80 virt/kvm/kvm_main.c:1375
 __fput+0x3fb/0xb50 fs/file_table.c:512
 fput_close_sync+0x118/0x250 fs/file_table.c:618
 filp_close_sync+0x75/0xa0 fs/open.c:1574
 __range_close+0x4a6/0x8b0 fs/file.c:919
 __do_sys_close_range fs/file.c:1003 [inline]
 __se_sys_close_range fs/file.c:954 [inline]
 __x64_sys_close_range+0x1f8/0x430 fs/file.c:954
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f5f6ab9fb19
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:00007fff0931e598 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4
RAX: ffffffffffffffda RBX: 00007fff0931e680 RCX: 00007f5f6ab9fb19
RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003
RBP: 000000000000e232 R08: 0000000000000001 R09: 0000000000000000
R10: 0000001b2fb20000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f5f6ae25fac R14: 00007f5f6ae25fa8 R15: 00007f5f6ae25fa0
 </TASK>

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/09 21:16 upstream 7475ea8b5861 bf7e1705 .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream WARNING in __nested_vmx_vmexit
* Struck through repros no longer work on HEAD.