Skip to content

Commit 7f31cce

Browse files
howlettakpm00
authored andcommitted
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. Link: https://lkml.kernel.org/r/[email protected] Fixes: 8220543 ("nommu: remove uses of VMA linked list") Signed-off-by: Liam R. Howlett <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Yu Zhao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent bf61acb commit 7f31cce

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/nommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ unsigned long do_mmap(struct file *file,
12401240
error_just_free:
12411241
up_write(&nommu_region_sem);
12421242
error:
1243+
mas_destroy(&mas);
12431244
if (region->vm_file)
12441245
fput(region->vm_file);
12451246
kmem_cache_free(vm_region_jar, region);
@@ -1250,7 +1251,6 @@ unsigned long do_mmap(struct file *file,
12501251

12511252
sharing_violation:
12521253
up_write(&nommu_region_sem);
1253-
mas_destroy(&mas);
12541254
pr_warn("Attempt to share mismatched mappings\n");
12551255
ret = -EINVAL;
12561256
goto error;

0 commit comments

Comments
 (0)