Skip to content

Commit fd0c306

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: 29163734 CVE: CVE-2018-18397 Signed-off-by: Shan Hai <[email protected]> Reviewed-by: Jack Vogel <[email protected]>
1 parent 3eba1d5 commit fd0c306

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
@@ -1563,7 +1563,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
15631563
cond_resched();
15641564

15651565
BUG_ON(!vma_can_userfault(vma));
1566-
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
15671566

15681567
/*
15691568
* Nothing to do: this vma is already registered into this
@@ -1572,6 +1571,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
15721571
if (!vma->vm_userfaultfd_ctx.ctx)
15731572
goto skip;
15741573

1574+
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
1575+
15751576
if (vma->vm_start > start)
15761577
start = vma->vm_start;
15771578
vma_end = min(end, vma->vm_end);

0 commit comments

Comments
 (0)