* [PATCH] mm/mmap: undo ->mmap() when mas_preallocate() fails
@ 2022-10-18 2:49 Mike Kravetz
2022-10-18 13:39 ` Liam Howlett
0 siblings, 1 reply; 2+ messages in thread
From: Mike Kravetz @ 2022-10-18 2:49 UTC (permalink / raw)
To: linux-mm, linux-kernel
Cc: Lukas Bulwahn, Muchun Song, Liam Howlett, Carlos Llamas,
Catalin Marinas, Andrii Nakryiko, Andrew Morton, Mike Kravetz
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/
Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree")
Reported-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
mm/mmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
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;
}
--
2.37.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/mmap: undo ->mmap() when mas_preallocate() fails
2022-10-18 2:49 [PATCH] mm/mmap: undo ->mmap() when mas_preallocate() fails Mike Kravetz
@ 2022-10-18 13:39 ` Liam Howlett
0 siblings, 0 replies; 2+ messages in thread
From: Liam Howlett @ 2022-10-18 13:39 UTC (permalink / raw)
To: Mike Kravetz
Cc: linux-mm, linux-kernel, Lukas Bulwahn, Muchun Song,
Carlos Llamas, Catalin Marinas, Andrii Nakryiko, Andrew Morton
This is for sure necessary.
Thanks Mike & Lukas.
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
* Mike Kravetz <mike.kravetz@oracle.com> [221017 22:49]:
> 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/
>
> Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree")
> Reported-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
> mm/mmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> 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;
> }
> --
> 2.37.3
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-18 13:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 2:49 [PATCH] mm/mmap: undo ->mmap() when mas_preallocate() fails Mike Kravetz
2022-10-18 13:39 ` Liam Howlett
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.