]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/mmap: Fix leak on expand_downwards() and expand_upwards()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 12 May 2022 17:53:29 +0000 (13:53 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 13 May 2022 14:43:31 +0000 (10:43 -0400)
A memory leak is possible in the race and error path in both
expand_downwards() and expand_upwards() due to the maple tree
preallocations.  Fix these by always destroying the maple state.

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

index d2fccec093fa8032ff929494ea8cae1106619ab8..546034e7e1f70cb45408076f0761178318ddb254 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2017,6 +2017,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
        }
        anon_vma_unlock_write(vma->anon_vma);
        khugepaged_enter_vma_merge(vma, vma->vm_flags);
+       mas_destroy(&mas);
        return error;
 }
 #endif /* CONFIG_STACK_GROWSUP || CONFIG_IA64 */
@@ -2098,6 +2099,7 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address)
        }
        anon_vma_unlock_write(vma->anon_vma);
        khugepaged_enter_vma_merge(vma, vma->vm_flags);
+       mas_destroy(&mas);
        return error;
 }