Skip to content

Commit 89be254

Browse files
schlacfrankjaa
authored andcommitted
KVM: s390: selftests: Verify reject memory region operations for ucontrol VMs
Add a test case verifying KVM_SET_USER_MEMORY_REGION and KVM_SET_USER_MEMORY_REGION2 cannot be executed on ucontrol VMs. Executing this test case on not patched kernels will cause a null pointer dereference in the host kernel. This is fixed with commit: commit 7816e58 ("kvm: s390: Reject memory region operations for ucontrol VMs") Signed-off-by: Christoph Schlameuss <[email protected]> Reviewed-by: Janosch Frank <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fixed patch prefix] Signed-off-by: Janosch Frank <[email protected]> Message-ID: <[email protected]>
1 parent 0185fbc commit 89be254

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tools/testing/selftests/kvm/s390x/ucontrol_test.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,28 @@ static void uc_assert_diag44(FIXTURE_DATA(uc_kvm) * self)
440440
TEST_ASSERT_EQ(0x440000, sie_block->ipb);
441441
}
442442

443+
TEST_F(uc_kvm, uc_no_user_region)
444+
{
445+
struct kvm_userspace_memory_region region = {
446+
.slot = 1,
447+
.guest_phys_addr = self->code_gpa,
448+
.memory_size = VM_MEM_EXT_SIZE,
449+
.userspace_addr = (uintptr_t)self->code_hva,
450+
};
451+
struct kvm_userspace_memory_region2 region2 = {
452+
.slot = 1,
453+
.guest_phys_addr = self->code_gpa,
454+
.memory_size = VM_MEM_EXT_SIZE,
455+
.userspace_addr = (uintptr_t)self->code_hva,
456+
};
457+
458+
ASSERT_EQ(-1, ioctl(self->vm_fd, KVM_SET_USER_MEMORY_REGION, &region));
459+
ASSERT_EQ(EINVAL, errno);
460+
461+
ASSERT_EQ(-1, ioctl(self->vm_fd, KVM_SET_USER_MEMORY_REGION2, &region2));
462+
ASSERT_EQ(EINVAL, errno);
463+
}
464+
443465
TEST_F(uc_kvm, uc_map_unmap)
444466
{
445467
struct kvm_sync_regs *sync_regs = &self->run->s.regs;

0 commit comments

Comments
 (0)