|
|
0a981fd |
From 01593d3299a1cfdb5e08acf95f63ec59dd674906 Mon Sep 17 00:00:00 2001
|
|
|
0a981fd |
From: Stephen Smalley <sds@tycho.nsa.gov>
|
|
|
0a981fd |
Date: Mon, 9 Jan 2017 10:07:31 -0500
|
|
|
0a981fd |
Subject: [PATCH] selinux: allow context mounts on tmpfs, ramfs, devpts within
|
|
|
0a981fd |
user namespaces
|
|
|
0a981fd |
|
|
|
0a981fd |
commit aad82892af261b9903cc11c55be3ecf5f0b0b4f8 ("selinux: Add support for
|
|
|
0a981fd |
unprivileged mounts from user namespaces") prohibited any use of context
|
|
|
0a981fd |
mount options within non-init user namespaces. However, this breaks
|
|
|
0a981fd |
use of context mount options for tmpfs mounts within user namespaces,
|
|
|
0a981fd |
which are being used by Docker/runc. There is no reason to block such
|
|
|
0a981fd |
usage for tmpfs, ramfs or devpts. Exempt these filesystem types
|
|
|
0a981fd |
from this restriction.
|
|
|
0a981fd |
|
|
|
0a981fd |
Before:
|
|
|
0a981fd |
sh$ userns_child_exec -p -m -U -M '0 1000 1' -G '0 1000 1' bash
|
|
|
0a981fd |
sh# mount -t tmpfs -o context=system_u:object_r:user_tmp_t:s0:c13 none /tmp
|
|
|
0a981fd |
mount: tmpfs is write-protected, mounting read-only
|
|
|
0a981fd |
mount: cannot mount tmpfs read-only
|
|
|
0a981fd |
|
|
|
0a981fd |
After:
|
|
|
0a981fd |
sh$ userns_child_exec -p -m -U -M '0 1000 1' -G '0 1000 1' bash
|
|
|
0a981fd |
sh# mount -t tmpfs -o context=system_u:object_r:user_tmp_t:s0:c13 none /tmp
|
|
|
0a981fd |
sh# ls -Zd /tmp
|
|
|
0a981fd |
unconfined_u:object_r:user_tmp_t:s0:c13 /tmp
|
|
|
0a981fd |
|
|
|
0a981fd |
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
|
|
|
0a981fd |
Signed-off-by: Paul Moore <paul@paul-moore.com>
|
|
|
0a981fd |
---
|
|
|
0a981fd |
security/selinux/hooks.c | 10 +++++++---
|
|
|
0a981fd |
1 file changed, 7 insertions(+), 3 deletions(-)
|
|
|
0a981fd |
|
|
|
0a981fd |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
|
|
|
0a981fd |
index e4b953f..e32f4b5 100644
|
|
|
0a981fd |
--- a/security/selinux/hooks.c
|
|
|
0a981fd |
+++ b/security/selinux/hooks.c
|
|
|
0a981fd |
@@ -834,10 +834,14 @@ static int selinux_set_mnt_opts(struct super_block *sb,
|
|
|
0a981fd |
}
|
|
|
0a981fd |
|
|
|
0a981fd |
/*
|
|
|
0a981fd |
- * If this is a user namespace mount, no contexts are allowed
|
|
|
0a981fd |
- * on the command line and security labels must be ignored.
|
|
|
0a981fd |
+ * If this is a user namespace mount and the filesystem type is not
|
|
|
0a981fd |
+ * explicitly whitelisted, then no contexts are allowed on the command
|
|
|
0a981fd |
+ * line and security labels must be ignored.
|
|
|
0a981fd |
*/
|
|
|
0a981fd |
- if (sb->s_user_ns != &init_user_ns) {
|
|
|
0a981fd |
+ if (sb->s_user_ns != &init_user_ns &&
|
|
|
0a981fd |
+ strcmp(sb->s_type->name, "tmpfs") &&
|
|
|
0a981fd |
+ strcmp(sb->s_type->name, "ramfs") &&
|
|
|
0a981fd |
+ strcmp(sb->s_type->name, "devpts")) {
|
|
|
0a981fd |
if (context_sid || fscontext_sid || rootcontext_sid ||
|
|
|
0a981fd |
defcontext_sid) {
|
|
|
0a981fd |
rc = -EACCES;
|
|
|
0a981fd |
--
|
|
|
0a981fd |
2.9.3
|
|
|
0a981fd |
|