Skip to contentSkip to conversation

drm/amdgpu: fix memory leak

PATCH NAK Nirmoy Das 3 participants 7 messages Oct 4, 2019

Subsystems (2)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix memory leak

In amdgpu_bo_list_ioctl when idr_alloc fails
don't return without freeing bo list entry.

Fixes 964d0fbf6301d ("drm/amdgpu: Allow to create BO lists in CS ioctl v3")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
index 7bcf86c61999..c3e5ea544857 100644
@@ -284,7 +284,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
 		mutex_unlock(&fpriv->bo_list_lock);
 		if (r < 0) {
 			amdgpu_bo_list_put(list);
-			return r;
+			goto error_free;
 		}
 
 		handle = r;
Signature · 1 line
2.23.0
maintainer NAK
#1 lore raw

First of all please send mails regarding amdgpu to the amd-gfx mailing list and not lkml/dri-devel.

Am 04.10.19 um 12:17 schrieb Nirmoy Das:

Quoted 15 lines

In amdgpu_bo_list_ioctl when idr_alloc fails
don't return without freeing bo list entry.

Fixes 964d0fbf6301d ("drm/amdgpu: Allow to create BO lists in CS ioctl v3")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -0
index 7bcf86c61999..c3e5ea544857 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, · line 287

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
@@ -284,7 +284,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
  		mutex_unlock(&fpriv->bo_list_lock);
  		if (r < 0) {
  			amdgpu_bo_list_put(list);
-			return r;
+			goto error_free;

NAK, that is a double free. The bo list entries are freed by amdgpu_bo_list_put().

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, · line 290

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -0
  		}
 
  		handle = r;

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 2 lines · Christian

First of all please send mails regarding amdgpu to the amd-gfx mailing list and not lkml/dri-devel.

Okay.

Quoted 11 lines

Am 04.10.19 um 12:17 schrieb Nirmoy Das:

Quoted 10 lines

In amdgpu_bo_list_ioctl when idr_alloc fails
don't return without freeing bo list entry.

Fixes 964d0fbf6301d ("drm/amdgpu: Allow to create BO lists in CS ioctl v3")
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, · line 287

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
index 7bcf86c61999..c3e5ea544857 100644
@@ -284,7 +284,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
   		mutex_unlock(&fpriv->bo_list_lock);
   		if (r < 0) {
   			amdgpu_bo_list_put(list);
-			return r;
+			goto error_free;

NAK, that is a double free. The bo list entries are freed by amdgpu_bo_list_put().

Thanks, didn't realize that.

Quoted 2 lines

Regards,
Christian.

Regards,

Nirmoy

Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -0
   		}
 
   		handle = r;
#3 lore raw

Am 04.10.19 um 13:00 schrieb Das, Nirmoy:

Quoted 27 lines · Christian
Quoted 2 lines

First of all please send mails regarding amdgpu to the amd-gfx mailing list and not lkml/dri-devel.

Okay.

Quoted 11 lines

Am 04.10.19 um 12:17 schrieb Nirmoy Das:

Quoted 10 lines

In amdgpu_bo_list_ioctl when idr_alloc fails
don't return without freeing bo list entry.

Fixes 964d0fbf6301d ("drm/amdgpu: Allow to create BO lists in CS ioctl v3")
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, · line 287

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1 -1
index 7bcf86c61999..c3e5ea544857 100644
@@ -284,7 +284,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
    		mutex_unlock(&fpriv->bo_list_lock);
    		if (r < 0) {
    			amdgpu_bo_list_put(list);
-			return r;
+			goto error_free;

NAK, that is a double free. The bo list entries are freed by amdgpu_bo_list_put().

Quoted 1 line

Thanks, didn't realize that.

Wait a second, what entries are you talking about?

The entries in the list object are freed when amdgpu_bo_list_put() is called, but the temporary info array with the handles needs to be freed as well.

And it looks like that is indeed leaked here.

Regards,
Christian.

Quoted 9 lines
Quoted 2 lines

Regards,
Christian.

Regards,

Nirmoy

Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -0
    		}
 
    		handle = r;

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 11 lines · Christian
Quoted 4 lines
Quoted 3 lines

NAK, that is a double free. The bo list entries are freed by amdgpu_bo_list_put().

Thanks, didn't realize that.

Wait a second, what entries are you talking about?

The entries in the list object are freed when amdgpu_bo_list_put() is called, but the temporary info array with the handles needs to be freed as well.

And it looks like that is indeed leaked here.

I am talking about the info array created by
amdgpu_bo_create_list_entry_array().

Quoted 12 lines

Regards,
Christian.

Quoted 9 lines
Quoted 2 lines

Regards,
Christian.

Regards,

Nirmoy

Quoted 3 lines
Quoted 3 lines
     		}
     
     		handle = r;

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Am 04.10.19 um 13:26 schrieb Das, Nirmoy:

Quoted 6 lines · Christian
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

NAK, that is a double free. The bo list entries are freed by amdgpu_bo_list_put().

Thanks, didn't realize that.

Wait a second, what entries are you talking about?

Quoted 7 lines
Quoted 5 lines

The entries in the list object are freed when amdgpu_bo_list_put() is called, but the temporary info array with the handles needs to be freed as well.

And it looks like that is indeed leaked here.

I am talking about the info array created by
amdgpu_bo_create_list_entry_array().

Yeah, that are the handles and not the entries. Sorry that I was confused about that.

Your patch is correct, you should just update the commit message a bit.

BTW: Could you cleanup error handling here a bit more?

E.g. add an error_put_list handle and drop the "if (info)" and instead return directly if we fail to allocate info.

Thanks,
Christian.

Quoted 12 lines
Quoted 12 lines

Regards,
Christian.

Quoted 9 lines
Quoted 2 lines

Regards,
Christian.

Regards,

Nirmoy

Quoted 3 lines
Quoted 3 lines
      		}
      
      		handle = r;
#6 lore raw
Quoted 17 lines · Christian

Am 04.10.19 um 13:26 schrieb Das, Nirmoy:

Quoted 6 lines · Christian
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

NAK, that is a double free. The bo list entries are freed by amdgpu_bo_list_put().

Thanks, didn't realize that.

Wait a second, what entries are you talking about?

Quoted 7 lines
Quoted 5 lines

The entries in the list object are freed when amdgpu_bo_list_put() is called, but the temporary info array with the handles needs to be freed as well.

And it looks like that is indeed leaked here.

I am talking about the info array created by
amdgpu_bo_create_list_entry_array().

Yeah, that are the handles and not the entries. Sorry that I was confused about that.

Quoted 6 lines

Your patch is correct, you should just update the commit message a bit.

BTW: Could you cleanup error handling here a bit more?

E.g. add an error_put_list handle and drop the "if (info)" and instead return directly if we fail to allocate info.

Okay I will do that in v2 of this patch.

Quoted 2 lines

Thanks,
Christian.

Regards,

Nirmoy

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel