Skip to content

Commit 01e67e0

Browse files
bonzinitorvalds
authored andcommitted
mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0)
If an mremap() syscall with old_size=0 ends up in move_page_tables(), it will call invalidate_range_start()/invalidate_range_end() unnecessarily, i.e. with an empty range. This causes a WARN in KVM's mmu_notifier. In the past, empty ranges have been diagnosed to be off-by-one bugs, hence the WARNing. Given the low (so far) number of unique reports, the benefits of detecting more buggy callers seem to outweigh the cost of having to fix cases such as this one, where userspace is doing something silly. In this particular case, an early return from move_page_tables() is enough to fix the issue. Link: https://lkml.kernel.org/r/20220329173155.172439-1-pbonzini@redhat.com Reported-by: syzbot+6bde52d89cfdf9f61425@syzkaller.appspotmail.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Sean Christopherson <seanjc@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a431dbb commit 01e67e0

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

mm/mremap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
486486
pmd_t *old_pmd, *new_pmd;
487487
pud_t *old_pud, *new_pud;
488488

489+
if (!len)
490+
return 0;
491+
489492
old_end = old_addr + len;
490493
flush_cache_range(vma, old_addr, old_end);
491494

0 commit comments

Comments
 (0)