diff mbox

vfio/pci: return -EFAULT if copy_to_user fails

Message ID 20160225075212.GD7333@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter Feb. 25, 2016, 7:52 a.m. UTC
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 <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Michael S. Tsirkin Feb. 25, 2016, 9:28 a.m. UTC | #1
On Thu, Feb 25, 2016 at 10:52:12AM +0300, Dan Carpenter wrote:
> 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')

Where's this commit? In which tree?

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 1ce1d36..98059df 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);
>  			}
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter Feb. 25, 2016, 11:09 a.m. UTC | #2
On Thu, Feb 25, 2016 at 11:28:54AM +0200, Michael S. Tsirkin wrote:
> On Thu, Feb 25, 2016 at 10:52:12AM +0300, Dan Carpenter wrote:
> > 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')
> 
> Where's this commit? In which tree?

linux-next.  It only has Alex's signed off by.  So likely my patch will
be folded in?

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael S. Tsirkin Feb. 25, 2016, 11:33 a.m. UTC | #3
On Thu, Feb 25, 2016 at 02:09:44PM +0300, Dan Carpenter wrote:
> On Thu, Feb 25, 2016 at 11:28:54AM +0200, Michael S. Tsirkin wrote:
> > On Thu, Feb 25, 2016 at 10:52:12AM +0300, Dan Carpenter wrote:
> > > 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')
> > 
> > Where's this commit? In which tree?
> 
> linux-next.  It only has Alex's signed off by.  So likely my patch will
> be folded in?
> 
> regards,
> dan carpenter

BTW, vfio repeats this in otherplaces.
I'll fix it up.
Michael S. Tsirkin Feb. 25, 2016, 11:34 a.m. UTC | #4
On Thu, Feb 25, 2016 at 10:52:12AM +0300, Dan Carpenter wrote:
> 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 <dan.carpenter@oracle.com>


Acked-by: Michael S. Tsirkin <mst@redhat.com>

I posted a patch to fix up all other places.


> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 1ce1d36..98059df 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);
>  			}
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alex Williamson Feb. 28, 2016, 2:05 p.m. UTC | #5
On Thu, 25 Feb 2016 10:52:12 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> 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 <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 1ce1d36..98059df 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);
>  			}

Applied to next.  Thanks,

Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 1ce1d36..98059df 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);
 			}