From: Dan Carpenter Date: Thu, 25 Feb 2016 07:52:12 +0000 (+0300) Subject: vfio/pci: return -EFAULT if copy_to_user fails X-Git-Tag: next-20160301~47^2 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=c4aec3101319f84363a57e09086c2aff6c60a3c3;p=karo-tx-linux.git vfio/pci: return -EFAULT if copy_to_user fails The copy_to_user() function returns the number of bytes that were not copied but we want to return -EFAULT on error here. Fixes: 188ad9d6cbbc ('vfio/pci: Include sparse mmap capability for MSI-X table regions') Signed-off-by: Dan Carpenter Signed-off-by: Alex Williamson --- diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 1ce1d364308c..98059df9cff6 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -664,12 +664,11 @@ static long vfio_pci_ioctl(void *device_data, info.cap_offset = 0; } else { vfio_info_cap_shift(&caps, sizeof(info)); - ret = copy_to_user((void __user *)arg + - sizeof(info), caps.buf, - caps.size); - if (ret) { + if (copy_to_user((void __user *)arg + + sizeof(info), caps.buf, + caps.size)) { kfree(caps.buf); - return ret; + return -EFAULT; } info.cap_offset = sizeof(info); }