Skip to content

Commit

Permalink
userfaultfd: check VM_MAYWRITE was set after verifying the uffd is re…
Browse files Browse the repository at this point in the history
…gistered

commit 01e881f upstream.

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]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
aagit authored and gregkh committed Dec 21, 2018
1 parent 5f4610f commit b99eaef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/userfaultfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
cond_resched();

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

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

WARN_ON(!(vma->vm_flags & VM_MAYWRITE));

if (vma->vm_start > start)
start = vma->vm_start;
vma_end = min(end, vma->vm_end);
Expand Down

0 comments on commit b99eaef

Please sign in to comment.