]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
drm: return -EFAULT if copy_to_user() fails
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 18 Jun 2019 13:18:43 +0000 (16:18 +0300)
committerSean Paul <seanpaul@chromium.org>
Tue, 18 Jun 2019 17:08:48 +0000 (13:08 -0400)
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>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190618131843.GA29463@mwanda
drivers/gpu/drm/drm_bufs.c
drivers/gpu/drm/drm_ioc32.c

index bfc419ed9d6c54b7db8ea464f738e3843dbed95d..ceca79b1468d8a0ed630e07a4e1fe0f9fb9ac12e 100644 (file)
@@ -1340,7 +1340,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,
index 374b372da58a4e290e62ecb62a3dbcbfd3c64586..3972ebe48463d8716f8786f136f05ca2cdbe5c30 100644 (file)
@@ -375,7 +375,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,