* [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails
@ 2025-09-04 18:58 Dan Carpenter
2025-09-05 12:52 ` Francis, David
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-09-04 18:58 UTC (permalink / raw)
To: David Francis
Cc: Alex Deucher, Christian König, David Airlie, Simona Vetter,
Arvind Yadav, Shashank Sharma, Thomas Zimmermann, amd-gfx,
dri-devel, linux-kernel, kernel-janitors
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")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 63eb75a579ce..2b58bc805374 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails 2025-09-04 18:58 [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails Dan Carpenter @ 2025-09-05 12:52 ` Francis, David 2025-09-05 14:01 ` Alex Deucher 0 siblings, 1 reply; 3+ messages in thread From: Francis, David @ 2025-09-05 12:52 UTC (permalink / raw) To: Dan Carpenter Cc: Deucher, Alexander, Koenig, Christian, David Airlie, Simona Vetter, Arvind Yadav, Sharma, Shashank, Thomas Zimmermann, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org [-- Attachment #1: Type: text/plain, Size: 2648 bytes --] [AMD Official Use Only - AMD Internal Distribution Only] Whoops. Yep, story checks out. This is Reviewed-By: David Francis <David.Francis@amd.com> ________________________________ From: Dan Carpenter <dan.carpenter@linaro.org> Sent: Thursday, September 4, 2025 2:58 PM To: Francis, David <David.Francis@amd.com> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; David Airlie <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Arvind Yadav <Arvind.Yadav@amd.com>; Sharma, Shashank <Shashank.Sharma@amd.com>; Thomas Zimmermann <tzimmermann@suse.de>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org <kernel-janitors@vger.kernel.org> 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") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 63eb75a579ce..2b58bc805374 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -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 [-- Attachment #2: Type: text/html, Size: 5428 bytes --] ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails 2025-09-05 12:52 ` Francis, David @ 2025-09-05 14:01 ` Alex Deucher 0 siblings, 0 replies; 3+ messages in thread From: Alex Deucher @ 2025-09-05 14:01 UTC (permalink / raw) To: Francis, David Cc: Dan Carpenter, Deucher, Alexander, Koenig, Christian, David Airlie, Simona Vetter, Arvind Yadav, Sharma, Shashank, Thomas Zimmermann, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Applied. Thanks! On Fri, Sep 5, 2025 at 8:59 AM Francis, David <David.Francis@amd.com> wrote: > > [AMD Official Use Only - AMD Internal Distribution Only] > > Whoops. Yep, story checks out. > > This is > Reviewed-By: David Francis <David.Francis@amd.com> > ________________________________ > From: Dan Carpenter <dan.carpenter@linaro.org> > Sent: Thursday, September 4, 2025 2:58 PM > To: Francis, David <David.Francis@amd.com> > Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; David Airlie <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Arvind Yadav <Arvind.Yadav@amd.com>; Sharma, Shashank <Shashank.Sharma@amd.com>; Thomas Zimmermann <tzimmermann@suse.de>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org <kernel-janitors@vger.kernel.org> > 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") > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > index 63eb75a579ce..2b58bc805374 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > @@ -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 > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-05 14:02 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-04 18:58 [PATCH next] drm/amdgpu: Fix error codes if copy_to_user() fails Dan Carpenter 2025-09-05 12:52 ` Francis, David 2025-09-05 14:01 ` Alex Deucher
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.