Skip to content

Commit 09d952c

Browse files
committed
KVM: check userspace_addr for all memslots
The userspace_addr alignment and range checks are not performed for private memory slots that are prepared by KVM itself. This is unnecessary and makes it questionable to use __*_user functions to access memory later on. We also rely on the userspace address being aligned since we have an entire family of functions to map gfn to pfn. Fortunately skipping the check is completely unnecessary. Only x86 uses private memslots and their userspace_addr is obtained from vm_mmap, therefore it must be below PAGE_OFFSET. In fact, any attempt to pass an address above PAGE_OFFSET would have failed because such an address would return true for kvm_is_error_hva. Reported-by: Linus Torvalds <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent fb0cb6a commit 09d952c

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

virt/kvm/kvm_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,10 +1225,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
12251225
if (mem->guest_phys_addr & (PAGE_SIZE - 1))
12261226
return -EINVAL;
12271227
/* We can read the guest memory with __xxx_user() later on. */
1228-
if ((id < KVM_USER_MEM_SLOTS) &&
1229-
((mem->userspace_addr & (PAGE_SIZE - 1)) ||
1228+
if ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
12301229
!access_ok((void __user *)(unsigned long)mem->userspace_addr,
1231-
mem->memory_size)))
1230+
mem->memory_size))
12321231
return -EINVAL;
12331232
if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_MEM_SLOTS_NUM)
12341233
return -EINVAL;

0 commit comments

Comments
 (0)