kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: return -EFAULT if copy_one_buf() fails
@ 2019-06-18 12:56 Dan Carpenter
  2019-06-18 12:58 ` Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-06-18 12:56 UTC (permalink / raw)
  To: Al Viro
  Cc: Maxime Ripard, kernel-janitors, dri-devel, David Airlie, Sean Paul

The copy_to_user() function returns the number of bytes remaining to be
copied, but we want to return -EFAULT.  This function is called from
__drm_legacy_infobufs() which expects negative error codes.

Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This goes through Al's tree and not through drm.  Presumably this patch
will just get folded into the original.

 drivers/gpu/drm/drm_bufs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 68dacf8422c6..8ce9d73fab4f 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1351,7 +1351,10 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
 				 .size = from->buf_size,
 				 .low_mark = from->low_mark,
 				 .high_mark = from->high_mark};
-	return copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags));
+
+	if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
+		return -EFAULT;
+	return 0;
 }
 
 int drm_legacy_infobufs(struct drm_device *dev, void *data,
-- 
2.20.1

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

* Re: [PATCH] drm: return -EFAULT if copy_one_buf() fails
  2019-06-18 12:56 [PATCH] drm: return -EFAULT if copy_one_buf() fails Dan Carpenter
@ 2019-06-18 12:58 ` Dan Carpenter
  2019-06-18 13:18 ` [PATCH v2] drm: return -EFAULT if copy_to_user() fails Dan Carpenter
  2019-06-25 23:17 ` [PATCH] drm: return -EFAULT if copy_one_buf() fails Al Viro
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-06-18 12:58 UTC (permalink / raw)
  To: Al Viro
  Cc: Maxime Ripard, kernel-janitors, dri-devel, David Airlie, Sean Paul

Ah crap.  I need to fix copy_one_buf32() as well.  I will sent a v2.

regards,
dan carpenter

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

* [PATCH v2] drm: return -EFAULT if copy_to_user() fails
  2019-06-18 12:56 [PATCH] drm: return -EFAULT if copy_one_buf() fails Dan Carpenter
  2019-06-18 12:58 ` Dan Carpenter
@ 2019-06-18 13:18 ` Dan Carpenter
  2019-06-18 17:16   ` Sean Paul
  2019-06-25 23:17 ` [PATCH] drm: return -EFAULT if copy_one_buf() fails Al Viro
  2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2019-06-18 13:18 UTC (permalink / raw)
  To: Al Viro
  Cc: Maxime Ripard, kernel-janitors, linux-kernel, dri-devel,
	David Airlie, Sean Paul

The copy_from_user() function returns the number of bytes remaining
to be copied but we want to return a negative error code.  Otherwise
the callers treat it as a successful copy.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: The first version was missing a chunk

 drivers/gpu/drm/drm_bufs.c  | 5 ++++-
 drivers/gpu/drm/drm_ioc32.c | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 68dacf8422c6..8ce9d73fab4f 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1351,7 +1351,10 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
 				 .size = from->buf_size,
 				 .low_mark = from->low_mark,
 				 .high_mark = from->high_mark};
-	return copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags));
+
+	if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
+		return -EFAULT;
+	return 0;
 }
 
 int drm_legacy_infobufs(struct drm_device *dev, void *data,
diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
index 586aa28024c5..a16b6dc2fa47 100644
--- a/drivers/gpu/drm/drm_ioc32.c
+++ b/drivers/gpu/drm/drm_ioc32.c
@@ -378,7 +378,10 @@ static int copy_one_buf32(void *data, int count, struct drm_buf_entry *from)
 			      .size = from->buf_size,
 			      .low_mark = from->low_mark,
 			      .high_mark = from->high_mark};
