Skip to contentSkip to conversation

mm/mmap: Properly unaccount memory on mas_preallocate() failure

PATCH Applied Alistair Popple 2 participants 2 messages Dec 2, 2022

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

PATCH 1/1 mm/mmap: Properly unaccount memory on mas_preallocate() failure

security_vm_enough_memory_mm() accounts memory via a call to vm_acct_memory(). Therefore any subsequent failures should unaccount for this memory prior to returning the error.

Fixes 28c5609fb236 ("mm/mmap: preallocate maple nodes for brk vma expansion")

---

Pretty trivial fixup that I noticed was needed while working on the code.

---
 mm/mmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/mmap.c +3 -3
index 74a84eb33b90..3e50a571c3c4 100644
@@ -2954,7 +2954,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
 	    ((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) {
 		mas_set_range(mas, vma->vm_start, addr + len - 1);
 		if (mas_preallocate(mas, vma, GFP_KERNEL))
-			return -ENOMEM;
+			goto unacct_fail;
 
 		vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0);
 		if (vma->anon_vma) {
@@ -2976,7 +2976,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
 	/* create a vma struct for an anonymous mapping */
 	vma = vm_area_alloc(mm);
 	if (!vma)
-		goto vma_alloc_fail;
+		goto unacct_fail;
 
 	vma_set_anonymous(vma);
 	vma->vm_start = addr;
@@ -3001,7 +3001,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
 
 mas_store_fail:
 	vm_area_free(vma);
-vma_alloc_fail:
+unacct_fail:
 	vm_unacct_memory(len >> PAGE_SHIFT);
 	return -ENOMEM;
 }
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Alistair Popple

security_vm_enough_memory_mm() accounts memory via a call to vm_acct_memory(). Therefore any subsequent failures should unaccount for this memory prior to returning the error.

Fixes 28c5609fb236 ("mm/mmap: preallocate maple nodes for brk vma expansion")
Quoted 43 lines

---

Pretty trivial fixup that I noticed was needed while working on the code.

---
 mm/mmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/mmap.c +3 -3
index 74a84eb33b90..3e50a571c3c4 100644
@@ -2954,7 +2954,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
 	    ((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) {
 		mas_set_range(mas, vma->vm_start, addr + len - 1);
 		if (mas_preallocate(mas, vma, GFP_KERNEL))
-			return -ENOMEM;
+			goto unacct_fail;
 
 		vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0);
 		if (vma->anon_vma) {
@@ -2976,7 +2976,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
 	/* create a vma struct for an anonymous mapping */
 	vma = vm_area_alloc(mm);
 	if (!vma)
-		goto vma_alloc_fail;
+		goto unacct_fail;
 
 	vma_set_anonymous(vma);
 	vma->vm_start = addr;
@@ -3001,7 +3001,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
 
 mas_store_fail:
 	vm_area_free(vma);
-vma_alloc_fail:
+unacct_fail:
 	vm_unacct_memory(len >> PAGE_SHIFT);
 	return -ENOMEM;
 }
Signature · 1 line
2.35.1