aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>2011-05-07 03:35:38 -0400
committerAvi Kivity <avi@redhat.com>2011-05-22 08:47:56 -0400
commitfa3d315a4ce2c0891cdde262562e710d95fba19e (patch)
tree79205998f6734b51628f92641124dbe4aaa9882f
parent12cb814f3bb35736420cc6bfc9fed7b6a9d3a828 (diff)
KVM: Validate userspace_addr of memslot when registered
This way, we can avoid checking the user space address many times when we read the guest memory. Although we can do the same for write if we check which slots are writable, we do not care write now: reading the guest memory happens more often than writing. [avi: change VERIFY_READ to VERIFY_WRITE] Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--arch/x86/kvm/paging_tmpl.h2
-rw-r--r--virt/kvm/kvm_main.c7
2 files changed, 6 insertions, 3 deletions
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 88ca456ccd68..e3f81418797e 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -185,7 +185,7 @@ walk:
185 } 185 }
186 186
187 ptep_user = (pt_element_t __user *)((void *)host_addr + offset); 187 ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
188 if (unlikely(copy_from_user(&pte, ptep_user, sizeof(pte)))) { 188 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte)))) {
189 present = false; 189 present = false;
190 break; 190 break;
191 } 191 }
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 58146457bf97..ed3c4e7c1008 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -648,7 +648,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
648 goto out; 648 goto out;
649 if (mem->guest_phys_addr & (PAGE_SIZE - 1)) 649 if (mem->guest_phys_addr & (PAGE_SIZE - 1))
650 goto out; 650 goto out;
651 if (user_alloc && (mem->userspace_addr & (PAGE_SIZE - 1))) 651 /* We can read the guest memory with __xxx_user() later on. */
652 if (user_alloc &&
653 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
654 !access_ok(VERIFY_WRITE, mem->userspace_addr, mem->memory_size)))
652 goto out; 655 goto out;
653 if (mem->slot >= KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS) 656 if (mem->slot >= KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS)
654 goto out; 657 goto out;
@@ -1283,7 +1286,7 @@ int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
1283 addr = gfn_to_hva(kvm, gfn); 1286 addr = gfn_to_hva(kvm, gfn);
1284 if (kvm_is_error_hva(addr)) 1287 if (kvm_is_error_hva(addr))
1285 return -EFAULT; 1288 return -EFAULT;
1286 r = copy_from_user(data, (void __user *)addr + offset, len); 1289 r = __copy_from_user(data, (void __user *)addr + offset, len);
1287 if (r) 1290 if (r)
1288 return -EFAULT; 1291 return -EFAULT;
1289 return 0; 1292 return 0;