From: Hugh Dickins Date: Sat, 8 Jul 2023 23:04:00 +0000 (-0700) Subject: mm: lock newly mapped VMA with corrected ordering X-Git-Tag: v6.6.17~4402 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c7873e3364570ec89343ff4877e0f27a7b21a61;p=platform%2Fkernel%2Flinux-rpi.git mm: lock newly mapped VMA with corrected ordering Lockdep is certainly right to complain about (&vma->vm_lock->lock){++++}-{3:3}, at: vma_start_write+0x2d/0x3f but task is already holding lock: (&mapping->i_mmap_rwsem){+.+.}-{3:3}, at: mmap_region+0x4dc/0x6db Invert those to the usual ordering. Fixes: 33313a747e81 ("mm: lock newly mapped VMA which can be modified after it becomes visible") Cc: stable@vger.kernel.org Signed-off-by: Hugh Dickins Tested-by: Suren Baghdasaryan Signed-off-by: Linus Torvalds --- diff --git a/mm/mmap.c b/mm/mmap.c index 84c7143..3eda23c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2809,11 +2809,11 @@ cannot_expand: if (vma_iter_prealloc(&vmi)) goto close_and_free_vma; + /* Lock the VMA since it is modified after insertion into VMA tree */ + vma_start_write(vma); if (vma->vm_file) i_mmap_lock_write(vma->vm_file->f_mapping); - /* Lock the VMA since it is modified after insertion into VMA tree */ - vma_start_write(vma); vma_iter_store(&vmi, vma); mm->map_count++; if (vma->vm_file) {