public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 1/3] vfio-mdev: return -EFAULT if copy_to_user() fails
@ 2017-01-07  6:27 Dan Carpenter
  2017-01-09 18:49 ` Kirti Wankhede
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2017-01-07  6:27 UTC (permalink / raw)
  To: Kirti Wankhede; +Cc: kvm, kernel-janitors

The copy_to_user() function returns the number of bytes which it wasn't
able to copy but we want to return a negative error code.

Fixes: 9d1a546c53b4 ("docs: Sample driver to demonstrate how to use Mediated device framework.")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 919c10d5b12e..d2656ff569c1 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1180,7 +1180,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
 
 		memcpy(&mdev_state->dev_info, &info, sizeof(info));
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+
+		return 0;
 	}
 	case VFIO_DEVICE_GET_REGION_INFO:
 	{
@@ -1201,7 +1204,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
 		if (ret)
 			return ret;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+
+		return 0;
 	}
 
 	case VFIO_DEVICE_GET_IRQ_INFO:
@@ -1224,7 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
 		if (info.count = -1)
 			return -EINVAL;
 
-		return copy_to_user((void __user *)arg, &info, minsz);
+		if (copy_to_user((void __user *)arg, &info, minsz))
+			return -EFAULT;
+
+		return 0;
 	}
 	case VFIO_DEVICE_SET_IRQS:
 	{

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch 1/3] vfio-mdev: return -EFAULT if copy_to_user() fails
  2017-01-07  6:27 [patch 1/3] vfio-mdev: return -EFAULT if copy_to_user() fails Dan Carpenter
@ 2017-01-09 18:49 ` Kirti Wankhede
  2017-01-11 19:15   ` Alex Williamson
  0 siblings, 1 reply; 3+ messages in thread
From: Kirti Wankhede @ 2017-01-09 18:49 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: kvm, kernel-janitors, Alex Williamson


CC+= Alex to pull this change.

Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>

Thanks,
Kirti

On 1/7/2017 11:57 AM, Dan Carpenter wrote:
> The copy_to_user() function returns the number of bytes which it wasn't
> able to copy but we want to return a negative error code.
> 
> Fixes: 9d1a546c53b4 ("docs: Sample driver to demonstrate how to use Mediated device framework.")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
> index 919c10d5b12e..d2656ff569c1 100644
> --- a/samples/vfio-mdev/mtty.c
> +++ b/samples/vfio-mdev/mtty.c
> @@ -1180,7 +1180,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
>  
>  		memcpy(&mdev_state->dev_info, &info, sizeof(info));
>  
> -		return copy_to_user((void __user *)arg, &info, minsz);
> +		if (copy_to_user((void __user *)arg, &info, minsz))
> +			return -EFAULT;
> +
> +		return 0;
>  	}
>  	case VFIO_DEVICE_GET_REGION_INFO:
>  	{
> @@ -1201,7 +1204,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
>  		if (ret)
>  			return ret;
>  
> -		return copy_to_user((void __user *)arg, &info, minsz);
> +		if (copy_to_user((void __user *)arg, &info, minsz))
> +			return -EFAULT;
> +
> +		return 0;
>  	}
>  
>  	case VFIO_DEVICE_GET_IRQ_INFO:
> @@ -1224,7 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
>  		if (info.count = -1)
>  			return -EINVAL;
>  
> -		return copy_to_user((void __user *)arg, &info, minsz);
> +		if (copy_to_user((void __user *)arg, &info, minsz))
> +			return -EFAULT;
> +
> +		return 0;
>  	}
>  	case VFIO_DEVICE_SET_IRQS:
>  	{
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/3] vfio-mdev: return -EFAULT if copy_to_user() fails
  2017-01-09 18:49 ` Kirti Wankhede
@ 2017-01-11 19:15   ` Alex Williamson
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2017-01-11 19:15 UTC (permalink / raw)
  To: Kirti Wankhede; +Cc: Dan Carpenter, kvm, kernel-janitors

On Tue, 10 Jan 2017 00:07:23 +0530
Kirti Wankhede <kwankhede@nvidia.com> wrote:

> CC+= Alex to pull this change.
> 
> Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>

Thanks Dan.  Applied all three to for-linus for v4.10 with Kirti's R-b.
Thanks,

Alex

> On 1/7/2017 11:57 AM, Dan Carpenter wrote:
> > The copy_to_user() function returns the number of bytes which it wasn't
> > able to copy but we want to return a negative error code.
> > 
> > Fixes: 9d1a546c53b4 ("docs: Sample driver to demonstrate how to use Mediated device framework.")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
> > index 919c10d5b12e..d2656ff569c1 100644
> > --- a/samples/vfio-mdev/mtty.c
> > +++ b/samples/vfio-mdev/mtty.c
> > @@ -1180,7 +1180,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
> >  
> >  		memcpy(&mdev_state->dev_info, &info, sizeof(info));
> >  
> > -		return copy_to_user((void __user *)arg, &info, minsz);
> > +		if (copy_to_user((void __user *)arg, &info, minsz))
> > +			return -EFAULT;
> > +
> > +		return 0;
> >  	}
> >  	case VFIO_DEVICE_GET_REGION_INFO:
> >  	{
> > @@ -1201,7 +1204,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
> >  		if (ret)
> >  			return ret;
> >  
> > -		return copy_to_user((void __user *)arg, &info, minsz);
> > +		if (copy_to_user((void __user *)arg, &info, minsz))
> > +			return -EFAULT;
> > +
> > +		return 0;
> >  	}
> >  
> >  	case VFIO_DEVICE_GET_IRQ_INFO:
> > @@ -1224,7 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
> >  		if (info.count = -1)
> >  			return -EINVAL;
> >  
> > -		return copy_to_user((void __user *)arg, &info, minsz);
> > +		if (copy_to_user((void __user *)arg, &info, minsz))
> > +			return -EFAULT;
> > +
> > +		return 0;
> >  	}
> >  	case VFIO_DEVICE_SET_IRQS:
> >  	{
> >   
> --
> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-11 19:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-07  6:27 [patch 1/3] vfio-mdev: return -EFAULT if copy_to_user() fails Dan Carpenter
2017-01-09 18:49 ` Kirti Wankhede
2017-01-11 19:15   ` Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox