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/[email protected] Cc: <[email protected]> Fixes: 29ec906 ("userfaultfd: shmem/hugetlbfs: only allow to register VM_MAYWRITE vmas") Signed-off-by: Andrea Arcangeli <[email protected]> Reported-by: [email protected] Acked-by: Mike Rapoport <[email protected]> Acked-by: Hugh Dickins <[email protected]> Acked-by: Peter Xu <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> (cherry picked from commit 01e881f) Orabug: 29163742 CVE: CVE-2018-18397 Signed-off-by: Shan Hai <[email protected]> Reviewed-by: Jack Vogel <[email protected]>
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)