The patch titled Subject: mmap: fix do_brk_flags() modifying obviously incorrect VMAs has been added to the -mm mm-unstable branch. Its filename is mmap-fix-do_brk_flags-modifying-obviously-incorrect-vmas.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mmap-fix-do_brk_flags-modifying-obviously-incorrect-vmas.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Liam Howlett <liam.howlett@xxxxxxxxxx> Subject: mmap: fix do_brk_flags() modifying obviously incorrect VMAs Date: Mon, 5 Dec 2022 19:23:17 +0000 Add more sanity checks to the VMA that do_brk_flags() will expand. Ensure the VMA matches basic merge requirements within the function before calling can_vma_merge_after(). Drop the duplicate checks from vm_brk_flags() since they will be enforced later. Link: https://lkml.kernel.org/r/20221205192304.1957418-1-Liam.Howlett@xxxxxxxxxx Fixes: 2e7ce7d354f2 ("mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()") Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> Suggested-by: Jann Horn <jannh@xxxxxxxxxx> Cc: Jason A. Donenfeld <Jason@xxxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: SeongJae Park <sj@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Cc: Yu Zhao <yuzhao@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/mmap.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- a/mm/mmap.c~mmap-fix-do_brk_flags-modifying-obviously-incorrect-vmas +++ a/mm/mmap.c @@ -2945,9 +2945,9 @@ static int do_brk_flags(struct ma_state * Expand the existing vma if possible; Note that singular lists do not * occur after forking, so the expand will only happen on new VMAs. */ - if (vma && - (!vma->anon_vma || list_is_singular(&vma->anon_vma_chain)) && - ((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) { + if (vma && vma->vm_end == addr && !vma_policy(vma) && + can_vma_merge_after(vma, flags, NULL, NULL, + addr >> PAGE_SHIFT, NULL_VM_UFFD_CTX, NULL)) { mas_set_range(mas, vma->vm_start, addr + len - 1); if (mas_preallocate(mas, vma, GFP_KERNEL)) goto unacct_fail; @@ -3034,11 +3034,6 @@ int vm_brk_flags(unsigned long addr, uns goto munmap_failed; vma = mas_prev(&mas, 0); - if (!vma || vma->vm_end != addr || vma_policy(vma) || - !can_vma_merge_after(vma, flags, NULL, NULL, - addr >> PAGE_SHIFT, NULL_VM_UFFD_CTX, NULL)) - vma = NULL; - ret = do_brk_flags(&mas, vma, addr, len, flags); populate = ((mm->def_flags & VM_LOCKED) != 0); mmap_write_unlock(mm); _ Patches currently in -mm which might be from liam.howlett@xxxxxxxxxx are mmap-fix-do_brk_flags-modifying-obviously-incorrect-vmas.patch maple_tree-fix-mas_find_rev-comment.patch maple_tree-update-copyright-dates-for-test-code.patch