2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-17 09:43:59 +08:00

VMCI: use memdup_user().

Use memdup_user to duplicate a memory region from user-space to
kernel-space, instead of open coding using kmalloc & copy_from_user.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Muhammad Falak R Wani 2016-05-20 17:48:56 +05:30 committed by Greg Kroah-Hartman
parent b58189b3c5
commit 655745b0d1

View File

@ -381,18 +381,12 @@ static int vmci_host_do_send_datagram(struct vmci_host_dev *vmci_host_dev,
return -EINVAL;
}
dg = kmalloc(send_info.len, GFP_KERNEL);
if (!dg) {
dg = memdup_user((void __user *)(uintptr_t)send_info.addr,
send_info.len);
if (IS_ERR(dg)) {
vmci_ioctl_err(
"cannot allocate memory to dispatch datagram\n");
return -ENOMEM;
}
if (copy_from_user(dg, (void __user *)(uintptr_t)send_info.addr,
send_info.len)) {
vmci_ioctl_err("error getting datagram\n");
kfree(dg);
return -EFAULT;
return PTR_ERR(dg);
}
if (VMCI_DG_SIZE(dg) != send_info.len) {