]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/mmap: Fix potential leak on do_mas_align_munmap() maple_mm_stable_lowmem
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 13 May 2022 14:13:22 +0000 (10:13 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 13 May 2022 14:43:31 +0000 (10:43 -0400)
There is a leak when the system is low on resources and fails to
allocate enough memory to complete the munmap task.  Fix this by adding
the necessary free operations in the unwinding.

Fixes: a760774e7b7b (mm: start tracking VMAs with maple tree)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/mmap.c

index 546034e7e1f70cb45408076f0761178318ddb254..de264351ce88c41d185390d37ed6398938c599d7 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2454,7 +2454,7 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
                return -ENOMEM;
 
        if (mas_preallocate(&mas_detach, vma, GFP_KERNEL))
-               return -ENOMEM;
+               goto detach_alloc_fail;
 
        mas->last = end - 1;
        /* If we need to split any vma, do it now to save pain later. */
@@ -2577,6 +2577,8 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
 map_count_exceeded:
 split_failed:
 userfaultfd_error:
+       mas_destroy(&mas_detach);
+detach_alloc_fail:
        mas_destroy(mas);
        return error;
 }