Skip to content

Commit

Permalink
KVM: Check userspace_addr when modifying a memory slot
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Alex Williamson <[email protected]>
Signed-off-by: Marcelo Tosatti <[email protected]>
  • Loading branch information
awilliam authored and matosatti committed Dec 14, 2012
1 parent f0736cf commit 9c695d4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 9c695d4

Please sign in to comment.