]> git.baikalelectronics.ru Git - kernel.git/commit
userfaultfd: fix a race between writeprotect and exit_mmap()
authorNadav Amit <namit@vmware.com>
Mon, 18 Oct 2021 22:15:25 +0000 (15:15 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 19 Oct 2021 06:22:02 +0000 (20:22 -1000)
commita2b7664bdf5cc1319eaf123a80716dba9b7416fb
tree1156aa57eb9c1c0c0c52a72ddb33fa91e827584f
parent247ac46cc9a8adcab3674e2720a71744f346db4a
userfaultfd: fix a race between writeprotect and exit_mmap()

A race is possible when a process exits, its VMAs are removed by
exit_mmap() and at the same time userfaultfd_writeprotect() is called.

The race was detected by KASAN on a development kernel, but it appears
to be possible on vanilla kernels as well.

Use mmget_not_zero() to prevent the race as done in other userfaultfd
operations.

Link: https://lkml.kernel.org/r/20210921200247.25749-1-namit@vmware.com
Fixes: 979fc1e1ffe0e ("userfaultfd: wp: add the writeprotect API to userfaultfd ioctl")
Signed-off-by: Nadav Amit <namit@vmware.com>
Tested-by: Li Wang <liwang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/userfaultfd.c