Skip to contentSkip to conversation

drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_signal_ioctl

PATCH Superseded Sunil Khatri 4 participants 14 messages Feb 24

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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.

Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")
---
 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
index 18e77b61b201..e53e14e3bf2d 100644
@@ -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
#1 lore raw

PATCH v4 2/4 drm/amdgpu/userq: initialize gobj_read/write in amdgpu_userq_wait_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.

Fixes 42e01090a47c ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_wait_ioctl")
---
 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
index e53e14e3bf2d..42b548c8a86e 100644
@@ -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
#2 lore raw

PATCH v4 3/4 drm/amdgpu: add upper bound check on user inputs in signal ioctl

In reply to Sunil Khatri

Huge 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
index 42b548c8a86e..4f9386677c47 100644
@@ -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
maintainer Reviewed-by on v4 3/4
#3 lore raw

Re: [PATCH v4 3/4] drm/amdgpu: add upper bound check on user inputs in signal ioctl

Quoted 8 lines · Sunil Khatri

Huge 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.

In the long term we should probably move those checks into the DRM helpers for those objects. But for now:

Quoted 29 lines
---
 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
index 42b548c8a86e..4f9386677c47 100644
@@ -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));
#4 lore raw

PATCH v4 4/4 drm/amdgpu: add upper bound check on user inputs in wait ioctl

In reply to Sunil Khatri

Huge 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 | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +7 -0
index 4f9386677c47..c2435ddfbd49 100644
@@ -636,6 +636,13 @@ 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->syncobj_timeline_points > 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
maintainer
#5 lore raw

Re: [PATCH v4 4/4] drm/amdgpu: add upper bound check on user inputs in wait ioctl

Quoted 17 lines · Sunil Khatri

Huge 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 | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +0 -0
index 4f9386677c47..c2435ddfbd49 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, · line 642

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3 -0
@@ -636,6 +636,13 @@ 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->syncobj_timeline_points > AMDGPU_USERQ_MAX_HANDLES ||

That here is wrong, syncobj_timeline_points is a 64bit VA pointer.

The number of timeline points is always the same as the number of timeline syncobj handles.

Regards,
Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +4 -0
+	    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));

#6 lore raw

Re: [PATCH v4 4/4] drm/amdgpu: add upper bound check on user inputs in wait ioctl

Quoted 22 lines · Christian König
Quoted 20 lines · Sunil Khatri

Huge 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 | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +0 -0
index 4f9386677c47..c2435ddfbd49 100644
@@ -636,6 +636,13 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
  	if (!amdgpu_userq_enabled(dev))
  		return -ENOTSUPP;
 
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, · line 641

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3 -0
+	if (wait_info->num_syncobj_handles > AMDGPU_USERQ_MAX_HANDLES ||
+	    wait_info->num_syncobj_timeline_handles > AMDGPU_USERQ_MAX_HANDLES ||
+	    wait_info->syncobj_timeline_points > AMDGPU_USERQ_MAX_HANDLES ||

That here is wrong, syncobj_timeline_points is a 64bit VA pointer.

Right, but do we want to set the value to be much bigger value for this ?

Quoted 2 lines

The number of timeline points is always the same as the number of timeline syncobj handles.

So should i check only for num_syncobj_timeline_handles, or its ok to check for both ?

Regards Sunil khatri

Quoted 11 lines

Regards,
Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +4 -0
+	    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));
maintainer
#7 lore raw

Re: [PATCH v4 4/4] drm/amdgpu: add upper bound check on user inputs in wait ioctl

Quoted 23 lines · Sunil
Quoted 21 lines · Christian König
Quoted 20 lines · Sunil Khatri

Huge 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 | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +0 -0
index 4f9386677c47..c2435ddfbd49 100644
@@ -636,6 +636,13 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
 	if (!amdgpu_userq_enabled(dev))
 		return -ENOTSUPP;
 
Quoted 5 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, · line 641

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3 -0
+	if (wait_info->num_syncobj_handles > AMDGPU_USERQ_MAX_HANDLES ||
+	    wait_info->num_syncobj_timeline_handles > AMDGPU_USERQ_MAX_HANDLES ||
+	    wait_info->syncobj_timeline_points > AMDGPU_USERQ_MAX_HANDLES ||

That here is wrong, syncobj_timeline_points is a 64bit VA pointer.

Right, but do we want to set the value to be much bigger value for this ?

No, this is not a number but only a VA.

Quoted 3 lines
Quoted 1 line

The number of timeline points is always the same as the number of timeline syncobj handles.

So should i check only for num_syncobj_timeline_handles, or its ok to check for both ?

Checking only num_syncobj_timeline_handles is sufficient, syncobj_timeline_points should not be checked.

Regards,
Christian.

Quoted 13 lines

Regards Sunil khatri

Quoted 10 lines

Regards,
Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +4 -0
+	    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));
#8 lore raw

Re: [PATCH v4 4/4] drm/amdgpu: add upper bound check on user inputs in wait ioctl

Quoted 23 lines · Christian König
Quoted 22 lines · Sunil
Quoted 21 lines · Christian König
Quoted 20 lines · Sunil Khatri

