From 2a4c6c0dbed891610b6d10f663c797e9e80d1981 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Wed, 17 Sep 2025 12:16:39 +0200 Subject: executor: sys/linux/: pkg/runtest: pkg/vminfo: add syz_kvm_assert_syzos_kvm_exit Implement a pseudo-syscall to check the value of kvm_run.exit_reason --- executor/common_kvm.h | 25 +++++++++++++++++++++++++ executor/common_kvm_386.h | 7 +++++++ executor/common_kvm_amd64.h | 1 + executor/common_kvm_arm64.h | 1 + executor/common_linux.h | 2 +- 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 executor/common_kvm.h (limited to 'executor') diff --git a/executor/common_kvm.h b/executor/common_kvm.h new file mode 100644 index 000000000..fecd00922 --- /dev/null +++ b/executor/common_kvm.h @@ -0,0 +1,25 @@ +// Copyright 2025 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +// This file is shared between executor and csource package. + +// Common KVM-related definitions. + +#if SYZ_EXECUTOR || __NR_syz_kvm_assert_syzos_kvm_exit +static long syz_kvm_assert_syzos_kvm_exit(volatile long a0, volatile long a1) +{ + struct kvm_run* run = (struct kvm_run*)a0; + uint64 expect = a1; + + if (!run) { + errno = EINVAL; + return -1; + } + + if (run->exit_reason != expect) { + errno = EDOM; + return -1; + } + return 0; +} +#endif diff --git a/executor/common_kvm_386.h b/executor/common_kvm_386.h index 77ca4ce0e..f1b634150 100644 --- a/executor/common_kvm_386.h +++ b/executor/common_kvm_386.h @@ -24,6 +24,13 @@ static long syz_kvm_assert_syzos_uexit(volatile long a0, volatile long a1) } #endif +#if SYZ_EXECUTOR || __NR_syz_kvm_assert_syzos_uexit +static long syz_kvm_assert_syzos_kvm_exit(volatile long a0, volatile long a1) +{ + return 0; +} +#endif + #if SYZ_EXECUTOR || __NR_syz_kvm_setup_cpu static volatile long syz_kvm_setup_cpu(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4, volatile long a5, volatile long a6, volatile long a7) { diff --git a/executor/common_kvm_amd64.h b/executor/common_kvm_amd64.h index c21b8a09f..1344e635f 100644 --- a/executor/common_kvm_amd64.h +++ b/executor/common_kvm_amd64.h @@ -7,6 +7,7 @@ // See Intel Software Developer’s Manual Volume 3: System Programming Guide // for details on what happens here. +#include "common_kvm.h" #include "common_kvm_amd64_syzos.h" #include "kvm.h" #include "kvm_amd64.S.h" diff --git a/executor/common_kvm_arm64.h b/executor/common_kvm_arm64.h index 97a6429fe..4428a3484 100644 --- a/executor/common_kvm_arm64.h +++ b/executor/common_kvm_arm64.h @@ -6,6 +6,7 @@ // Implementation of syz_kvm_setup_cpu pseudo-syscall. #include +#include "common_kvm.h" #include "kvm.h" #if SYZ_EXECUTOR || __NR_syz_kvm_setup_cpu || __NR_syz_kvm_add_vcpu || __NR_syz_kvm_setup_syzos_vm diff --git a/executor/common_linux.h b/executor/common_linux.h index dea1ba0c8..31ce14dc3 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -3187,7 +3187,7 @@ error_clear_loop: } #endif -#if SYZ_EXECUTOR || __NR_syz_kvm_setup_cpu || __NR_syz_kvm_vgic_v3_setup || __NR_syz_kvm_setup_syzos_vm || __NR_syz_kvm_add_vcpu || __NR_syz_kvm_assert_syzos_uexit || __NR_syz_kvm_assert_reg +#if SYZ_EXECUTOR || __NR_syz_kvm_setup_cpu || __NR_syz_kvm_vgic_v3_setup || __NR_syz_kvm_setup_syzos_vm || __NR_syz_kvm_add_vcpu || __NR_syz_kvm_assert_syzos_uexit || __NR_syz_kvm_assert_reg || __NR_syz_kvm_assert_syzos_kvm_exit // KVM is not yet supported on RISC-V #if !GOARCH_riscv64 && !GOARCH_arm #include -- cgit mrf-deployment