diff mbox series

drm: return -EFAULT if copy_one_buf() fails

Message ID 20190618125623.GA24896@mwanda (mailing list archive)
State New, archived
Headers show
Series drm: return -EFAULT if copy_one_buf() fails | expand

Commit Message

Dan Carpenter June 18, 2019, 12:56 p.m. UTC
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(-)

Comments

Dan Carpenter June 18, 2019, 12:58 p.m. UTC | #1
Ah crap.  I need to fix copy_one_buf32() as well.  I will sent a v2.

regards,
dan carpenter
Al Viro June 25, 2019, 11:17 p.m. UTC | #2
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...
diff mbox series

Patch

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,