Skip to contentSkip to conversation

drm/amd: fix potential memleak in err branch

PATCH Superseded Bernard Zhao 2 participants 2 messages Jun 20, 2020 – Jun 23, 2020

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amd: fix potential memleak in err branch

The function kobject_init_and_add alloc memory like:
kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs ->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller ->kmalloc_slab, in err branch this memory not free. If use kmemleak, this path maybe catched.
These changes are to add kobject_put in kobject_init_and_add failed branch, fix potential memleak.

---
Changes since V1:
*Remove duplicate changed file kfd_topology.c, this file`s fix already applied to the main line.

---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2 -0
index d27221ddcdeb..5ee4d6cfb16d 100644
@@ -124,6 +124,7 @@ void kfd_procfs_init(void)
 	if (ret) {
 		pr_warn("Could not create procfs proc folder");
 		/* If we fail to create the procfs, clean up */
+		kobject_put(procfs.kobj);
 		kfd_procfs_shutdown();
 	}
 }
@@ -428,6 +429,7 @@ struct kfd_process *kfd_create_process(struct file *filep)
 					   (int)process->lead_thread->pid);
 		if (ret) {
 			pr_warn("Creating procfs pid directory failed");
+			kobject_put(process->kobj);
 			goto out;
 		}
 
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 1/1
#1 lore raw

Am 2020-06-20 um 4:54 a.m. schrieb Bernard Zhao:

Quoted 9 lines

The function kobject_init_and_add alloc memory like:
kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs ->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller ->kmalloc_slab, in err branch this memory not free. If use kmemleak, this path maybe catched.
These changes are to add kobject_put in kobject_init_and_add failed branch, fix potential memleak.

The patch is

I'll apply it to amd-staging-drm-next.

Thanks,
  Felix

Quoted 21 lines

---
Changes since V1:
*Remove duplicate changed file kfd_topology.c, this file`s fix already applied to the main line.

---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
index d27221ddcdeb..5ee4d6cfb16d 100644
@@ -124,6 +124,7 @@ void kfd_procfs_init(void)
 	if (ret) {
 		pr_warn("Could not create procfs proc folder");
 		/* If we fail to create the procfs, clean up */
+		kobject_put(procfs.kobj);
 		kfd_procfs_shutdown();
 	}
 }

drivers/gpu/drm/amd/amdkfd/kfd_process.c struct kfd_process *kfd_create_process(struct file *filep) · line 435

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -428,6 +429,7 @@ struct kfd_process *kfd_create_process(struct file *filep)
 					   (int)process->lead_thread->pid);
 		if (ret) {
 			pr_warn("Creating procfs pid directory failed");
+			kobject_put(process->kobj);
 			goto out;
 		}
 

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