-	return copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags));
+
+	if (copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags)))
+		return -EFAULT;
+	return 0;
 }
 
 static int drm_legacy_infobufs32(struct drm_device *dev, void *data,
-- 
2.20.1

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

* Re: [PATCH v2] drm: return -EFAULT if copy_to_user() fails
  2019-06-18 13:18 ` [PATCH v2] drm: return -EFAULT if copy_to_user() fails Dan Carpenter
@ 2019-06-18 17:16   ` Sean Paul
  2019-06-25 23:18     ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Paul @ 2019-06-18 17:16 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Maxime Ripard, kernel-janitors, linux-kernel, dri-devel,
	David Airlie, Al Viro, Sean Paul

On Tue, Jun 18, 2019 at 04:18:43PM +0300, Dan Carpenter wrote:
> The copy_from_user() function returns the number of bytes remaining
> to be copied but we want to return a negative error code.  Otherwise
> the callers treat it as a successful copy.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks Dan, I've applied this to drm-misc-fixes.

Sean

> ---
> v2: The first version was missing a chunk
> 
>  drivers/gpu/drm/drm_bufs.c  | 5 ++++-
>  drivers/gpu/drm/drm_ioc32.c | 5 ++++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index 68dacf8422c6..8ce9d73fab4f 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -1351,7 +1351,10 @@ static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
>  				 .size = from->buf_size,
>  				 .low_mark = from->low_mark,
>  				 .high_mark = from->high_mark};
> -	return copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags));
> +
> +	if (copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags)))
> +		return -EFAULT;
> +	return 0;
>  }
>  
>  int drm_legacy_infobufs(struct drm_device *dev, void *data,
> diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
> index 586aa28024c5..a16b6dc2fa47 100644
> --- a/drivers/gpu/drm/drm_ioc32.c
> +++ b/drivers/gpu/drm/drm_ioc32.c
> @@ -378,7 +378,10 @@ static int copy_one_buf32(void *data, int count, struct drm_buf_entry *from)
>  			      .size = from->buf_size,
>  			      .low_mark = from->low_mark,
>  			      .high_mark = from->high_mark};
> -	return copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags));
> +
> +	if (copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags)))
> +		return -EFAULT;
> +	return 0;
>  }
>  
>  static int drm_legacy_infobufs32(struct drm_device *dev, void *data,
> -- 
> 2.20.1
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS

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

* Re: [PATCH] drm: return -EFAULT if copy_one_buf() fails
  2019-06-18 12:56 [PATCH] drm: return -EFAULT if copy_one_buf() fails Dan Carpenter
  2019-06-18 12:58 ` Dan Carpenter
  2019-06-18 13:18 ` [PATCH v2] drm: return -EFAULT if copy_to_user() fails Dan Carpenter
@ 2019-06-25 23:17 ` Al Viro
  2 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2019-06-25 23:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Maxime Ripard, kernel-janitors, dri-devel, David Airlie, Sean Paul

On Tue, Jun 18, 2019 at 03:56:23PM +0300, Dan Carpenter wrote:
> The copy_to_user() function returns the number of bytes remaining to be
> copied, but we want to return -EFAULT.  This function is called from
> __drm_legacy_infobufs() which expects negative error codes.
> 
> Fixes: 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This goes through Al's tree and not through drm.  Presumably this patch
> will just get folded into the original.

Wha..?  The original has been in mainline since v4.13, so it's a bit too
late to fold anything into it...

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

* Re: [PATCH v2] drm: return -EFAULT if copy_to_user() fails
  2019-06-18 17:16   ` Sean Paul
@ 2019-06-25 23:18     ` Al Viro
  0 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2019-06-25 23:18 UTC (permalink / raw)
  To: Sean Paul
  Cc: Dan Carpenter, Maarten Lankhorst, Maxime Ripard, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel, kernel-janitors

On Tue, Jun 18, 2019 at 01:16:29PM -0400, Sean Paul wrote:
> On Tue, Jun 18, 2019 at 04:18:43PM +0300, Dan Carpenter wrote:
> > The copy_from_user() function returns the number of bytes remaining
> > to be copied but we want to return a negative error code.  Otherwise
> > the callers treat it as a successful copy.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thanks Dan, I've applied this to drm-misc-fixes.

FWIW, Acked-by: Al Viro <viro@zeniv.linux.org.uk>

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

end of thread, other threads:[~2019-06-25 23:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 12:56 [PATCH] drm: return -EFAULT if copy_one_buf() fails Dan Carpenter
2019-06-18 12:58 ` Dan Carpenter
2019-06-18 13:18 ` [PATCH v2] drm: return -EFAULT if copy_to_user() fails Dan Carpenter
2019-06-18 17:16   ` Sean Paul
2019-06-25 23:18     ` Al Viro
2019-06-25 23:17 ` [PATCH] drm: return -EFAULT if copy_one_buf() fails Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).