Skip to content

Commit

Permalink
KVM: fix missing check for memslot flags
Browse files Browse the repository at this point in the history
Check flags when memslot is registered from userspace as Avi's suggestion

Signed-off-by: Xiao Guangrong <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>
  • Loading branch information
Xiao Guangrong authored and avikivity committed Aug 22, 2012
1 parent 8e3d9d0 commit a50d64d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,14 @@ void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new)
slots->generation++;
}

static int check_memory_region_flags(struct kvm_userspace_memory_region *mem)
{
if (mem->flags & ~KVM_MEM_LOG_DIRTY_PAGES)
return -EINVAL;

return 0;
}

/*
* Allocate some memory and give it an address in the guest physical address
* space.
Expand All @@ -698,6 +706,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
struct kvm_memory_slot old, new;
struct kvm_memslots *slots, *old_memslots;

r = check_memory_region_flags(mem);
if (r)
goto out;

r = -EINVAL;
/* General sanity checks */
if (mem->memory_size & (PAGE_SIZE - 1))
Expand Down

0 comments on commit a50d64d

Please sign in to comment.