userfaultfd: check VM_MAYWRITE was set after verifying the uffd is registered
authorAndrea Arcangeli <aarcange@redhat.com>
Fri, 14 Dec 2018 22:17:17 +0000 (14:17 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Dec 2018 13:13:04 +0000 (14:13 +0100)
commitb99eaefb6850b38abdd8a2029bbfde08170ec6c9
tree3fd8ff53b36338f0ba3d7eeea7b00bb6f199d344
parent5f4610fe2ed4351b45c0d82b3246f18b886d26f9
userfaultfd: check VM_MAYWRITE was set after verifying the uffd is registered

commit 01e881f5a1fca4677e82733061868c6d6ea05ca7 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/20181206212028.18726-2-aarcange@redhat.com
Cc: <stable@vger.kernel.org>
Fixes: 29ec90660d68 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/userfaultfd.c