All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/mmap: Fix potential leak on do_mas_align_munmap()
@ 2022-05-13 14:15 Liam Howlett
  2022-05-13 14:32 ` Liam Howlett
  0 siblings, 1 reply; 2+ messages in thread
From: Liam Howlett @ 2022-05-13 14:15 UTC (permalink / raw)
  To: maple-tree, linux-mm, linux-kernel, Andrew Morton; +Cc: Qian Cai

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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index ebfd71a79814..9d41df730b22 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2365,7 +2365,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;
 	/*
@@ -2504,6 +2504,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;
 }
-- 
2.35.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-13 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 14:15 [PATCH] mm/mmap: Fix potential leak on do_mas_align_munmap() Liam Howlett
2022-05-13 14:32 ` 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.