drm/amdgpu: update memdup_user with memdup_array_user
Subsystems (2)
PATCH 1/2 drm/amdgpu: update memdup_user with memdup_array_user
memdup_user could return invalid memory allocation if there is an integer overflow. Using memdup_array_user make sure we validate the size requirements upfront and return with an error.
--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +16 -16
@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles =memdup_user (u64_to_user_ptr (args->syncobj_handles), -size_mul (sizeof (u32), num_syncobj_handles)); + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), + num_syncobj_handles,sizeof (u32));if (IS_ERR (syncobj_handles))return PTR_ERR (syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_read_bo_handles = args->num_bo_read_handles; - bo_handles_read =memdup_user (u64_to_user_ptr (args->bo_read_handles), -sizeof (u32) * num_read_bo_handles); + bo_handles_read =memdup_array_user (u64_to_user_ptr (args->bo_read_handles), + num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read)) { r =PTR_ERR (bo_handles_read); goto free_syncobj;
@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write =memdup_user (u64_to_user_ptr (args->bo_write_handles), -sizeof (u32) * num_write_bo_handles); + bo_handles_write =memdup_array_user (u64_to_user_ptr (args->bo_write_handles), + num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) { r =PTR_ERR (bo_handles_write); goto put_gobj_read;
@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read =memdup_user (u64_to_user_ptr (wait_info->bo_read_handles), -size_mul (sizeof (u32), num_read_bo_handles)); + bo_handles_read =memdup_array_user (u64_to_user_ptr (wait_info->bo_read_handles), + num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read))return PTR_ERR (bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write =memdup_user (u64_to_user_ptr (wait_info->bo_write_handles), -size_mul (sizeof (u32), num_write_bo_handles)); + bo_handles_write =memdup_array_user (u64_to_user_ptr (wait_info->bo_write_handles), + num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) { r =PTR_ERR (bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles =memdup_user (u64_to_user_ptr (wait_info->syncobj_handles), -size_mul (sizeof (u32), num_syncobj)); + syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), + num_syncobj,sizeof (u32));if (IS_ERR (syncobj_handles)) { r =PTR_ERR (syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles =memdup_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), -sizeof (u32) * num_points); + timeline_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), + num_points,sizeof (u32));if (IS_ERR (timeline_handles)) { r =PTR_ERR (timeline_handles); goto free_syncobj_handles; } - timeline_points =memdup_user (u64_to_user_ptr (wait_info->syncobj_timeline_points), -sizeof (u32) * num_points); + timeline_points =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_points), + num_points,sizeof (u32));if (IS_ERR (timeline_points)) { r =PTR_ERR (timeline_points); goto free_timeline_handles;
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu: add upper bound check on user inputs in signal/wait ioctl
There are various input arguments set by user in the signal/wait ioctl which could be a huge value eventually leading to a OOM condition and system crash and could be exploited.
So check these input value against AMDGPU_USERQ_MAX_HANDLES which is big enough value and also to avoid out of memory condition.
--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +37 -0
@@ -35,6 +35,8 @@static const struct dma_fence_ops amdgpu_userq_fence_ops;static struct kmem_cache *amdgpu_userq_fence_slab; +#define AMDGPU_USERQ_MAX_HANDLES (1U << 16) +int amdgpu_userq_fence_slab_init (void ) { amdgpu_userq_fence_slab = kmem_cache_create("amdgpu_userq_fence",
@@ -480,6 +482,9 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_syncobj_handles = args->num_syncobj_handles; +if (num_syncobj_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), num_syncobj_handles,sizeof (u32));if (IS_ERR (syncobj_handles))
@@ -501,6 +506,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_read_bo_handles = args->num_bo_read_handles; +if (num_read_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_syncobj; + } + bo_handles_read =memdup_array_user (u64_to_user_ptr (args->bo_read_handles), num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read)) {
@@ -524,6 +534,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; +if (num_write_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto put_gobj_read; + } + bo_handles_write =memdup_array_user (u64_to_user_ptr (args->bo_write_handles), num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) {
@@ -666,12 +681,20 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_read_bo_handles = wait_info->num_bo_read_handles; +if (num_read_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + bo_handles_read =memdup_array_user (u64_to_user_ptr (wait_info->bo_read_handles), num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read))return PTR_ERR (bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; +if (num_write_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_bo_handles_read; + } + bo_handles_write =memdup_array_user (u64_to_user_ptr (wait_info->bo_write_handles), num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) {
@@ -680,6 +703,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_syncobj = wait_info->num_syncobj_handles; +if (num_syncobj >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_bo_handles_write; + } + syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), num_syncobj,sizeof (u32));if (IS_ERR (syncobj_handles)) {
@@ -688,6 +716,10 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_points = wait_info->num_syncobj_timeline_handles; +if (num_points >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_syncobj_handles; + } timeline_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), num_points,sizeof (u32));if (IS_ERR (timeline_handles)) {
@@ -750,6 +782,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } } +if (wait_info->num_fences >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto exec_fini; + } +if (!wait_info->num_fences) {if (num_points) {struct dma_fence_unwrap iter;
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH v1 2/2] drm/amdgpu: add upper bound check on user inputs in signal/wait ioctl
Quoted 27 lines · Sunil Khatri
There are various input arguments set by user in the signal/wait ioctl which could be a huge value eventually leading to a OOM condition and system crash and could be exploited.
So check these input value against
AMDGPU_USERQ_MAX_HANDLESwhich is big enough value and also to avoid out of memory condition.Signed-off-by Sunil Khatri <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-0@@ -35,6 +35,8 @@static const struct dma_fence_ops amdgpu_userq_fence_ops;static struct kmem_cache *amdgpu_userq_fence_slab; +#define AMDGPU_USERQ_MAX_HANDLES (1U << 16) +int amdgpu_userq_fence_slab_init (void ) { amdgpu_userq_fence_slab = kmem_cache_create("amdgpu_userq_fence",
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, · line 489
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3
-0@@ -480,6 +482,9 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_syncobj_handles = args->num_syncobj_handles; +if (num_syncobj_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), num_syncobj_handles,sizeof (u32));
There is actually the helper function drm_syncobj_array_find() which should handle all of that.
If it doesn't we need to improve that function.
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, · line 513
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +5
-0if (IS_ERR (syncobj_handles))@@ -501,6 +506,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_read_bo_handles = args->num_bo_read_handles; +if (num_read_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_syncobj; + } +
Same here, we already have a helper for that. I started using those helpers in my patch.
Maybe just extract that change and apply it separately.
Regards,
Christian.
Quoted 71 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +27
-0bo_handles_read =memdup_array_user (u64_to_user_ptr (args->bo_read_handles), num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read)) {@@ -524,6 +534,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; +if (num_write_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto put_gobj_read; + } + bo_handles_write =memdup_array_user (u64_to_user_ptr (args->bo_write_handles), num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) {@@ -666,12 +681,20 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_read_bo_handles = wait_info->num_bo_read_handles; +if (num_read_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + bo_handles_read =memdup_array_user (u64_to_user_ptr (wait_info->bo_read_handles), num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read))return PTR_ERR (bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; +if (num_write_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_bo_handles_read; + } + bo_handles_write =memdup_array_user (u64_to_user_ptr (wait_info->bo_write_handles), num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) {@@ -680,6 +703,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_syncobj = wait_info->num_syncobj_handles; +if (num_syncobj >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_bo_handles_write; + } + syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), num_syncobj,sizeof (u32));if (IS_ERR (syncobj_handles)) {@@ -688,6 +716,10 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_points = wait_info->num_syncobj_timeline_handles; +if (num_points >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_syncobj_handles; + } timeline_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), num_points,sizeof (u32));if (IS_ERR (timeline_handles)) {@@ -750,6 +782,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } } +if (wait_info->num_fences >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto exec_fini; + } +if (!wait_info->num_fences) {if (num_points) {struct dma_fence_unwrap iter;
Re: [PATCH v1 2/2] drm/amdgpu: add upper bound check on user inputs in signal/wait ioctl
Quoted 38 lines · Christian König
Quoted 27 lines · Sunil Khatri
There are various input arguments set by user in the signal/wait ioctl which could be a huge value eventually leading to a OOM condition and system crash and could be exploited.
So check these input value against
AMDGPU_USERQ_MAX_HANDLESwhich is big enough value and also to avoid out of memory condition.Signed-off-by Sunil Khatri <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-0@@ -35,6 +35,8 @@static const struct dma_fence_ops amdgpu_userq_fence_ops;static struct kmem_cache *amdgpu_userq_fence_slab; +#define AMDGPU_USERQ_MAX_HANDLES (1U << 16) +int amdgpu_userq_fence_slab_init (void ) { amdgpu_userq_fence_slab = kmem_cache_create("amdgpu_userq_fence",drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, · line 489
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3
-0@@ -480,6 +482,9 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_syncobj_handles = args->num_syncobj_handles; +if (num_syncobj_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), num_syncobj_handles,sizeof (u32));There is actually the helper function
drm_syncobj_array_find()which should handle all of that.
Quoted 1 line
If it doesn't we need to improve that function.
i checked the above function and i dont see them handling the maximum limit on the no of the objects in that we are doing the same thing in that function i.e based on the count we allocating memory and copying objects from user.
If we want to limit on no of objects a user can send that we need this change as per my understanding.
Regards
Sunil Khatri
Quoted 89 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, · line 513
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +5
-0if (IS_ERR (syncobj_handles))@@ -501,6 +506,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_read_bo_handles = args->num_bo_read_handles; +if (num_read_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_syncobj; + } +Same here, we already have a helper for that. I started using those helpers in my patch.
Maybe just extract that change and apply it separately.
Regards,
Christian.Quoted 71 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +27
-0bo_handles_read =memdup_array_user (u64_to_user_ptr (args->bo_read_handles), num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read)) {@@ -524,6 +534,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; +if (num_write_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto put_gobj_read; + } + bo_handles_write =memdup_array_user (u64_to_user_ptr (args->bo_write_handles), num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) {@@ -666,12 +681,20 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_read_bo_handles = wait_info->num_bo_read_handles; +if (num_read_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + bo_handles_read =memdup_array_user (u64_to_user_ptr (wait_info->bo_read_handles), num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read))return PTR_ERR (bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; +if (num_write_bo_handles >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_bo_handles_read; + } + bo_handles_write =memdup_array_user (u64_to_user_ptr (wait_info->bo_write_handles), num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) {@@ -680,6 +703,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_syncobj = wait_info->num_syncobj_handles; +if (num_syncobj >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_bo_handles_write; + } + syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), num_syncobj,sizeof (u32));if (IS_ERR (syncobj_handles)) {@@ -688,6 +716,10 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_points = wait_info->num_syncobj_timeline_handles; +if (num_points >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto free_syncobj_handles; + } timeline_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), num_points,sizeof (u32));if (IS_ERR (timeline_handles)) {@@ -750,6 +782,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } } +if (wait_info->num_fences >AMDGPU_USERQ_MAX_HANDLES ) { + r = -EINVAL ; + goto exec_fini; + } +if (!wait_info->num_fences) {if (num_points) {struct dma_fence_unwrap iter;
Re: [PATCH v1 2/2] drm/amdgpu: add upper bound check on user inputs in signal/wait ioctl
Quoted 40 lines · Sunil
Quoted 38 lines · Christian König
Quoted 27 lines · Sunil Khatri
There are various input arguments set by user in the signal/wait ioctl which could be a huge value eventually leading to a OOM condition and system crash and could be exploited.
So check these input value against
AMDGPU_USERQ_MAX_HANDLESwhich is big enough value and also to avoid out of memory condition.Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 37
+++++++++++++++++++1 file changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-0@@ -35,6 +35,8 @@ static const struct dma_fence_ops amdgpu_userq_fence_ops; static struct kmem_cache *amdgpu_userq_fence_slab; +#define AMDGPU_USERQ_MAX_HANDLES (1U << 16) + int amdgpu_userq_fence_slab_init(void) { amdgpu_userq_fence_slab = kmem_cache_create("amdgpu_userq_fence",drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_signal_ioctl(struct drm_device · line 489
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3
-0@@ -480,6 +482,9 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; + if (num_syncobj_handles > AMDGPU_USERQ_MAX_HANDLES) + return -EINVAL; + syncobj_handles = memdup_array_user(u64_to_user_ptr(args->syncobj_handles), num_syncobj_handles, sizeof(u32));There is actually the helper function
drm_syncobj_array_find()which should handle all of that.
Quoted 6 lines
Quoted 1 line
If it doesn't we need to improve that function.
i checked the above function and i dont see them handling the maximum limit on the no of the objects in that we are doing the same thing in that function i.e based on the count we allocating memory and copying objects from user.
If we want to limit on no of objects a user can send that we need this change as per my understanding.
We could use the helper function "drm_gem_objects_lookup" to organize the code better but we still want to put in the limits on the user input provided count.
Let me pull in the Tvrtko change for the helper function and apply the limits above it. Hope thats fine ?
Regards
Sunil Khatri
Quoted 92 lines
Regards
Sunil KhatriQuoted 88 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_signal_ioctl(struct drm_device · line 513
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +5
-0if (IS_ERR(syncobj_handles))@@ -501,6 +506,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_read_bo_handles = args->num_bo_read_handles; + if (num_read_bo_handles > AMDGPU_USERQ_MAX_HANDLES) { + r = -EINVAL; + goto free_syncobj; + } +Same here, we already have a helper for that. I started using those helpers in my patch.
Maybe just extract that change and apply it separately.
Regards,
Christian.Quoted 70 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +26
-0bo_handles_read = memdup_array_user(u64_to_user_ptr(args->bo_read_handles), num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {@@ -524,6 +534,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; + if (num_write_bo_handles > AMDGPU_USERQ_MAX_HANDLES) { + r = -EINVAL; + goto put_gobj_read; + } + bo_handles_write = memdup_array_user(u64_to_user_ptr(args->bo_write_handles), num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {@@ -666,12 +681,20 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; + if (num_read_bo_handles > AMDGPU_USERQ_MAX_HANDLES) + return -EINVAL; + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info->bo_read_handles), num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; + if (num_write_bo_handles > AMDGPU_USERQ_MAX_HANDLES) { + r = -EINVAL; + goto free_bo_handles_read; + } + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info->bo_write_handles), num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {@@ -680,6 +703,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_syncobj = wait_info->num_syncobj_handles; + if (num_syncobj > AMDGPU_USERQ_MAX_HANDLES) { + r = -EINVAL; + goto free_bo_handles_write; + } + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_handles), num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) {@@ -688,6 +716,10 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } num_points = wait_info->num_syncobj_timeline_handles; + if (num_points > AMDGPU_USERQ_MAX_HANDLES) { + r = -EINVAL; + goto free_syncobj_handles; + } timeline_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) {@@ -750,6 +782,11 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, } } + if (wait_info->num_fences > AMDGPU_USERQ_MAX_HANDLES) { + r = -EINVAL; + goto exec_fini; + } + if (!wait_info->num_fences) { if (num_points) {struct
dma_fence_unwrapiter;
Quoted 4 lines · Sunil Khatri
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.
FYI:
https://lore.kernel.org/amd-gfx/[email protected]/
And later:
https://lore.kernel.org/amd-gfx/[email protected]/.
Regards,
Tvrtko
Quoted 91 lines
Signed-off-by Sunil Khatri <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +16
-16@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles =memdup_user (u64_to_user_ptr (args->syncobj_handles), -size_mul (sizeof (u32), num_syncobj_handles)); + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), + num_syncobj_handles,sizeof (u32));if (IS_ERR (syncobj_handles))return PTR_ERR (syncobj_handles);@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_read_bo_handles = args->num_bo_read_handles; - bo_handles_read =memdup_user (u64_to_user_ptr (args->bo_read_handles), -sizeof (u32) * num_read_bo_handles); + bo_handles_read =memdup_array_user (u64_to_user_ptr (args->bo_read_handles), + num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read)) { r =PTR_ERR (bo_handles_read); goto free_syncobj;@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write =memdup_user (u64_to_user_ptr (args->bo_write_handles), -sizeof (u32) * num_write_bo_handles); + bo_handles_write =memdup_array_user (u64_to_user_ptr (args->bo_write_handles), + num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) { r =PTR_ERR (bo_handles_write); goto put_gobj_read;@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,return -ENOTSUPP ; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read =memdup_user (u64_to_user_ptr (wait_info->bo_read_handles), -size_mul (sizeof (u32), num_read_bo_handles)); + bo_handles_read =memdup_array_user (u64_to_user_ptr (wait_info->bo_read_handles), + num_read_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_read))return PTR_ERR (bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write =memdup_user (u64_to_user_ptr (wait_info->bo_write_handles), -size_mul (sizeof (u32), num_write_bo_handles)); + bo_handles_write =memdup_array_user (u64_to_user_ptr (wait_info->bo_write_handles), + num_write_bo_handles,sizeof (u32));if (IS_ERR (bo_handles_write)) { r =PTR_ERR (bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles =memdup_user (u64_to_user_ptr (wait_info->syncobj_handles), -size_mul (sizeof (u32), num_syncobj)); + syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), + num_syncobj,sizeof (u32));if (IS_ERR (syncobj_handles)) { r =PTR_ERR (syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles =memdup_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), -sizeof (u32) * num_points); + timeline_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_handles), + num_points,sizeof (u32));if (IS_ERR (timeline_handles)) { r =PTR_ERR (timeline_handles); goto free_syncobj_handles; } - timeline_points =memdup_user (u64_to_user_ptr (wait_info->syncobj_timeline_points), -sizeof (u32) * num_points); + timeline_points =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_timeline_points), + num_points,sizeof (u32));if (IS_ERR (timeline_points)) { r =PTR_ERR (timeline_points); goto free_timeline_handles;
Quoted 11 lines · Tvrtko Ursulin
Quoted 4 lines · Sunil Khatri
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 5 lines
And later:
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatri
Quoted 106 lines
Regards,
Tvrtko
Quoted 100 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 +++++++++----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles =memdup_user (u64_to_user_ptr (args->syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args->bo_read_handles),
- sizeof(u32) *num_read_bo_handles);
+bo_handles_read= memdup_array_user(u64_to_user_ptr(args->bo_read_handles),
+num_read_bo_handles, sizeof(u32));
if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args->bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +9
-9@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info->bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info->bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info->bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), + num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) { r = PTR_ERR(timeline_handles); goto free_syncobj_handles; } - timeline_points = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), - sizeof(u32) * num_points); + timeline_points =memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), +
num_points, sizeof(u32));
if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points);
gotofree_timeline_handles;
Christian König
maintainerQuoted 9 lines · Sunil
Quoted 7 lines · Tvrtko Ursulin
Quoted 4 lines · Sunil Khatri
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.
Quoted 4 lines
Quoted 3 lines
FYI:
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
I simply couldn't find time to review those patches and then they felt under the table.
If Tvrtko came up with the same patch earlier than us then just take that one, review it and push to amd-staging-drm-next.
Thanks,
Christian.
Quoted 100 lines
Quoted 5 lines
And later:
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 88 lines
Regards,
Tvrtko
Quoted 82 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 +++++++++----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args->syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args->syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles)) return PTR_ERR(syncobj_handles); @@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args->bo_read_handles), - sizeof(u32) *num_read_bo_handles);
+bo_handles_read= memdup_array_user(u64_to_user_ptr(args->bo_read_handles), +num_read_bo_handles, sizeof(u32));
if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +12
-11@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args->bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto put_gobj_read;@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info->bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info->bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info->bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), + num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) { r = PTR_ERR(timeline_handles); goto free_syncobj_handles; } - timeline_points = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), - sizeof(u32) * num_points); + timeline_points = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), + num_points, sizeof(u32)); if (IS_ERR(timeline_points)) { r = PTR_ERR(timeline_points); goto free_timeline_handles;
Quoted 7 lines · Christian König
Quoted 6 lines · Sunil
Quoted 5 lines · Tvrtko Ursulin
Quoted 4 lines · Sunil Khatri
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
FYI:
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
I simply couldn't find time to review those patches and then they felt under the table.
If Tvrtko came up with the same patch earlier than us then just take that one, review it and push to amd-staging-drm-next.
I have reviewed the patches for Tvrtko, change, you can review patch 2 as that is not related to this.
regards
Sunil Khatri
Quoted 99 lines
Thanks,
Christian.Quoted 95 lines
Quoted 3 lines
And later:
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 85 lines
Regards,
Tvrtko
Quoted 81 lines
Signed-off-by Sunil Khatri <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args->syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args->syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles)) return PTR_ERR(syncobj_handles); @@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args->bo_read_handles), - sizeof(u32) *num_read_bo_handles);
+bo_handles_read= memdup_array_user(u64_to_user_ptr(args->bo_read_handles), +num_read_bo_handles, sizeof(u32));
if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +12
-11@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args->bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto put_gobj_read;@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info->bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info->bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info->bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), + num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) { r = PTR_ERR(timeline_handles); goto free_syncobj_handles; } - timeline_points = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), - sizeof(u32) * num_points); + timeline_points = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), + num_points, sizeof(u32)); if (IS_ERR(timeline_points)) { r = PTR_ERR(timeline_points); goto free_timeline_handles;
Applied the changes @Tvrtko Ursulin <[email protected]>
Regards
Sunil Khatri
Quoted 134 lines · Sunil
Quoted 11 lines · Tvrtko Ursulin
Quoted 4 lines · Sunil Khatri
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 5 lines
And later:
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 107 lines
Regards,
Tvrtko
Quoted 101 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32
+++++++++----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles =memdup_user (u64_to_user_ptr (args->syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args->bo_read_handles),
- sizeof(u32) *num_read_bo_handles);
+bo_handles_read= memdup_array_user(u64_to_user_ptr(args->bo_read_handles),
+num_read_bo_handles, sizeof(u32));
if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args->bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +9
-9@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info->bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info->bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info->bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles = memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_handles), + num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) { r = PTR_ERR(timeline_handles); goto free_syncobj_handles; } - timeline_points = memdup_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), - sizeof(u32) * num_points); + timeline_points =memdup_array_user(u64_to_user_ptr(wait_info->syncobj_timeline_points), +
num_points, sizeof(u32));
if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points);
gotofree_timeline_handles;
Quoted 1 line · Sunil
Applied the changes @Tvrtko Ursulin <[email protected]>
Thank you! I am glad they still applied!
Also, you were suggesting in your last week's reply to "Please make sure the changes are made for all memdup_user". There are also patches in that series which convert to drm_gem_objects_lookup() which remove some more, but, for those I think I need to check if they need tweaking after dbce431756f8 ("drm/gem: Make drm_gem_objects_lookup() self-cleaning on failure v6"). Maybe it just works though. I will wait until the ones you merge appear in some branch and check.
Regards,
Tvrtko
Quoted 134 lines · Sunil
Quoted 133 lines · Tvrtko Ursulin
Quoted 10 lines · Sunil Khatri
Quoted 4 lines
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
https://lore.kernel.org/amd-gfx/20251205134035.91551-1- [email protected]/
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 4 lines
And later:
https://lore.kernel.org/amd-gfx/20260202125149.2067-7- [email protected]/.
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 108 lines
Regards,
Tvrtko
Quoted 102 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 ++++++++
+----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args- >syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),- sizeof(u32) *
num_read_bo_handles); +bo_handles_read= memdup_array_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),+
num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args- >bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +8
-8@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles = memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_timeline_handles), + num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) { r = PTR_ERR(timeline_handles); goto free_syncobj_handles; }-
timeline_points= memdup_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),- sizeof(u32) *
num_points);
+timeline_points= memdup_array_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),+
num_points, sizeof(u32)); if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points); gotofree_timeline_handles;
Quoted 9 lines · Tvrtko Ursulin
Quoted 1 line · Sunil
Applied the changes @Tvrtko Ursulin <[email protected]>
Thank you! I am glad they still applied!
Also, you were suggesting in your last week's reply to "Please make sure the changes are made for all
memdup_user". There are also patches in that series which convert todrm_gem_objects_lookup()which remove some more, but, for those I think I need to check if they need tweaking afterdbce431756f8("drm/gem: Makedrm_gem_objects_lookup()self-cleaning on failure v6"). Maybe it just works though. I will wait until the ones you merge appear in some branch and check.
I am in process to merge only two changes patch no 6 and 7 in the series. There were conflicts but i fixed those but still there are some more memdup_user which i will fix with a patch which are left after these 2 patches gets merged.
Also if you want to take that up its ok with me. Let me know.
Regards
Sunil Khatri
Quoted 142 lines
Regards,
Tvrtko
Quoted 136 lines · Sunil
Quoted 135 lines · Tvrtko Ursulin
Quoted 10 lines · Sunil Khatri
Quoted 4 lines
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
https://lore.kernel.org/amd-gfx/20251205134035.91551-1- [email protected]/
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 4 lines
And later:
https://lore.kernel.org/amd-gfx/20260202125149.2067-7- [email protected]/.
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 110 lines
Regards,
Tvrtko
Quoted 104 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 ++++++++
+----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args- >syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),- sizeof(u32) *
num_read_bo_handles); +bo_handles_read= memdup_array_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),+
num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args- >bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +7
-8@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles =memdup_array_user(u64_to_user_ptr(wait_info-
Quoted 1 line
syncobj_timeline_handles),+
num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) {
r =PTR_ERR(timeline_handles);
gotofree_syncobj_handles;
}
-timeline_points= memdup_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),- sizeof(u32) *
num_points); +timeline_points= memdup_array_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),+
num_points, sizeof(u32)); if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points); gotofree_timeline_handles;
Quoted 5 lines · Sunil
Quoted 3 lines · Tvrtko Ursulin
On 23/02/2026 04:31, Khatri, Sunil wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Applied the changes @Tvrtko Ursulin <[email protected]>
Thank you! I am glad they still applied!
Also, you were suggesting in your last week's reply to "Please make sure the changes are made for all
memdup_user". There are also patches in that series which convert todrm_gem_objects_lookup()which remove some more, but, for those I think I need to check if they need tweaking afterdbce431756f8("drm/gem: Makedrm_gem_objects_lookup()self-cleaning on failure v6"). Maybe it just works though. I will wait until the ones you merge appear in some branch and check.I am in process to merge only two changes patch no 6 and 7 in the series. There were conflicts but i fixed those but still there are some more
memdup_userwhich i will fix with a patch which are left after these 2 patches gets merged.
The before mentioned object lookup and syncpoint lookup. For the latter I also had cleanup back in December but did not send it:
commit ddb4985391907155a9cf5ef6f5262c1cc8f334c6
Author: Tvrtko Ursulin <[email protected]> Date: Thu Dec 4 13:56:56 2025 +0000
use syncobj lookup helper in amdgpu_userq_signal_ioctl
commit b21686063a5858833a09bb8f84cfbae2376f0c18
Author: Tvrtko Ursulin <[email protected]> Date: Thu Dec 4 13:36:15 2025 +0000
export sync obj lookup helper
Those two I was planning to send together with some more syncobj patches:
27cf1f1dabfc drm/syncobj: Add a fast path to drm_syncobj_array_find e7efbf50342b drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout 363279cd8eb4 drm/syncobj: Use vmemdup_array_user in drm_syncobj_array_find
Which are interesting for graphics since four stack fast path slots avoid 99% of temporary allocations. Not sure for user queues how many sync points are typical.
Quoted 1 line
Also if you want to take that up its ok with me. Let me know.
¯\_(ツ)_/¯
Not sure if you want to re-do it because what I sent has a flaw somewhere or something else?
Regards,
Tvrtko
Quoted 137 lines
Quoted 137 lines
Quoted 136 lines · Sunil
Quoted 135 lines · Tvrtko Ursulin
Quoted 10 lines · Sunil Khatri
Quoted 4 lines
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
https://lore.kernel.org/amd-gfx/20251205134035.91551-1- [email protected]/
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 4 lines
And later:
https://lore.kernel.org/amd-gfx/20260202125149.2067-7- [email protected]/.
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 110 lines
Regards,
Tvrtko
Quoted 104 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 ++++++++
+----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args- >syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),- sizeof(u32) *
num_read_bo_handles); +bo_handles_read= memdup_array_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),+
num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args- >bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +7
-8@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles =memdup_array_user(u64_to_user_ptr(wait_info-
Quoted 1 line
syncobj_timeline_handles),+
num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) {
r =PTR_ERR(timeline_handles);
gotofree_syncobj_handles;
}
-timeline_points= memdup_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),- sizeof(u32) *
num_points); +timeline_points= memdup_array_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),+
num_points, sizeof(u32)); if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points); gotofree_timeline_handles;
Quoted 40 lines · Tvrtko Ursulin
Quoted 5 lines · Sunil
Quoted 3 lines · Tvrtko Ursulin
On 23/02/2026 04:31, Khatri, Sunil wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Applied the changes @Tvrtko Ursulin <[email protected]>
Thank you! I am glad they still applied!
Also, you were suggesting in your last week's reply to "Please make sure the changes are made for all
memdup_user". There are also patches in that series which convert todrm_gem_objects_lookup()which remove some more, but, for those I think I need to check if they need tweaking afterdbce431756f8("drm/gem: Makedrm_gem_objects_lookup()self-cleaning on failure v6"). Maybe it just works though. I will wait until the ones you merge appear in some branch and check.I am in process to merge only two changes patch no 6 and 7 in the series. There were conflicts but i fixed those but still there are some more
memdup_userwhich i will fix with a patch which are left after these 2 patches gets merged.The before mentioned object lookup and syncpoint lookup. For the latter I also had cleanup back in December but did not send it:
commit
ddb4985391907155a9cf5ef6f5262c1cc8f334c6
Author: Tvrtko Ursulin <[email protected]> Date: Thu Dec 4 13:56:56 2025 +0000use syncobj lookup helper in
amdgpu_userq_signal_ioctlSigned-off-by Tvrtko Ursulin <[email protected]>commit
b21686063a5858833a09bb8f84cfbae2376f0c18
Author: Tvrtko Ursulin <[email protected]> Date: Thu Dec 4 13:36:15 2025 +0000export sync obj lookup helper
Signed-off-by Tvrtko Ursulin <[email protected]>Those two I was planning to send together with some more syncobj patches:
27cf1f1dabfcdrm/syncobj: Add a fast path todrm_syncobj_array_finde7efbf50342bdrm/syncobj: Add a fast path todrm_syncobj_array_wait_timeout363279cd8eb4drm/syncobj: Usevmemdup_array_userindrm_syncobj_array_find
Quoted 7 lines
Which are interesting for graphics since four stack fast path slots avoid 99% of temporary allocations. Not sure for user queues how many sync points are typical.
Quoted 1 line
Also if you want to take that up its ok with me. Let me know.
¯\_(ツ)_/¯
Not sure if you want to re-do it because what I sent has a flaw somewhere or something else?
i do not want to redo it for sure :) , could you send the patches for review if you havent yet and add me in CC. Also i am here focusing on fixing the the left over place for the same function.
Example below, these changes are still left even after your two changes that i pushed. So i am assuming the patches you mentioned have these changes accomodated this way or some other. Please send them for review.
+ bo_handles_read = memdup_array_user(u64_to_user_ptr(args->bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {
r = PTR_ERR(bo_handles_read);
goto free_syncobj;
@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, }
num_write_bo_handles = args->num_bo_write_handles;
- bo_handles_write = memdup_user(u64_to_user_ptr(args->bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args->bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {
r = PTR_ERR(bo_handles_write);
goto put_gobj_read;
@@ -666,14 +666,15 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP;
num_read_bo_handles = wait_info->num_bo_read_handles;
- bo_handles_read = memdup_user(u64_to_user_ptr(wait_info->bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info->bo_read_handles), + num_read_bo_handles, sizeof(u32)); +
if (IS_ERR(bo_handles_read))
return PTR_ERR(bo_handles_read);
num_write_bo_handles = wait_info->num_bo_write_handles;
- bo_handles_write = memdup_user(u64_to_user_ptr(wait_info->bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info->bo_write_handles), + num_write_bo_handles, sizeof(u32));
Regards
Sunil khatri
Quoted 144 lines
Regards,
Tvrtko
Quoted 138 lines
Quoted 138 lines
Quoted 137 lines · Sunil
Quoted 136 lines · Tvrtko Ursulin
Quoted 10 lines · Sunil Khatri
Quoted 4 lines
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
https://lore.kernel.org/amd-gfx/20251205134035.91551-1- [email protected]/
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 4 lines
And later:
https://lore.kernel.org/amd-gfx/20260202125149.2067-7- [email protected]/.
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 111 lines
Regards,
Tvrtko
Quoted 105 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 ++++++++
+----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args- >syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),- sizeof(u32) *
num_read_bo_handles); +bo_handles_read= memdup_array_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),+
num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args- >bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +7
-8@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles =memdup_array_user(u64_to_user_ptr(wait_info-
Quoted 1 line
syncobj_timeline_handles),+
num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) {
r =PTR_ERR(timeline_handles);
gotofree_syncobj_handles;
}
-timeline_points= memdup_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),- sizeof(u32) *
num_points); +timeline_points= memdup_array_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),+
num_points, sizeof(u32)); if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points); gotofree_timeline_handles;
Quoted 44 lines · Sunil
Quoted 42 lines · Tvrtko Ursulin
Quoted 5 lines · Sunil
Quoted 3 lines · Tvrtko Ursulin
On 23/02/2026 04:31, Khatri, Sunil wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Applied the changes @Tvrtko Ursulin <[email protected]>
Thank you! I am glad they still applied!
Also, you were suggesting in your last week's reply to "Please make sure the changes are made for all
memdup_user". There are also patches in that series which convert todrm_gem_objects_lookup()which remove some more, but, for those I think I need to check if they need tweaking afterdbce431756f8("drm/gem: Makedrm_gem_objects_lookup()self-cleaning on failure v6"). Maybe it just works though. I will wait until the ones you merge appear in some branch and check.I am in process to merge only two changes patch no 6 and 7 in the series. There were conflicts but i fixed those but still there are some more
memdup_userwhich i will fix with a patch which are left after these 2 patches gets merged.The before mentioned object lookup and syncpoint lookup. For the latter I also had cleanup back in December but did not send it:
commit
ddb4985391907155a9cf5ef6f5262c1cc8f334c6
Author: Tvrtko Ursulin <[email protected]> Date: Thu Dec 4 13:56:56 2025 +0000use syncobj lookup helper in
amdgpu_userq_signal_ioctlSigned-off-by Tvrtko Ursulin <[email protected]>commit
b21686063a5858833a09bb8f84cfbae2376f0c18
Author: Tvrtko Ursulin <[email protected]> Date: Thu Dec 4 13:36:15 2025 +0000export sync obj lookup helper
Signed-off-by Tvrtko Ursulin <[email protected]>Those two I was planning to send together with some more syncobj patches:
27cf1f1dabfcdrm/syncobj: Add a fast path todrm_syncobj_array_finde7efbf50342bdrm/syncobj: Add a fast path todrm_syncobj_array_wait_timeout363279cd8eb4drm/syncobj: Usevmemdup_array_userindrm_syncobj_array_findWhich are interesting for graphics since four stack fast path slots avoid 99% of temporary allocations. Not sure for user queues how many sync points are typical.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Also if you want to take that up its ok with me. Let me know.
¯\_(ツ)_/¯
Not sure if you want to re-do it because what I sent has a flaw somewhere or something else?
i do not want to redo it for sure :) , could you send the patches for review if you havent yet and add me in CC. Also i am here focusing on fixing the the left over place for the same function.
Example below, these changes are still left even after your two changes that i pushed. So i am assuming the patches you mentioned have these changes accomodated this way or some other. Please send them for review.
Got it, thanks! I've sent the rebased series. You can pick and choose from it but please also test the userq part since I only tested the standard submission path.
Regards,
Tvrtko
Quoted 199 lines
+ bo_handles_read = memdup_array_user(u64_to_user_ptr(args-
Quoted 1 line
bo_read_handles),+ num_read_bo_handles, sizeof(u32));
if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;(quoted diff) +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args- >bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >bo_write_handles), + num_write_bo_handles,sizeof(u32));
if (IS_ERR(bo_handles_write)) {
r =PTR_ERR(bo_handles_write);
gotoput_gobj_read;(quoted diff) +3
-4@@ -666,14 +666,15 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), + num_read_bo_handles, sizeof(u32)); + if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >bo_write_handles), - size_mul(sizeof(u32),
num_write_bo_handles));
+ bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info-Quoted 1 line
bo_write_handles),+
num_write_bo_handles, sizeof(u32));Regards
Sunil khatriQuoted 144 lines
Regards,
Tvrtko
Quoted 138 lines
Quoted 138 lines
Quoted 137 lines · Sunil
Quoted 136 lines · Tvrtko Ursulin
Quoted 10 lines · Sunil Khatri
Quoted 4 lines
memdup_usercould return invalid memory allocation if there is an integer overflow. Usingmemdup_array_usermake sure we validate the size requirements upfront and return with an error.FYI:
https://lore.kernel.org/amd-gfx/20251205134035.91551-1- [email protected]/
Are you awaiting for anything to merge the changes Tvrtko or they are merged in drm upstream already? Since issue is reported now so we need to fix this.
Quoted 4 lines
And later:
https://lore.kernel.org/amd-gfx/20260202125149.2067-7- [email protected]/.
Yeah i am aware of these Christian changes and we decided we will fix the issues first and reorganize the code later as needed along with Christian changes. So we are going to push the changes
on the existing code base first.
regards
Sunil khatriQuoted 111 lines
Regards,
Tvrtko
Quoted 105 lines
Signed-off-by Sunil Khatri <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 32 ++++++++
+----------1 file changed, 16 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -480,8 +480,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_syncobj_handles = args->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(args- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj_handles)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(args- >syncobj_handles), + num_syncobj_handles, sizeof(u32)); if (IS_ERR(syncobj_handles))return
PTR_ERR(syncobj_handles);
@@ -501,8 +501,8 @@ int amdgpu_userq_signal_ioctl(structdrm_device*dev, void *data, }
num_read_bo_handles=args->num_bo_read_handles;
-bo_handles_read= memdup_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),- sizeof(u32) *
num_read_bo_handles); +bo_handles_read= memdup_array_user(u64_to_user_ptr(args-Quoted 1 line
bo_read_handles),+
num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) {
r =PTR_ERR(bo_handles_read);
gotofree_syncobj;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-2@@ -524,8 +524,8 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, } num_write_bo_handles = args->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(args- >bo_write_handles), - sizeof(u32) * num_write_bo_handles); + bo_handles_write = memdup_array_user(u64_to_user_ptr(args- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) {r =
PTR_ERR(bo_handles_write);
gotoput_gobj_read;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +7
-8@@ -666,37 +666,37 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, return -ENOTSUPP; num_read_bo_handles = wait_info->num_bo_read_handles; - bo_handles_read = memdup_user(u64_to_user_ptr(wait_info- >bo_read_handles), - size_mul(sizeof(u32), num_read_bo_handles)); + bo_handles_read = memdup_array_user(u64_to_user_ptr(wait_info- >bo_read_handles), + num_read_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_read)) return PTR_ERR(bo_handles_read); num_write_bo_handles = wait_info->num_bo_write_handles; - bo_handles_write = memdup_user(u64_to_user_ptr(wait_info- >bo_write_handles), - size_mul(sizeof(u32), num_write_bo_handles)); + bo_handles_write = memdup_array_user(u64_to_user_ptr(wait_info- >bo_write_handles), + num_write_bo_handles, sizeof(u32)); if (IS_ERR(bo_handles_write)) { r = PTR_ERR(bo_handles_write); goto free_bo_handles_read; } num_syncobj = wait_info->num_syncobj_handles; - syncobj_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_handles), - size_mul(sizeof(u32), num_syncobj)); + syncobj_handles = memdup_array_user(u64_to_user_ptr(wait_info- >syncobj_handles), + num_syncobj, sizeof(u32)); if (IS_ERR(syncobj_handles)) { r = PTR_ERR(syncobj_handles); goto free_bo_handles_write; } num_points = wait_info->num_syncobj_timeline_handles; - timeline_handles = memdup_user(u64_to_user_ptr(wait_info- >syncobj_timeline_handles), - sizeof(u32) * num_points); + timeline_handles =memdup_array_user(u64_to_user_ptr(wait_info-
Quoted 1 line
syncobj_timeline_handles),+
num_points, sizeof(u32)); if (IS_ERR(timeline_handles)) {
r =PTR_ERR(timeline_handles);
gotofree_syncobj_handles;
}
-timeline_points= memdup_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),- sizeof(u32) *
num_points); +timeline_points= memdup_array_user(u64_to_user_ptr(wait_info-Quoted 1 line
syncobj_timeline_points),+
num_points, sizeof(u32)); if (IS_ERR(timeline_points)) {
r =PTR_ERR(timeline_points); gotofree_timeline_handles;