From 1432fc84530255f6208c5719be796918244fa9d3 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Wed, 18 Dec 2024 10:51:20 +0100 Subject: sys/linux/test: add a seed enabling PMU Add sys/linux/test/arm64-syz_kvm_setup_syzos_vm-enable-pmu, a seed that enables PMU and touches PMEVCNTR0_EL0. It was inspired by https://github.com/google/syzkaller/pull/5582 and led to a notable (+500) coverage increase, as the fuzzer couldn't previously guess that it should pass KVM_ARM_VCPU_PMU_V3 when creating the vCPU and set the KVM_ARM_VCPU_PMU_V3_INIT attribute at the same time. --- .../test/arm64-syz_kvm_setup_syzos_vm-enable-pmu | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 sys/linux/test/arm64-syz_kvm_setup_syzos_vm-enable-pmu (limited to 'sys/linux') diff --git a/sys/linux/test/arm64-syz_kvm_setup_syzos_vm-enable-pmu b/sys/linux/test/arm64-syz_kvm_setup_syzos_vm-enable-pmu new file mode 100644 index 000000000..eee1ce9db --- /dev/null +++ b/sys/linux/test/arm64-syz_kvm_setup_syzos_vm-enable-pmu @@ -0,0 +1,26 @@ +# +# requires: arch=arm64 -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(r1, &(0x7f0000c00000/0x400000)=nil) +# +# 0x603000000013df40 is PMEVCNTR0_EL0, write to it will trigger access_pmu_evcntr() in arch/arm64/kvm/sys_regs.c +# This is done to illustrate that PMU is accessible. +# 0x8 corresponds to the KVM_ARM_VCPU_PMU_V3 feature bit and is required to enable PMU. +# +r3 = syz_kvm_add_vcpu(r2, &AUTO={0x0, &AUTO=[@msr={AUTO, AUTO, {0x603000000013df40, 0x8000}}], AUTO}, &AUTO=[@featur1={0x1, 0x8}], 0x1) +# +# Call ioctl(KVM_SET_DEVICE_ATTR) with group=KVM_ARM_VCPU_PMU_V3_CTRL and attr=KVM_ARM_VCPU_PMU_V3_INIT, +# as per https://www.kernel.org/doc/Documentation/virt/kvm/devices/vcpu.rst. +# +ioctl$KVM_SET_DEVICE_ATTR_vcpu(r3, AUTO, &AUTO=@attr_pmu_init) + +r4 = ioctl$KVM_GET_VCPU_MMAP_SIZE(r0, AUTO) +r5 = mmap$KVM_VCPU(&(0x7f0000009000/0x1000)=nil, r4, 0x3, 0x1, r3, 0x0) +# +# Run till the end of guest_main(). 0xffffffffffffffff is UEXIT_END. +# +ioctl$KVM_RUN(r3, AUTO, 0x0) +syz_kvm_assert_syzos_uexit(r5, 0xffffffffffffffff) +syz_kvm_assert_reg(r3, 0x603000000013df40, 0x8000) -- cgit mrf-deployment