Skip to content

Commit 6f12be7

Browse files
tehcasterakpm00
authored andcommitted
mm, mremap: fix mremap() expanding vma with addr inside vma
Since 6.1 we have noticed random rpm install failures that were tracked to mremap() returning -ENOMEM and to commit ca3d76b ("mm: add merging after mremap resize"). The problem occurs when mremap() expands a VMA in place, but using an starting address that's not vma->vm_start, but somewhere in the middle. The extension_pgoff calculation introduced by the commit is wrong in that case, so vma_merge() fails due to pgoffs not being compatible. Fix the calculation. By the way it seems that the situations, where rpm now expands a vma from the middle, were made possible also due to that commit, thanks to the improved vma merging. Yet it should work just fine, except for the buggy calculation. Link: https://lkml.kernel.org/r/[email protected] Reported-by: Jiri Slaby <[email protected]> Link: https://bugzilla.suse.com/show_bug.cgi?id=1206359 Fixes: ca3d76b ("mm: add merging after mremap resize") Signed-off-by: Vlastimil Babka <[email protected]> Cc: Jakub Matěna <[email protected]> Cc: "Kirill A . Shutemov" <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1644d75 commit 6f12be7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/mremap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
10161016
long pages = (new_len - old_len) >> PAGE_SHIFT;
10171017
unsigned long extension_start = addr + old_len;
10181018
unsigned long extension_end = addr + new_len;
1019-
pgoff_t extension_pgoff = vma->vm_pgoff + (old_len >> PAGE_SHIFT);
1019+
pgoff_t extension_pgoff = vma->vm_pgoff +
1020+
((extension_start - vma->vm_start) >> PAGE_SHIFT);
10201021

10211022
if (vma->vm_flags & VM_ACCOUNT) {
10221023
if (security_vm_enough_memory_mm(mm, pages)) {

0 commit comments

Comments
 (0)