Skip to content

Commit 01e881f

Browse files
aagittorvalds
authored andcommitted
userfaultfd: check VM_MAYWRITE was set after verifying the uffd is registered
Calling UFFDIO_UNREGISTER on virtual ranges not yet registered in uffd could trigger an harmless false positive WARN_ON. Check the vma is already registered before checking VM_MAYWRITE to shut off the false positive warning. Link: http://lkml.kernel.org/r/20181206212028.18726-2-aarcange@redhat.com Cc: <stable@vger.kernel.org> Fixes: 29ec906 ("userfaultfd: shmem/hugetlbfs: only allow to register VM_MAYWRITE vmas") Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Reported-by: syzbot+06c7092e7d71218a2c16@syzkaller.appspotmail.com Acked-by: Mike Rapoport <rppt@linux.ibm.com> Acked-by: Hugh Dickins <hughd@google.com> Acked-by: Peter Xu <peterx@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 61c6de6 commit 01e881f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/userfaultfd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
15661566
cond_resched();
15671567

15681568
BUG_ON(!vma_can_userfault(vma));
1569-
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
15701569

15711570
/*
15721571
* Nothing to do: this vma is already registered into this
@@ -1575,6 +1574,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
15751574
if (!vma->vm_userfaultfd_ctx.ctx)
15761575
goto skip;
15771576

1577+
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
1578+
15781579
if (vma->vm_start > start)
15791580
start = vma->vm_start;
15801581
vma_end = min(end, vma->vm_end);

0 commit comments

Comments
 (0)