signal and wait ioctl fixes
Subsystems (2)
v5 cover signal and wait ioctl fixes
v5:
Only patch 4/4 is updated:
Removed the syncobj_timeline_points as its not needed and also its not not count but a VA.
Sunil Khatri (4):
drm/amdgpu/userq: initialize gobj_read/write in
amdgpu_userq_signal_ioctl
drm/amdgpu/userq: initialize gobj_read/write in
amdgpu_userq_wait_ioctl
drm/amdgpu: add upper bound check on user inputs in signal ioctl drm/amdgpu: add upper bound check on user inputs in wait ioctl
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/4 drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_signal_ioctl
In case num_read_bo_handles or num_write_bo_handles is zero the ptrs remain uninitialized and during free cause a fault. So to handle such cases we better set the gobj_read and gobj_write to NULL.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
@@ -465,7 +465,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,const unsigned int num_read_bo_handles = args->num_bo_read_handles;struct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr; -struct drm_gem_object **gobj_write, **gobj_read; +struct drm_gem_object **gobj_write =NULL , **gobj_read =NULL ;u32 *syncobj_handles, num_syncobj_handles;struct amdgpu_userq_fence *userq_fence;struct amdgpu_usermode_queue *queue;
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH v5 1/4] drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_signal_ioctl
Quoted 3 lines · Sunil Khatri
In case
num_read_bo_handlesornum_write_bo_handlesis zero the ptrs remain uninitialized and during free cause a fault. So to handle such cases we better set thegobj_readandgobj_writeto NULL.
Yeah that still doesn't looks like a good idea to me.
We intentionally avoid nationalizations like that if they aren't necessary because that allows the compiler to complain about it.
Christian.
Quoted 20 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-1@@ -465,7 +465,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,const unsigned int num_read_bo_handles = args->num_bo_read_handles;struct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr; -struct drm_gem_object **gobj_write, **gobj_read; +struct drm_gem_object **gobj_write =NULL , **gobj_read =NULL ;u32 *syncobj_handles, num_syncobj_handles;struct amdgpu_userq_fence *userq_fence;struct amdgpu_usermode_queue *queue;
Re: [PATCH v5 1/4] drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_signal_ioctl
Quoted 9 lines · Christian König
Quoted 3 lines · Sunil Khatri
In case
num_read_bo_handlesornum_write_bo_handlesis zero the ptrs remain uninitialized and during free cause a fault. So to handle such cases we better set thegobj_readandgobj_writeto NULL.Yeah that still doesn't looks like a good idea to me.
We intentionally avoid nationalizations like that if they aren't necessary because that allows the compiler to complain about it.
Christian.
Sure Christian.
@Alex, can you pull in the drm-misc-next to have the fixes in ASDN, or if it is supposed to take some time then in that case i think we need to push the change no 1 and 2 to ASDN as signal/wait IOCTL are broken right now.
Regards
Sunil Khatri
Quoted 20 lines
Quoted 20 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-1@@ -465,7 +465,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,const unsigned int num_read_bo_handles = args->num_bo_read_handles;struct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr; -struct drm_gem_object **gobj_write, **gobj_read; +struct drm_gem_object **gobj_write =NULL , **gobj_read =NULL ;u32 *syncobj_handles, num_syncobj_handles;struct amdgpu_userq_fence *userq_fence;struct amdgpu_usermode_queue *queue;
Christian König
maintainerRe: [PATCH v5 1/4] drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_signal_ioctl
Quoted 6 lines · Sunil
Quoted 4 lines · Christian König
Quoted 3 lines · Sunil Khatri
In case
num_read_bo_handlesornum_write_bo_handlesis zero the ptrs remain uninitialized and during free cause a fault. So to handle such cases we better set thegobj_readandgobj_writeto NULL.
Quoted 7 lines
Quoted 5 lines
Yeah that still doesn't looks like a good idea to me.
We intentionally avoid nationalizations like that if they aren't necessary because that allows the compiler to complain about it.
Christian.
Sure Christian.
@Alex, can you pull in the drm-misc-next to have the fixes in ASDN, or if it is supposed to take some time then in that case i think we need to push the change no 1 and 2 to ASDN as signal/wait IOCTL are broken right now.
We just need the ack from Alex to cherry pick the patch from Srini over to ASDN. Should be able to do this by tomorrow.
Regards,
Christian.
Quoted 23 lines
Regards
Sunil KhatriQuoted 20 lines
Quoted 20 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")Signed-off-by Sunil Khatri <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-1@@ -465,7 +465,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, const unsigned int num_read_bo_handles = args->num_bo_read_handles; struct amdgpu_fpriv *fpriv = filp->driver_priv; struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr; - struct drm_gem_object **gobj_write, **gobj_read; + struct drm_gem_object **gobj_write = NULL, **gobj_read = NULL; u32 *syncobj_handles, num_syncobj_handles; struct amdgpu_userq_fence *userq_fence; struct amdgpu_usermode_queue *queue;
Alex Deucher
Acked-byRe: [PATCH v5 1/4] drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_signal_ioctl
Quoted 10 lines · Christian König
Quoted 8 lines · Sunil
Quoted 6 lines · Christian König
Quoted 3 lines · Sunil Khatri
In case
num_read_bo_handlesornum_write_bo_handlesis zero the ptrs remain uninitialized and during free cause a fault. So to handle such cases we better set thegobj_readandgobj_writeto NULL.Yeah that still doesn't looks like a good idea to me.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
We intentionally avoid nationalizations like that if they aren't necessary because that allows the compiler to complain about it.
Christian.
Sure Christian.
@Alex, can you pull in the drm-misc-next to have the fixes in ASDN, or if it is supposed to take some time then in that case i think we need to push the change no 1 and 2 to ASDN as signal/wait IOCTL are broken right now.We just need the ack from Alex to cherry pick the patch from Srini over to ASDN. Should be able to do this by tomorrow.
Sure go ahead and cherry-pick what you need. That said, I think this patch is fine on its own as well:
Alex
Quoted 28 lines
Regards,
Christian.Quoted 23 lines
Regards
Sunil KhatriQuoted 20 lines
Quoted 20 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-1@@ -465,7 +465,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,const unsigned int num_read_bo_handles = args->num_bo_read_handles;struct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr; -struct drm_gem_object **gobj_write, **gobj_read; +struct drm_gem_object **gobj_write =NULL , **gobj_read =NULL ;u32 *syncobj_handles, num_syncobj_handles;struct amdgpu_userq_fence *userq_fence;struct amdgpu_usermode_queue *queue;
PATCH v5 2/4 drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_wait_ioctl
In reply to Sunil KhatriIn case num_read_bo_handles or num_write_bo_handles is zero the ptrs remain uninitialized and during free cause a fault. So to handle such cases we better set the gobj_read and gobj_write to NULL.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
@@ -617,7 +617,7 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,struct drm_amdgpu_userq_fence_info *fence_info =NULL ;struct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr; -struct drm_gem_object **gobj_write, **gobj_read; +struct drm_gem_object **gobj_write =NULL , **gobj_read =NULL ;u32 *timeline_points, *timeline_handles;struct amdgpu_usermode_queue *waitq;u32 *syncobj_handles, num_syncobj;
Signature · 1 line
2.34.1
PATCH v5 3/4 drm/amdgpu: add upper bound check on user inputs in signal ioctl
In reply to Sunil KhatriHuge input values in amdgpu_userq_signal_ioctl can lead to a OOM and could be exploited.
So check these input value against AMDGPU_USERQ_MAX_HANDLES which is big enough value for genuine use cases and could potentially avoid OOM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +7 -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",
@@ -478,6 +480,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,if (!amdgpu_userq_enabled (dev))return -ENOTSUPP ; +if (args->num_syncobj_handles >AMDGPU_USERQ_MAX_HANDLES || + args->num_bo_write_handles >AMDGPU_USERQ_MAX_HANDLES || + args->num_bo_read_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + num_syncobj_handles = args->num_syncobj_handles; syncobj_handles =memdup_array_user (u64_to_user_ptr (args->syncobj_handles), num_syncobj_handles,sizeof (u32));
Signature · 1 line
2.34.1
PATCH v5 4/4 drm/amdgpu: add upper bound check on user inputs in wait ioctl
In reply to Sunil KhatriHuge input values in amdgpu_userq_wait_ioctl can lead to a OOM and could be exploited.
So check these input value against AMDGPU_USERQ_MAX_HANDLES which is big enough value for genuine use cases and could potentially avoid OOM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +6 -0
@@ -636,6 +636,12 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,if (!amdgpu_userq_enabled (dev))return -ENOTSUPP ; +if (wait_info->num_syncobj_handles >AMDGPU_USERQ_MAX_HANDLES || + wait_info->num_syncobj_timeline_handles >AMDGPU_USERQ_MAX_HANDLES || + wait_info->num_bo_write_handles >AMDGPU_USERQ_MAX_HANDLES || + wait_info->num_bo_read_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + num_syncobj = wait_info->num_syncobj_handles; syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), num_syncobj,sizeof (u32));
Signature · 1 line
2.34.1
Re: [PATCH v5 4/4] drm/amdgpu: add upper bound check on user inputs in wait ioctl
Quoted 9 lines · Sunil Khatri
Huge input values in
amdgpu_userq_wait_ioctlcan lead to a OOM and could be exploited.So check these input value against
AMDGPU_USERQ_MAX_HANDLESwhich is big enough value for genuine use cases and could potentially avoid OOM.Signed-off-by Sunil Khatri <[email protected]>
Series is:
Quoted 24 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +6
-1@@ -636,6 +636,12 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,if (!amdgpu_userq_enabled (dev))return -ENOTSUPP ; +if (wait_info->num_syncobj_handles >AMDGPU_USERQ_MAX_HANDLES || + wait_info->num_syncobj_timeline_handles >AMDGPU_USERQ_MAX_HANDLES || + wait_info->num_bo_write_handles >AMDGPU_USERQ_MAX_HANDLES || + wait_info->num_bo_read_handles >AMDGPU_USERQ_MAX_HANDLES ) +return -EINVAL ; + num_syncobj = wait_info->num_syncobj_handles; syncobj_handles =memdup_array_user (u64_to_user_ptr (wait_info->syncobj_handles), num_syncobj,sizeof (u32)); --2.34.1