WSL2-Linux-Kernel/security
Ondrej Mosnacek fbbfb5c6bf selinux: always allow mounting submounts
[ Upstream commit 2cbdcb882f ]

If a superblock has the MS_SUBMOUNT flag set, we should always allow
mounting it. These mounts are done automatically by the kernel either as
part of mounting some parent mount (e.g. debugfs always mounts tracefs
under "tracing" for compatibility) or they are mounted automatically as
needed on subdirectory accesses (e.g. NFS crossmnt mounts). Since such
automounts are either an implicit consequence of the parent mount (which
is already checked) or they can happen during regular accesses (where it
doesn't make sense to check against the current task's context), the
mount permission check should be skipped for them.

Without this patch, attempts to access contents of an automounted
directory can cause unexpected SELinux denials.

In the current kernel tree, the MS_SUBMOUNT flag is set only via
vfs_submount(), which is called only from the following places:
 - AFS, when automounting special "symlinks" referencing other cells
 - CIFS, when automounting "referrals"
 - NFS, when automounting subtrees
 - debugfs, when automounting tracefs

In all cases the submounts are meant to be transparent to the user and
it makes sense that if mounting the master is allowed, then so should be
the automounts. Note that CAP_SYS_ADMIN capability checking is already
skipped for (SB_KERNMOUNT|SB_SUBMOUNT) in:
 - sget_userns() in fs/super.c:
	if (!(flags & (SB_KERNMOUNT|SB_SUBMOUNT)) &&
	    !(type->fs_flags & FS_USERNS_MOUNT) &&
	    !capable(CAP_SYS_ADMIN))
		return ERR_PTR(-EPERM);
 - sget() in fs/super.c:
        /* Ensure the requestor has permissions over the target filesystem */
        if (!(flags & (SB_KERNMOUNT|SB_SUBMOUNT)) && !ns_capable(user_ns, CAP_SYS_ADMIN))
                return ERR_PTR(-EPERM);

Verified internally on patched RHEL 7.6 with a reproducer using
NFS+httpd and selinux-tesuite.

Fixes: 93faccbbfa ("fs: Better permission checking for submounts")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-01-26 09:37:02 +01:00
..
apparmor apparmor: Fix uninitialized value in aa_split_fqname 2018-11-27 16:10:47 +01:00
integrity ima: re-initialize iint->atomic_flags 2018-12-01 09:43:00 +01:00
keys Revert "uapi/linux/keyctl.h: don't use C++ reserved keyword as a struct member name" 2018-09-29 03:06:04 -07:00
loadpin
selinux selinux: always allow mounting submounts 2019-01-26 09:37:02 +01:00
smack Smack: Fix handling of IPv4 traffic received by PF_INET6 sockets 2018-09-26 08:38:03 +02:00
tomoyo
yama Yama: Check for pid death before checking ancestry 2019-01-23 08:09:48 +01:00
Kconfig
Makefile
commoncap.c cap_inode_getsecurity: use d_find_any_alias() instead of d_find_alias() 2018-09-09 19:56:01 +02:00
device_cgroup.c
inode.c
lsm_audit.c
min_addr.c
security.c LSM: Check for NULL cred-security on free 2019-01-23 08:09:50 +01:00