summaryrefslogtreecommitdiff
path: root/virt
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2012-12-10 21:32:51 +0400
committerMarcelo Tosatti <mtosatti@redhat.com>2012-12-14 05:21:51 +0400
commit9c695d42dbd465bcaa865603b411a73c60e60978 (patch)
treeee8348edbd718928a384e2eb19103b3d163607ed /virt
parentf0736cf0550b349a5d5a374d65ca0488cc2eee40 (diff)
downloadlinux-9c695d42dbd465bcaa865603b411a73c60e60978.tar.xz
KVM: Check userspace_addr when modifying a memory slot
The API documents that only flags and guest physical memory space can be modified on an existing slot, but we don't enforce that the userspace address cannot be modified. Instead we just ignore it. This means that a user may think they've successfully moved both the guest and user addresses, when in fact only the guest address changed. Check and error instead. Reviewed-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3caf8162eb6b..e4d358195e54 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -784,13 +784,19 @@ int __kvm_set_memory_region(struct kvm *kvm,
r = -ENOMEM;
- /* Allocate if a slot is being created */
+ /*
+ * Allocate if a slot is being created. If modifying a slot,
+ * the userspace_addr cannot change.
+ */
if (!old.npages) {
new.user_alloc = user_alloc;
new.userspace_addr = mem->userspace_addr;
if (kvm_arch_create_memslot(&new, npages))
goto out_free;
+ } else if (npages && mem->userspace_addr != old.userspace_addr) {
+ r = -EINVAL;
+ goto out_free;
}
/* Allocate page dirty bitmap if needed */