The patch titled Subject: mm/mmap: fix return on maple tree expand fail in brk() has been added to the -mm mm-unstable branch. Its filename is mm-mmap-change-do_brk_flags-to-expand-existing-vma-and-add-do_brk_munmap-fix.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mmap-change-do_brk_flags-to-expand-existing-vma-and-add-do_brk_munmap-fix.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: mm/mmap: fix return on maple tree expand fail in brk() Date: Tue, 12 Jul 2022 14:51:08 +0000 When do_brk_flags() fails, ensure the necessary locking is undone. Link: https://lkml.kernel.org/r/20220712145059.4191132-1-Liam.Howlett@xxxxxxxxxx Fixes: e9bad648fe05 (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: Hugh Dickins <hughd@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/mmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/mm/mmap.c~mm-mmap-change-do_brk_flags-to-expand-existing-vma-and-add-do_brk_munmap-fix +++ a/mm/mmap.c @@ -2965,7 +2965,7 @@ static int do_brk_flags(struct ma_state vma->vm_end = addr + len; vma->vm_flags |= VM_SOFTDIRTY; if (mas_store_gfp(mas, vma, GFP_KERNEL)) - return -ENOMEM; + goto mas_expand_failed; if (vma->anon_vma) { anon_vma_interval_tree_post_update_vma(vma); @@ -3013,6 +3013,13 @@ mas_store_fail: vma_alloc_fail: vm_unacct_memory(len >> PAGE_SHIFT); return -ENOMEM; + +mas_expand_failed: + if (vma->anon_vma) { + anon_vma_interval_tree_post_update_vma(vma); + anon_vma_unlock_write(vma->anon_vma); + } + return -ENOMEM; } int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags) _ Patches currently in -mm which might be from liam.howlett@xxxxxxxxxx are android-binder-fix-lockdep-check-on-clearing-vma.patch maple-tree-add-new-data-structure-fix.patch maple-tree-add-new-data-structure-fix-2.patch maple-tree-add-new-data-structure-fix-3.patch maple-tree-add-new-data-structure-fix-4.patch lib-test_maple_tree-add-testing-for-maple-tree-fix.patch lib-test_maple_tree-add-testing-for-maple-tree-fix-2.patch lib-test_maple_tree-add-testing-for-maple-tree-fix-3.patch mm-mmap-change-do_brk_flags-to-expand-existing-vma-and-add-do_brk_munmap-fix.patch mm-remove-the-vma-linked-list-fix-3.patch mm-mlock-drop-dead-code-in-count_mm_mlocked_page_nr.patch