drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
Subsystems (2)
PATCH v2 1/1 drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
Using a helper shrinks the code and separating the user and kernel slabs is more secure.
---
v2:
* Remove now unused dev local.
--- drivers/gpu/drm/drm_gem.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/drm_gem.c +3 -10
@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,int drm_gem_objects_lookup (struct drm_file *filp,void __user *bo_handles,int count,struct drm_gem_object ***objs_out) { -struct drm_device *dev = filp->minor->dev;struct drm_gem_object **objs;u32 *handles;int ret;
@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, *objs_out = objs; - handles =kvmalloc_array (count,sizeof (u32),GFP_KERNEL ); -if (!handles) { - ret = -ENOMEM ; - goto out; - } - -if (copy_from_user (handles, bo_handles, count *sizeof (u32))) { - ret = -EFAULT ; -drm_dbg_core (dev,"Failed to copy in GEM handles\n" ); + handles =vmemdup_array_user (bo_handles, count,sizeof (u32)); +if (IS_ERR (handles)) { + ret =PTR_ERR (handles); goto out; }
Signature · 1 line
2.51.1
Hi Tvrtko,
Em 12/11/2025 06:27, Tvrtko Ursulin escreveu:
Quoted 2 lines
Using a helper shrinks the code and separating the user and kernel slabs is more secure.
As in the commit message, the commit description should be writing in the imperative mood.
Quoted 24 lines
Signed-off-by Tvrtko Ursulin <[email protected]>---
v2:
* Remove now unused dev local.--- drivers/gpu/drm/drm_gem.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_gem.c +0
-1@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,int drm_gem_objects_lookup (struct drm_file *filp,void __user *bo_handles,int count,struct drm_gem_object ***objs_out) { -struct drm_device *dev = filp->minor->dev;struct drm_gem_object **objs;u32 *handles;int ret;@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, *objs_out = objs;
drivers/gpu/drm/drm_gem.c int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, · line 809
Quoted 10 lines
drivers/gpu/drm/drm_gem.c +0
-9- handles =kvmalloc_array (count,sizeof (u32),GFP_KERNEL ); -if (!handles) { - ret = -ENOMEM ; - goto out; - } - -if (copy_from_user (handles, bo_handles, count *sizeof (u32))) { - ret = -EFAULT ; -drm_dbg_core (dev,"Failed to copy in GEM handles\n" );
Why the debugged message has been removed?
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +3
-0+ handles =vmemdup_array_user (bo_handles, count,sizeof (u32)); +if (IS_ERR (handles)) { + ret =PTR_ERR (handles); goto out; }
Quoted 7 lines · André Almeida
Hi Tvrtko,
Em 12/11/2025 06:27, Tvrtko Ursulin escreveu:
Quoted 2 lines
Using a helper shrinks the code and separating the user and kernel slabs is more secure.
As in the commit message, the commit description should be writing in the imperative mood.
"Use a helper to shrink the code and separate the user and kernel slabs for better security."
This sounds good?
Quoted 28 lines
Quoted 28 lines
Signed-off-by Tvrtko Ursulin <[email protected]>---
v2:
* Remove now unused dev local.
---
drivers/gpu/drm/drm_gem.c| 13 +++----------1 file changed, 3 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_gem.c +0
-1@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count, int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, int count, struct drm_gem_object ***objs_out) { - struct drm_device *dev = filp->minor->dev; struct drm_gem_object **objs; u32 *handles;int ret;
drivers/gpu/drm/drm_gem.c +0
-3@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp,void __user *bo_handles, *objs_out = objs; - handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL); - if (!handles) { - ret = -ENOMEM;
Quoted 8 lines
drivers/gpu/drm/drm_gem.c int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, · line 809
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +0
-6- goto out; - } - - if (copy_from_user(handles, bo_handles, count * sizeof(u32))) { - ret = -EFAULT; - drm_dbg_core(dev, "Failed to copy in GEM handles\n");Why the debugged message has been removed?
I should indeed have mentioned in the commit message:
"While at it lets remove the useless debug message."
Regards,
Tvrtko
Quoted 6 lines
Quoted 5 lines
drivers/gpu/drm/drm_gem.c +3
-0+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32)); + if (IS_ERR(handles)) { + ret = PTR_ERR(handles); goto out; }
André Almeida
Reviewed-byEm 20/11/2025 11:53, Tvrtko Ursulin escreveu:
Quoted 14 lines · André Almeida
Quoted 7 lines
Hi Tvrtko,
Em 12/11/2025 06:27, Tvrtko Ursulin escreveu:
Quoted 2 lines
Using a helper shrinks the code and separating the user and kernel slabs is more secure.
As in the commit message, the commit description should be writing in the imperative mood.
"Use a helper to shrink the code and separate the user and kernel slabs for better security."
This sounds good?
All good to me, thanks! With both observations addressed:
Quoted 50 lines
Quoted 28 lines
Quoted 28 lines
Signed-off-by Tvrtko Ursulin <[email protected]>---
v2:
* Remove now unused dev local.
---
drivers/gpu/drm/drm_gem.c| 13 +++----------1 file changed, 3 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_gem.c +0
-1@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count, int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, int count, struct drm_gem_object ***objs_out) { - struct drm_device *dev = filp->minor->dev; struct drm_gem_object **objs; u32 *handles;int ret;
drivers/gpu/drm/drm_gem.c +0
-3@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void__user *bo_handles, *objs_out = objs; - handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL); - if (!handles) { - ret = -ENOMEM;Quoted 8 lines
drivers/gpu/drm/drm_gem.c int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, · line 809
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +0
-6- goto out; - } - - if (copy_from_user(handles, bo_handles, count * sizeof(u32))) { - ret = -EFAULT; - drm_dbg_core(dev, "Failed to copy in GEM handles\n");Why the debugged message has been removed?
I should indeed have mentioned in the commit message:
"While at it lets remove the useless debug message."
Regards,
Tvrtko
Quoted 6 lines
Quoted 5 lines
drivers/gpu/drm/drm_gem.c +3
-0+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32)); + if (IS_ERR(handles)) { + ret = PTR_ERR(handles); goto out; }
Quoted 11 lines · André Almeida
Em 20/11/2025 11:53, Tvrtko Ursulin escreveu:
Quoted 10 lines · André Almeida
Quoted 7 lines
Hi Tvrtko,
Em 12/11/2025 06:27, Tvrtko Ursulin escreveu:
Quoted 2 lines
Using a helper shrinks the code and separating the user and kernel slabs is more secure.
As in the commit message, the commit description should be writing in the imperative mood.
Quoted 8 lines
Quoted 4 lines
"Use a helper to shrink the code and separate the user and kernel slabs for better security."
This sounds good?
All good to me, thanks! With both observations addressed:
Reviewed-by André Almeida <[email protected]>
Thank you, pushed to drm-misc-next!
Regards,
Tvrtko
Quoted 52 lines
Quoted 51 lines
Quoted 29 lines
Quoted 29 lines
Signed-off-by Tvrtko Ursulin <[email protected]>---
v2:
* Remove now unused dev local.
---
drivers/gpu/drm/drm_gem.c| 13 +++----------1 file changed, 3 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_gem.c +0
-1@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count, int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, int count, struct drm_gem_object ***objs_out) { - struct drm_device *dev = filp->minor->dev; struct drm_gem_object **objs; u32 *handles;int ret;
drivers/gpu/drm/drm_gem.c +0
-3@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void__user *bo_handles, *objs_out = objs; - handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL); - if (!handles) { - ret = -ENOMEM;Quoted 8 lines
drivers/gpu/drm/drm_gem.c int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, · line 809
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +0
-6- goto out; - } - - if (copy_from_user(handles, bo_handles, count * sizeof(u32))) { - ret = -EFAULT; - drm_dbg_core(dev, "Failed to copy in GEM handles\n");Why the debugged message has been removed?
I should indeed have mentioned in the commit message:
"While at it lets remove the useless debug message."
Regards,
Tvrtko
Quoted 6 lines
Quoted 5 lines
drivers/gpu/drm/drm_gem.c +3
-0+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32)); + if (IS_ERR(handles)) { + ret = PTR_ERR(handles); goto out; }