aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kravetz <[email protected]>2022-10-17 19:49:45 -0700
committerAndrew Morton <[email protected]>2022-10-20 21:27:22 -0700
commit5789151e48acc3fd34d2109bf2021dc4df5e33e9 (patch)
treee2d09b2ac8beca11692a13ef1c7a9e925efab146
parenteacf96d23f23e5bfd175be07048246efd0be4cc6 (diff)
mm/mmap: undo ->mmap() when mas_preallocate() fails
A memory leak in hugetlb_reserve_pages was reported in [1]. The root cause was traced to an error path in mmap_region when mas_preallocate() fails. In this case, the vma is freed after a successful call to filesystem specific mmap. The hugetlbfs mmap routine may allocate data structures pointed to by m_private_data. These need to be cleaned up by the hugetlb vm_ops->close() routine. The same issue was addressed by commit deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") for the arch_validate_flags() test. Go to the same close_and_free_vma label if mas_preallocate() fails. [1] https://lore.kernel.org/linux-mm/CAKXUXMxf7OiCwbxib7MwfR4M1b5+b3cNTU7n5NV9Zm4967=FPQ@mail.gmail.com/ Link: https://lkml.kernel.org/r/[email protected] Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree") Signed-off-by: Mike Kravetz <[email protected]> Reported-by: Lukas Bulwahn <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Carlos Llamas <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r--mm/mmap.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index bf2122af94e7..3c9890e443a3 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2681,7 +2681,7 @@ cannot_expand:
if (mas_preallocate(&mas, vma, GFP_KERNEL)) {
error = -ENOMEM;
if (file)
- goto unmap_and_free_vma;
+ goto close_and_free_vma;
else
goto free_vma;
}