Skip to contentSkip to conversation

drm/amdgpu: check the result of copy_from_user in secure display debugfs

PATCH In review Alex Deucher 2 participants 2 messages Jan 4, 2021

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

PATCH 1/1 drm/amdgpu: check the result of copy_from_user in secure display debugfs

Make sure the copy succeeded. Also fixes a warning.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +3 -1
index 455978781380..1f98ce4e56f2 100644
@@ -101,7 +101,9 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u
 		return -EINVAL;
 
 	memset(str,  0, sizeof(str));
-	copy_from_user(str, buf, size);
+	ret = copy_from_user(str, buf, size);
+	if (ret >= size)
+		return -EINVAL;
 
 	ret = pm_runtime_get_sync(dev->dev);
 	if (ret < 0) {
Signature · 6 lines
2.29.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

Am 04.01.21 um 18:43 schrieb Alex Deucher:

Quoted 12 lines

Make sure the copy succeeded. Also fixes a warning.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +0 -0
index 455978781380..1f98ce4e56f2 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u · line 106

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +3 -1
@@ -101,7 +101,9 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u
  		return -EINVAL;
 
  	memset(str,  0, sizeof(str));
-	copy_from_user(str, buf, size);
+	ret = copy_from_user(str, buf, size);
+	if (ret >= size)
+		return -EINVAL;

IIRC copy_from_user return the number of bytes which couldn't be copied.

E.g. theta should be if (ret) return -EFAULT.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u · line 109

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +0 -0
  	ret = pm_runtime_get_sync(dev->dev);
  	if (ret < 0) {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx