Skip to content

Commit 0c837ef

Browse files
aagitjfvogel
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> (cherry picked from commit 01e881f) Orabug: 29163742 CVE: CVE-2018-18397 Signed-off-by: Shan Hai <shan.hai@oracle.com> Reviewed-by: Jack Vogel <jack.vogel@oracle.com>
1 parent 509b21e commit 0c837ef

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
@@ -1567,7 +1567,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
15671567
cond_resched();
15681568

15691569
BUG_ON(!vma_can_userfault(vma));
1570-
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
15711570

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

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

0 commit comments

Comments
 (0)