From: Peter Xu Date: Wed, 8 May 2019 09:15:45 +0000 (+0800) Subject: KVM: Fix the bitmap range to copy during clear dirty X-Git-Tag: v5.0.18~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87e61d57ae37677c635098ecb33ab25431d7cc6f;p=thirdparty%2Fkernel%2Fstable.git KVM: Fix the bitmap range to copy during clear dirty commit 4ddc9204572c33f2eb91fbdb1d99d8078388b67d upstream. kvm_dirty_bitmap_bytes() will return the size of the dirty bitmap of the memslot rather than the size of bitmap passed over from the ioctl. Here for KVM_CLEAR_DIRTY_LOG we should only copy exactly the size of bitmap that covers kvm_clear_dirty_log.num_pages. Signed-off-by: Peter Xu Cc: stable@vger.kernel.org Fixes: 2a31b9db153530df4aa02dac8c32837bf5f47019 Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ff68b07e94e97..b5238bcba72cb 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1251,7 +1251,7 @@ int kvm_clear_dirty_log_protect(struct kvm *kvm, if (!dirty_bitmap) return -ENOENT; - n = kvm_dirty_bitmap_bytes(memslot); + n = ALIGN(log->num_pages, BITS_PER_LONG) / 8; if (log->first_page > memslot->npages || log->num_pages > memslot->npages - log->first_page)