Skip to contentSkip to conversation

drm/amdgpu: Fix error codes if copy_to_user() fails

PATCH Applied Dan Carpenter 3 participants 3 messages Sep 4, 2025 – Sep 5, 2025

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

PATCH 1/1 drm/amdgpu: Fix error codes if copy_to_user() fails

The copy_to_user() function returns the number of bytes that it wasn't able to copy, but we should return -EFAULT to the user.

Fixes 4d82724f7f2b ("drm/amdgpu: Add mapping info option for GEM_OP ioctl")
Fixes f9db1fc52ceb ("drm/amdgpu: Add ioctl to get all gem handles for a process")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4 -2
index 63eb75a579ce..2b58bc805374 100644
@@ -1067,7 +1067,8 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
 		drm_exec_fini(&exec);
 
 		if (num_mappings > 0 && num_mappings <= args->num_entries)
-			r = copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries));
+			if (copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries)))
+				r = -EFAULT;
 
 		args->num_entries = num_mappings;
 
@@ -1159,7 +1160,8 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
 	args->num_entries = bo_index;
 
 	if (!ret)
-		ret = copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries));
+		if (copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries)))
+			ret = -EFAULT;
 
 	kvfree(bo_entries);
 
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Whoops. Yep, story checks out.

This is

________________________________
From: Dan Carpenter <[email protected]>
Sent: Thursday, September 4, 2025 2:58 PM
To: Francis, David <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; Arvind Yadav <[email protected]>; Sharma, Shashank <[email protected]>; Thomas Zimmermann <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails

The copy_to_user() function returns the number of bytes that it wasn't able to copy, but we should return -EFAULT to the user.

Fixes 4d82724f7f2b ("drm/amdgpu: Add mapping info option for GEM_OP ioctl")
Fixes f9db1fc52ceb ("drm/amdgpu: Add ioctl to get all gem handles for a process")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4 -2
index 63eb75a579ce..2b58bc805374 100644
@@ -1067,7 +1067,8 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
                 drm_exec_fini(&exec);
 
                 if (num_mappings > 0 && num_mappings <= args->num_entries)
-                       r = copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries));
+                       if (copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries)))
+                               r = -EFAULT;
 
                 args->num_entries = num_mappings;
 
@@ -1159,7 +1160,8 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
         args->num_entries = bo_index;
 
         if (!ret)
-               ret = copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries));
+               if (copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries)))
+                       ret = -EFAULT;
 
         kvfree(bo_entries);
 

--
2.47.2

Applied
#2 lore raw

Applied. Thanks!

Quoted 51 lines · David

[AMD Official Use Only - AMD Internal Distribution Only]

Whoops. Yep, story checks out.

This is

________________________________
From: Dan Carpenter <[email protected]>
Sent: Thursday, September 4, 2025 2:58 PM
To: Francis, David <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; Arvind Yadav <[email protected]>; Sharma, Shashank <[email protected]>; Thomas Zimmermann <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails

The copy_to_user() function returns the number of bytes that it wasn't able to copy, but we should return -EFAULT to the user.

Fixes 4d82724f7f2b ("drm/amdgpu: Add mapping info option for GEM_OP ioctl")
Fixes f9db1fc52ceb ("drm/amdgpu: Add ioctl to get all gem handles for a process")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4 -3
index 63eb75a579ce..2b58bc805374 100644
@@ -1067,7 +1067,8 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
                 drm_exec_fini(&exec);
 
                 if (num_mappings > 0 && num_mappings <= args->num_entries)
-                       r = copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries));
+                       if (copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries)))
+                               r = -EFAULT;
 
                 args->num_entries = num_mappings;
 
@@ -1159,7 +1160,8 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
         args->num_entries = bo_index;
 
         if (!ret)
-               ret = copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries));
+               if (copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries)))
+                       ret = -EFAULT;
 
         kvfree(bo_entries);
 
--

2.47.2