Skip to contentSkip to conversation

drm: return -EFAULT if copy_one_buf() fails

PATCH Superseded Dan Carpenter 3 participants 6 messages Jun 18, 2019 – Jun 25, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 5c7640ab6258 ("switch compat_drm_infobufs() to drm_ioctl_kernel()")

---
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
index 68dacf8422c6..8ce9d73fab4f 100644
@@ -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
#1 lore raw

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

regards,
dan carpenter

#2 lore raw

PATCH v2 1/1 drm: return -EFAULT if copy_to_user() fails

In reply to 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.

---
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
index 68dacf8422c6..8ce9d73fab4f 100644
@@ -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
index 586aa28024c5..a16b6dc2fa47 100644
@@ -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
#3 lore raw

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.

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

Sean

Quoted 42 lines

---
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
index 68dacf8422c6..8ce9d73fab4f 100644
@@ -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
index 586aa28024c5..a16b6dc2fa47 100644
@@ -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
#4 lore raw

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.

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

FWIW, Acked-by: Al Viro <[email protected]>

#5 lore raw
In reply to Dan Carpenter
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()")

---
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...