1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#
# requires: arch=amd64 -threaded
#
r0 = openat$kvm(0, &AUTO='/dev/kvm\x00', 0x0, 0x0)
r1 = ioctl$KVM_CREATE_VM(r0, AUTO, 0x0)
r2 = syz_kvm_setup_syzos_vm$x86(r1, &(0x7f0000c00000/0x400000)=nil)
# Create a nested VM that performs HLT and INVD.
# 1. L2 executes HLT -> exit to L1.
# 2. L1 disables HLT exiting via vmwrite to CPU_BASED_VM_EXEC_CONTROL.
# 3. L1 resumes L2 (RIP still at HLT).
# 4. L2 executes HLT (no exit), which is delivered to L0.
# 5. L0 resumes L1, which is still running L2.
# 6. L2 executes INVD -> exit to L1.
#
r3 = syz_kvm_add_vcpu$x86(r2, &AUTO={0x0, &AUTO=[@enable_nested={AUTO, AUTO, 0x0}, @nested_create_vm={AUTO, AUTO, 0x0}, @nested_load_code={AUTO, AUTO, {0x0, "f40f08"}}, @nested_vmlaunch={AUTO, AUTO, 0x0}, @nested_intel_vmwrite_mask={AUTO, AUTO, {0x0, @control32=0x4002, 0x0, 0x80, 0x0}}, @nested_vmresume={AUTO, AUTO, 0x0}], AUTO})
r4 = ioctl$KVM_GET_VCPU_MMAP_SIZE(r0, AUTO)
r5 = mmap$KVM_VCPU(&(0x7f0000009000/0x1000)=nil, r4, 0x3, 0x1, r3, 0x0)
# L2 VM executes HLT. Exit reason is mapped to 0xe2e20001.
#
ioctl$KVM_RUN(r3, AUTO, 0x0)
syz_kvm_assert_syzos_uexit$x86(r3, r5, 0xe2e20001)
# L1 disables HLT exiting and resumes L2. L2 resumes at HLT, and breaks out of KVM_RUN.
# 0x05 is KVM_EXIT_HLT.
# This confirms that the vmwrite command to disable HLT exiting was successful.
#
ioctl$KVM_RUN(r3, AUTO, 0x0)
syz_kvm_assert_syzos_kvm_exit$x86(r5, 0x5)
# After resuming, L2 executes INVD. Exit reason is mapped to 0xe2e20002.
#
ioctl$KVM_RUN(r3, AUTO, 0x0)
syz_kvm_assert_syzos_uexit$x86(r3, r5, 0xe2e20002)
# guest_main should finish with guest_uexit(-1).
#
ioctl$KVM_RUN(r3, AUTO, 0x0)
syz_kvm_assert_syzos_uexit$x86(r3, r5, 0xffffffffffffffff)
|