Skip to contentSkip to conversation

mm/mmap: Fix potential leak on do_mas_align_munmap()

PATCH In review Liam Howlett 1 participant 2 messages May 13, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/mmap: Fix potential leak on do_mas_align_munmap()

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)
---
 mm/mmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/mmap.c +3 -1
index ebfd71a79814..9d41df730b22 100644
@@ -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;
 }
Signature · 1 line
2.35.1
#1 lore raw
Quoted 5 lines · Liam Howlett

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)

This is the wrong fixes. It fixes "67/69 mm: remove the vma linked list".

Quoted 30 lines
---
 mm/mmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/mmap.c +3 -1
index ebfd71a79814..9d41df730b22 100644
@@ -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;
 }
Signature · 1 line
2.35.1