Huge 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 | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +0 -0
index 4f9386677c47..c2435ddfbd49 100644
@@ -636,6 +636,13 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
  	if (!amdgpu_userq_enabled(dev))
  		return -ENOTSUPP;
 
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data, · line 641

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3 -0
+	if (wait_info->num_syncobj_handles > AMDGPU_USERQ_MAX_HANDLES ||
+	    wait_info->num_syncobj_timeline_handles > AMDGPU_USERQ_MAX_HANDLES ||
+	    wait_info->syncobj_timeline_points > AMDGPU_USERQ_MAX_HANDLES ||

That here is wrong, syncobj_timeline_points is a 64bit VA pointer.

Right, but do we want to set the value to be much bigger value for this ?

No, this is not a number but only a VA.

Ah, yes i see now thats not the count. Sorry will remove that in next version.

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

The number of timeline points is always the same as the number of timeline syncobj handles.

So should i check only for num_syncobj_timeline_handles, or its ok to check for both ?

Checking only num_syncobj_timeline_handles is sufficient, syncobj_timeline_points should not be checked.

Got it, will get that removed.

Regards
Sunil Khatri

Quoted 16 lines

Regards,
Christian.

Quoted 12 lines

Regards Sunil khatri

Quoted 10 lines

Regards,
Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +4 -0
+	    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));
#9 lore raw
In reply to Sunil Khatri
Quoted 3 lines · Sunil Khatri

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.

Hmm I thought this cannot be after dbce431756f8 ("drm/gem: Make drm_gem_objects_lookup() self-cleaning on failure v6"):

int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)

{
	struct drm_gem_object **objs;
	u32 *handles;
	int ret;

	*objs_out = NULL;

	if (!count)
		return 0;

So if count is zero, pointer is initialized to zero.

Maybe the branch you tested with does not have that patch?

But in any case, no harm in zero initializing so you can mark my r-b for both.

Regards,

Tvrtko

Quoted 20 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")
---
  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
index 18e77b61b201..e53e14e3bf2d 100644
@@ -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;
maintainer
#10 lore raw
In reply to Sunil Khatri
Quoted 3 lines · Sunil Khatri

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.

Mhm, that doesn't sounds correct to me.

When count is zero drm_gem_objects_lookup() sets the resulting pointer to NULL:

int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)

{
        struct drm_gem_object **objs;
        u32 *handles;
        int ret;

        *objs_out = NULL;

        if (!count)
                return 0;

But could be that this was only added by Srinis patch and previously we didn't do that correctly.

Regards,
Christian.

Quoted 20 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")
---
 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
index 18e77b61b201..e53e14e3bf2d 100644
@@ -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;
#11 lore raw
Quoted 21 lines · Christian König
Quoted 3 lines · Sunil Khatri

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.

Mhm, that doesn't sounds correct to me.

When count is zero drm_gem_objects_lookup() sets the resulting pointer to NULL:

int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)

{
         struct drm_gem_object **objs;
         u32 *handles;
         int ret;

         *objs_out = NULL;

         if (!count)
                 return 0;
Quoted 1 line

But could be that this was only added by Srinis patch and previously we didn't do that correctly.

For now i see the crash due to random ptr access. ASDN does not have the above code and we need to fix it for now.

Regards
Sunil Khatri

Quoted 23 lines

Regards,
Christian.

Quoted 19 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")
---
  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
index 18e77b61b201..e53e14e3bf2d 100644
@@ -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;
maintainer
#12 lore raw
Quoted 19 lines · Sunil
Quoted 17 lines · Christian König
Quoted 3 lines · Sunil Khatri

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.

Mhm, that doesn't sounds correct to me.

When count is zero drm_gem_objects_lookup() sets the resulting pointer to NULL:

int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, int count, struct drm_gem_object ***objs_out) {
         struct drm_gem_object **objs;
         u32 *handles;
         int ret;

         *objs_out = NULL;

Quoted 7 lines
Quoted 5 lines

         if (!count)
                 return 0;

But could be that this was only added by Srinis patch and previously we didn't do that correctly.

For now i see the crash due to random ptr access. ASDN does not have the above code and we need to fix it for now.

Please ping Alex if cherry picking this one patch back into ASDN is ok.

Regards,
Christian.

Quoted 27 lines

Regards
Sunil Khatri

Quoted 23 lines

Regards,
Christian.

Quoted 19 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")

---
  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
index 18e77b61b201..e53e14e3bf2d 100644
@@ -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;
#13 lore raw
Quoted 19 lines · Christian König
Quoted 18 lines · Sunil
Quoted 17 lines · Christian König
Quoted 3 lines · Sunil Khatri

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.

Mhm, that doesn't sounds correct to me.

When count is zero drm_gem_objects_lookup() sets the resulting pointer to NULL:

int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
                            int count, struct drm_gem_object ***objs_out)
{
         struct drm_gem_object **objs;
         u32 *handles;
         int ret;

         *objs_out = NULL;

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

         if (!count)
                 return 0;

But could be that this was only added by Srinis patch and previously we didn't do that correctly.

For now i see the crash due to random ptr access. ASDN does not have the above code and we need to fix it for now.

Please ping Alex if cherry picking this one patch back into ASDN is ok.

Alex, can we cherry-pick one the change from drm-next for drm_gem_objects_lookup, but anyways even if we have an explicit setting to NULL it should be okish ? Atleast for now we can pull in to avoid any crashes right now and later revert the change of setting to NULL once we have drm_gem_objects_lookup fix added in ASDN.. Regards Sunil Khatri

Quoted 29 lines

Regards,
Christian.

Quoted 25 lines

Regards
Sunil Khatri

Quoted 22 lines

Regards,
Christian.

Quoted 19 lines
Fixes 3cf117572294 ("drm/amdgpu/userq: Use drm_gem_objects_lookup in amdgpu_userq_signal_ioctl")
---
   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
index 18e77b61b201..e53e14e3bf2d 100644
@@ -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;