Commit c7cc4d56 authored by Sean Christopherson's avatar Sean Christopherson Committed by Lin Wang
Browse files

KVM: x86: Add a helper to retrieve userspace address from kvm_device_attr

mainline inclusion
from mainline-v5.17-rc2
commit 56f289a8
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5RQLJ


CVE: NA

Intel-SIG: commit 56f289a8 KVM: x86: Add a helper to retrieve userspace address from kvm_device_attr.

--------------------------------

Add a helper to handle converting the u64 userspace address embedded in
struct kvm_device_attr into a userspace pointer, it's all too easy to
forget the intermediate "unsigned long" cast as well as the truncation
check.

No functional change intended.

Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarLin Wang <lin.x.wang@intel.com>
parent d108c31b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -4006,7 +4006,15 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
		break;
	}
	return r;
}

static inline void __user *kvm_get_attr_addr(struct kvm_device_attr *attr)
{
	void __user *uaddr = (void __user*)(unsigned long)attr->addr;

	if ((u64)(unsigned long)uaddr != attr->addr)
		return ERR_PTR(-EFAULT);
	return uaddr;
}

long kvm_arch_dev_ioctl(struct file *filp,