Skip to content

Commit 8750f9b

Browse files
committed
KVM: add missing compat KVM_CLEAR_DIRTY_LOG
The arguments to the KVM_CLEAR_DIRTY_LOG ioctl include a pointer, therefore it needs a compat ioctl implementation. Otherwise, 32-bit userspace fails to invoke it on 64-bit kernels; for x86 it might work fine by chance if the padding is zero, but not on big-endian architectures. Reported-by: Thomas Sattler Cc: [email protected] Fixes: 2a31b9d ("kvm: introduce manual dirty log reprotect") Reviewed-by: Peter Xu <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 7477565 commit 8750f9b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

virt/kvm/kvm_main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4391,6 +4391,16 @@ struct compat_kvm_dirty_log {
43914391
};
43924392
};
43934393

4394+
struct compat_kvm_clear_dirty_log {
4395+
__u32 slot;
4396+
__u32 num_pages;
4397+
__u64 first_page;
4398+
union {
4399+
compat_uptr_t dirty_bitmap; /* one bit per page */
4400+
__u64 padding2;
4401+
};
4402+
};
4403+
43944404
static long kvm_vm_compat_ioctl(struct file *filp,
43954405
unsigned int ioctl, unsigned long arg)
43964406
{
@@ -4400,6 +4410,24 @@ static long kvm_vm_compat_ioctl(struct file *filp,
44004410
if (kvm->mm != current->mm)
44014411
return -EIO;
44024412
switch (ioctl) {
4413+
#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
4414+
case KVM_CLEAR_DIRTY_LOG: {
4415+
struct compat_kvm_clear_dirty_log compat_log;
4416+
struct kvm_clear_dirty_log log;
4417+
4418+
if (copy_from_user(&compat_log, (void __user *)arg,
4419+
sizeof(compat_log)))
4420+
return -EFAULT;
4421+
log.slot = compat_log.slot;
4422+
log.num_pages = compat_log.num_pages;
4423+
log.first_page = compat_log.first_page;
4424+
log.padding2 = compat_log.padding2;
4425+
log.dirty_bitmap = compat_ptr(compat_log.dirty_bitmap);
4426+
4427+
r = kvm_vm_ioctl_clear_dirty_log(kvm, &log);
4428+
break;
4429+
}
4430+
#endif
44034431
case KVM_GET_DIRTY_LOG: {
44044432
struct compat_kvm_dirty_log compat_log;
44054433
struct kvm_dirty_log log;

0 commit comments

Comments
 (0)