]> git.baikalelectronics.ru Git - kernel.git/commitdiff
fs/userfaultfd: Fix maple tree iterator in userfaultfd_unregister()
authorLiam Howlett <liam.howlett@oracle.com>
Mon, 7 Nov 2022 20:11:42 +0000 (20:11 +0000)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 7 Nov 2022 20:58:26 +0000 (12:58 -0800)
When iterating the VMAs, the maple state needs to be invalidated if the
tree is modified by a split or merge to ensure the maple tree node
contained in the maple state is still valid.  These invalidations were
missed, so add them to the paths which alter the tree.

Reported-by: syzbot+0d2014e4da2ccced5b41@syzkaller.appspotmail.com
Fixes: cfc904214ba4 (userfaultfd: use maple tree iterator to iterate VMAs)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/userfaultfd.c

index 07c81ab3fd4dd301f830180f540db84dc711e00c..98ac37e34e3d4bd4ac229e01a42b2e2a8a27685d 100644 (file)
@@ -1630,17 +1630,20 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
                                 NULL_VM_UFFD_CTX, anon_vma_name(vma));
                if (prev) {
                        vma = prev;
+                       mas_pause(&mas);
                        goto next;
                }
                if (vma->vm_start < start) {
                        ret = split_vma(mm, vma, start, 1);
                        if (ret)
                                break;
+                       mas_pause(&mas);
                }
                if (vma->vm_end > end) {
                        ret = split_vma(mm, vma, end, 0);
                        if (ret)
                                break;
+                       mas_pause(&mas);
                }
        next:
                /*