Skip to content

Commit

Permalink
VMCI: use memdup_user().
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
mfrw authored and gregkh committed Aug 31, 2016
1 parent b58189b commit 655745b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions drivers/misc/vmw_vmci/vmci_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 655745b

Please sign in to comment.