Skip to content

Commit 954652b

Browse files
Anthony Yznagaakpm00
authored andcommitted
mm/mremap: fix unaccount of memory on vma_merge() failure
Fix mremap so that only accounted memory is unaccounted if the mapping is expandable but vma_merge() fails. Link: https://lkml.kernel.org/r/[email protected] Fixes: fdbef61 ("mm/mremap: don't account pages in vma_to_resize()") Signed-off-by: Anthony Yznaga <[email protected]> Acked-by: Brian Geffon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b6afcb9 commit 954652b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mm/mremap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,12 +1037,14 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
10371037
pgoff_t extension_pgoff = vma->vm_pgoff +
10381038
((extension_start - vma->vm_start) >> PAGE_SHIFT);
10391039
VMA_ITERATOR(vmi, mm, extension_start);
1040+
long charged = 0;
10401041

10411042
if (vma->vm_flags & VM_ACCOUNT) {
10421043
if (security_vm_enough_memory_mm(mm, pages)) {
10431044
ret = -ENOMEM;
10441045
goto out;
10451046
}
1047+
charged = pages;
10461048
}
10471049

10481050
/*
@@ -1058,7 +1060,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
10581060
vma->vm_file, extension_pgoff, vma_policy(vma),
10591061
vma->vm_userfaultfd_ctx, anon_vma_name(vma));
10601062
if (!vma) {
1061-
vm_unacct_memory(pages);
1063+
vm_unacct_memory(charged);
10621064
ret = -ENOMEM;
10631065
goto out;
10641066
}

0 commit comments

Comments
 (0)