userfaultfd: open userfaultfds with O_RDONLY
authorOndrej Mosnacek <omosnace@redhat.com>
Fri, 8 Jul 2022 09:34:51 +0000 (11:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:25:17 +0000 (13:25 +0200)
commit6e4be747f15fa32a6382ca2d9392fb9ba2ce051f
treeea86bc2f1c2b3a0fe0d1fa0bdb9684fc336cfec1
parent28d9b39733078fe3a7e74a9186872ed5ab496c48
userfaultfd: open userfaultfds with O_RDONLY

[ Upstream commit abec3d015fdfb7c63105c7e1c956188bf381aa55 ]

Since userfaultfd doesn't implement a write operation, it is more
appropriate to open it read-only.

When userfaultfds are opened read-write like it is now, and such fd is
passed from one process to another, SELinux will check both read and
write permissions for the target process, even though it can't actually
do any write operation on the fd later.

Inspired by the following bug report, which has hit the SELinux scenario
described above:
https://bugzilla.redhat.com/show_bug.cgi?id=1974559

Reported-by: Robert O'Callahan <roc@ocallahan.org>
Fixes: 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Peter Xu <peterx@redhat.com>
Acked-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/userfaultfd.c