Skip to content

Commit 78d6121

Browse files
Anthony Yznagaopsiff
authored andcommitted
mm/mremap: fix unaccount of memory on vma_merge() failure
mainline inclusion from mainline-v6.7-rc1 categroy: bugfix Fix mremap so that only accounted memory is unaccounted if the mapping is expandable but vma_merge() fails. Link: https://lkml.kernel.org/r/20230830004549.16131-1-anthony.yznaga@oracle.com Fixes: fdbef61 ("mm/mremap: don't account pages in vma_to_resize()") Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> Acked-by: Brian Geffon <bgeffon@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 954652b) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 7a0c4f9 commit 78d6121

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

mm/mremap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,14 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
10441044
pgoff_t extension_pgoff = vma->vm_pgoff +
10451045
((extension_start - vma->vm_start) >> PAGE_SHIFT);
10461046
VMA_ITERATOR(vmi, mm, extension_start);
1047+
long charged = 0;
10471048

10481049
if (vma->vm_flags & VM_ACCOUNT) {
10491050
if (security_vm_enough_memory_mm(mm, pages)) {
10501051
ret = -ENOMEM;
10511052
goto out;
10521053
}
1054+
charged = pages;
10531055
}
10541056

10551057
/*
@@ -1065,7 +1067,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
10651067
vma->vm_file, extension_pgoff, vma_policy(vma),
10661068
vma->vm_userfaultfd_ctx, anon_vma_name(vma));
10671069
if (!vma) {
1068-
vm_unacct_memory(pages);
1070+
vm_unacct_memory(charged);
10691071
ret = -ENOMEM;
10701072
goto out;
10711073
}

0 commit comments

Comments
 (0)