selinux: move user accesses in selinuxfs out of locked regions
authorJann Horn <jannh@google.com>
Fri, 29 Jun 2018 00:39:54 +0000 (20:39 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Jul 2018 09:27:12 +0000 (11:27 +0200)
commit05e3000bb32e23939e91b57d8aadd2b14a7c4f87
tree3ed0eb0b229ac33b23c93775b1665c8448fb5126
parent54428453efda4c1c35ca75a0a5aa170de87ff1b0
selinux: move user accesses in selinuxfs out of locked regions

commit 0da74120c5341389b97c4ee27487a97224999ee1 upstream.

If a user is accessing a file in selinuxfs with a pointer to a userspace
buffer that is backed by e.g. a userfaultfd, the userspace access can
stall indefinitely, which can block fsi->mutex if it is held.

For sel_read_policy(), remove the locking, since this method doesn't seem
to access anything that requires locking.

For sel_read_bool(), move the user access below the locked region.

For sel_write_bool() and sel_commit_bools_write(), move the user access
up above the locked region.

Cc: stable@vger.kernel.org
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: removed an unused variable in sel_read_policy()]
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/selinux/selinuxfs.c