drm: return -EFAULT if copy_one_buf() fails
Subsystems (3)
PATCH 1/1 drm: return -EFAULT if copy_one_buf() fails
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.
---
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(-)
drivers/gpu/drm/drm_bufs.c +4 -1
@@ -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,
Signature · 1 line
2.20.1
Ah crap. I need to fix copy_one_buf32() as well. I will sent a v2.
regards,
dan carpenter
PATCH v2 1/1 drm: return -EFAULT if copy_to_user() fails
In reply to Dan CarpenterThe 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.
---
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(-)
drivers/gpu/drm/drm_bufs.c +4 -1
@@ -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,
drivers/gpu/drm/drm_ioc32.c +4 -1
@@ -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,
Signature · 1 line
2.20.1
Re: [PATCH v2] drm: return -EFAULT if copy_to_user() fails
Quoted 5 lines · Dan Carpenter
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 <[email protected]>
Thanks Dan, I've applied this to drm-misc-fixes.
Sean
Quoted 42 lines
---
v2: The first version was missing a chunkdrivers/gpu/drm/drm_bufs.c | 5 ++++- drivers/gpu/drm/drm_ioc32.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_bufs.c +4
-1@@ -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,drivers/gpu/drm/drm_ioc32.c +4
-1@@ -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,Signature · 1 line
2.20.1
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
Re: [PATCH v2] drm: return -EFAULT if copy_to_user() fails
Quoted 8 lines · Sean Paul
Quoted 5 lines · Dan Carpenter
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 <[email protected]>Thanks Dan, I've applied this to drm-misc-fixes.
FWIW, Acked-by: Al Viro <[email protected]>
Quoted 9 lines · Dan Carpenter
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 <[email protected]>---
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...