All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: selinux@tycho.nsa.gov
Cc: paul@paul-moore.com, dwalsh@redhat.com,
	seth.forshee@canonical.com, Stephen Smalley <sds@tycho.nsa.gov>
Subject: [RFC][PATCH] selinux: allow context mounts on tmpfs, ramfs, devpts within user namespaces
Date: Wed,  7 Dec 2016 12:16:07 -0500	[thread overview]
Message-ID: <1481130967-24760-1-git-send-email-sds@tycho.nsa.gov> (raw)

commit aad82892af261b9903cc11c55be3ecf5f0b0b4f8 ("selinux: Add support for
unprivileged mounts from user namespaces") prohibited any use of context
mount options within non-init user namespaces.  However, this breaks
use of context mount options for tmpfs mounts within user namespaces,
which are being used by Docker/runc.  There is no reason to block such
usage for tmpfs, ramfs or devpts.  Exempt these filesystem types
from this restriction.

Before:
sh$ userns_child_exec  -p -m -U -M '0 1000 1' -G '0 1000 1' bash
sh# mount -t tmpfs -o context=system_u:object_r:user_tmp_t:s0:c13 none /tmp
mount: tmpfs is write-protected, mounting read-only
mount: cannot mount tmpfs read-only

After:
sh$ userns_child_exec  -p -m -U -M '0 1000 1' -G '0 1000 1' bash
sh# mount -t tmpfs -o context=system_u:object_r:user_tmp_t:s0:c13 none /tmp
sh# ls -Zd /tmp
unconfined_u:object_r:user_tmp_t:s0 /tmp

Note that this still isn't quite right, and I do not know why yet -
the category (:c13) was dropped.  This works correctly in the init
namespace, and strace of mount shows that it is passing the context
correctly to the kernel and returning 0.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
---
 security/selinux/hooks.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 98a2e92..ef882a3 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -839,8 +839,12 @@ static int selinux_set_mnt_opts(struct super_block *sb,
 	if (sb->s_user_ns != &init_user_ns) {
 		if (context_sid || fscontext_sid || rootcontext_sid ||
 		    defcontext_sid) {
-			rc = -EACCES;
-			goto out;
+			if (strcmp(sb->s_type->name, "tmpfs") &&
+			    strcmp(sb->s_type->name, "ramfs") &&
+			    strcmp(sb->s_type->name, "devpts")) {
+				rc = -EACCES;
+				goto out;
+			}
 		}
 		if (sbsec->behavior == SECURITY_FS_USE_XATTR) {
 			sbsec->behavior = SECURITY_FS_USE_MNTPOINT;
-- 
2.7.4

             reply	other threads:[~2016-12-07 17:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 17:16 Stephen Smalley [this message]
2016-12-07 21:43 ` [RFC][PATCH] selinux: allow context mounts on tmpfs, ramfs, devpts within user namespaces Stephen Smalley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481130967-24760-1-git-send-email-sds@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=dwalsh@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@tycho.nsa.gov \
    --cc=seth.forshee@canonical.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.