mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 12:11:40 +00:00
KVM: selftests: Test vCPU boot IDs above 2^32 and MAX_VCPU_ID
The KVM_SET_BOOT_CPU_ID ioctl missed to reject invalid vCPU IDs. Verify this no longer works and gets rejected with an appropriate error code. Signed-off-by: Mathias Krause <minipli@grsecurity.net> Link: https://lore.kernel.org/r/20240614202859.3597745-6-minipli@grsecurity.net [sean: add test for MAX_VCPU_ID+1, always do negative test] Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
4b451a5780
commit
438a496b90
@ -33,6 +33,20 @@ static void guest_not_bsp_vcpu(void *arg)
|
|||||||
GUEST_DONE();
|
GUEST_DONE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_set_invalid_bsp(struct kvm_vm *vm)
|
||||||
|
{
|
||||||
|
unsigned long max_vcpu_id = vm_check_cap(vm, KVM_CAP_MAX_VCPU_ID);
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if (max_vcpu_id) {
|
||||||
|
r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(max_vcpu_id + 1));
|
||||||
|
TEST_ASSERT(r == -1 && errno == EINVAL, "BSP with ID > MAX should fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(1L << 32));
|
||||||
|
TEST_ASSERT(r == -1 && errno == EINVAL, "BSP with ID[63:32]!=0 should fail");
|
||||||
|
}
|
||||||
|
|
||||||
static void test_set_bsp_busy(struct kvm_vcpu *vcpu, const char *msg)
|
static void test_set_bsp_busy(struct kvm_vcpu *vcpu, const char *msg)
|
||||||
{
|
{
|
||||||
int r = __vm_ioctl(vcpu->vm, KVM_SET_BOOT_CPU_ID,
|
int r = __vm_ioctl(vcpu->vm, KVM_SET_BOOT_CPU_ID,
|
||||||
@ -80,6 +94,8 @@ static struct kvm_vm *create_vm(uint32_t nr_vcpus, uint32_t bsp_vcpu_id,
|
|||||||
|
|
||||||
vm = vm_create(nr_vcpus);
|
vm = vm_create(nr_vcpus);
|
||||||
|
|
||||||
|
test_set_invalid_bsp(vm);
|
||||||
|
|
||||||
vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(unsigned long)bsp_vcpu_id);
|
vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(unsigned long)bsp_vcpu_id);
|
||||||
|
|
||||||
for (i = 0; i < nr_vcpus; i++)
|
for (i = 0; i < nr_vcpus; i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user