Skip to contentSkip to conversation

nommu: Fix memory leak in do_mmap() error path

PATCH New Liam Howlett 1 participant 1 message Jan 10, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nommu: Fix memory leak in do_mmap() error path

The preallocation of the maple tree nodes may leak if the error path to "error_just_free" is taken. Fix this by moving the freeing of the maple tree nodes to a shared location for all error paths.

Fixes 8220543df148 ("nommu: remove uses of VMA linked list")

---

Changes since v1:
- Added 'Cc: [email protected]' to commit message

 mm/nommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/nommu.c +1 -1
index 214c70e1d059..c8252f01d5db 100644
@@ -1240,6 +1240,7 @@ unsigned long do_mmap(struct file *file,
 error_just_free:
 	up_write(&nommu_region_sem);
 error:
+	mas_destroy(&mas);
 	if (region->vm_file)
 		fput(region->vm_file);
 	kmem_cache_free(vm_region_jar, region);
@@ -1250,7 +1251,6 @@ unsigned long do_mmap(struct file *file,
 
 sharing_violation:
 	up_write(&nommu_region_sem);
-	mas_destroy(&mas);
 	pr_warn("Attempt to share mismatched mappings\n");
 	ret = -EINVAL;
 	goto error;
Signature · 1 line
2.35.1