diff options
| author | Alexander Potapenko <glider@google.com> | 2025-11-19 15:45:40 +0100 |
|---|---|---|
| committer | Alexander Potapenko <glider@google.com> | 2025-11-20 09:23:19 +0000 |
| commit | 5c74d2f73618084fe35322dbb04bf713f7d177f2 (patch) | |
| tree | 1c3b16cd8fa7e9a93adb462870551f6d99f04e72 /sys | |
| parent | ec988b2fb6c4aada0b3afcd9739ad27ec64b8249 (diff) | |
executor: sys/linux: implement SYZOS_API_NESTED_VMRESUME
Provide the SYZOS API command to resume L2 execution after a VM exit,
using VMRESUME on Intel and VMRUN on AMD.
For testing purpose, implement basic handling of the INVD instruction:
- enable INVD interception on AMD (set all bits in VMCB 00Ch);
- map EXIT_REASON_INVD and VMEXIT_INVD into SYZOS_NESTED_EXIT_REASON_INVD;
- advance L2 RIP to skip to the next instruction.
While at it, perform minor refactorings of L2 exit reason handling.
sys/linux/test/amd64-syz_kvm_nested_vmresume tests the new command by
executing two instructions, INVD and HLT, in the nested VM.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/linux/dev_kvm_amd64.txt | 1 | ||||
| -rw-r--r-- | sys/linux/test/amd64-syz_kvm_nested_vmresume | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/sys/linux/dev_kvm_amd64.txt b/sys/linux/dev_kvm_amd64.txt index cb116574d..d3dac2cf9 100644 --- a/sys/linux/dev_kvm_amd64.txt +++ b/sys/linux/dev_kvm_amd64.txt @@ -117,6 +117,7 @@ syzos_api_call$x86 [ nested_create_vm syzos_api$x86[301, syzos_api_vm_id] nested_load_code syzos_api$x86[302, syzos_api_nested_load_code] nested_vmlaunch syzos_api$x86[303, syzos_api_vm_id] + nested_vmresume syzos_api$x86[304, syzos_api_vm_id] ] [varlen] kvm_text_x86 [ diff --git a/sys/linux/test/amd64-syz_kvm_nested_vmresume b/sys/linux/test/amd64-syz_kvm_nested_vmresume new file mode 100644 index 000000000..f26b683bf --- /dev/null +++ b/sys/linux/test/amd64-syz_kvm_nested_vmresume @@ -0,0 +1,29 @@ +# +# 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 INVD (0f 08) and HLT (f4) to test vmresume. +# INVD is one of the few instructions that cause unconditional VM exit on Intel. +# On AMD, SYZOS also turns on INVD interception. +# +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, "0f08f4"}}, @nested_vmlaunch={AUTO, AUTO, 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 INVD. Exit reason is mapped to 0xe2e20002. +# +ioctl$KVM_RUN(r3, AUTO, 0x0) +syz_kvm_assert_syzos_uexit$x86(r5, 0xe2e20002) + +# L1 resumes L2, which executes HLT. Exit reason is mapped to 0xe2e20001. +# +ioctl$KVM_RUN(r3, AUTO, 0x0) +syz_kvm_assert_syzos_uexit$x86(r5, 0xe2e20001) + +# guest_main should finish with guest_uexit(-1). +# +ioctl$KVM_RUN(r3, AUTO, 0x0) +syz_kvm_assert_syzos_uexit$x86(r5, 0xffffffff) |
