]> git.karo-electronics.de Git - linux-beck.git/commitdiff
KVM: Check userspace_addr when modifying a memory slot
authorAlex Williamson <alex.williamson@redhat.com>
Mon, 10 Dec 2012 17:32:51 +0000 (10:32 -0700)
committerMarcelo Tosatti <mtosatti@redhat.com>
Fri, 14 Dec 2012 01:21:51 +0000 (23:21 -0200)
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>
virt/kvm/kvm_main.c

index 3caf8162eb6b191f74a2cf2f012184717b7ab163..e4d358195e540c3fa668721bb13b40478936212d 100644 (file)
@@ -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 */