selinux: allow context mounts on tmpfs, ramfs, devpts within user namespaces
PATCH v2 1/1 selinux: allow context mounts on tmpfs, ramfs, devpts within user namespaces
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:c13 /tmp
--- security/selinux/hooks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
security/selinux/hooks.c +7 -3
@@ -834,10 +834,14 @@ static int selinux_set_mnt_opts(struct super_block *sb, }/* -* If this is a user namespace mount, no contexts are allowed -* on the command line and security labels must be ignored. +* If this is a user namespace mount and the filesystem type is not +* explicitly whitelisted, then no contexts are allowed on the command +* line and security labels must be ignored. */ -if (sb->s_user_ns != &init_user_ns) { +if (sb->s_user_ns != &init_user_ns && +strcmp (sb->s_type->name,"tmpfs" ) && +strcmp (sb->s_type->name,"ramfs" ) && +strcmp (sb->s_type->name,"devpts" )) {if (context_sid || fscontext_sid || rootcontext_sid || defcontext_sid) { rc = -EACCES ;
Signature · 1 line
2.7.4
Quoted 37 lines · Stephen Smalley
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-onlyAfter:
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:c13 /tmpSigned-off-by Stephen Smalley <[email protected]>--- security/selinux/hooks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)security/selinux/hooks.c +2
-2@@ -834,10 +834,14 @@ static int selinux_set_mnt_opts(struct super_block *sb, }/* -* If this is a user namespace mount, no contexts are allowed -* on the command line and security labels must be ignored. +* If this is a user namespace mount and the filesystem type is not +* explicitly whitelisted, then no contexts are allowed on the command
security/selinux/hooks.c static int selinux_set_mnt_opts(struct super_block *sb, · line 847
Quoted 10 lines
security/selinux/hooks.c +5
-1+* line and security labels must be ignored. */ -if (sb->s_user_ns != &init_user_ns) { +if (sb->s_user_ns != &init_user_ns && +strcmp (sb->s_type->name,"tmpfs" ) && +strcmp (sb->s_type->name,"ramfs" ) && +strcmp (sb->s_type->name,"devpts" )) {if (context_sid || fscontext_sid || rootcontext_sid || defcontext_sid) { rc = -EACCES ;
We have confirmed that this patch fixes the first issue, we are seeing other issues, but I am not sure
if SELinux/UserNamespace is the issue.
Paul could you create a rpm kernel package with this patch?
Paul Moore
maintainerQuoted 53 lines · Daniel J Walsh
Quoted 37 lines · Stephen Smalley
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-onlyAfter:
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:c13 /tmpSigned-off-by Stephen Smalley <[email protected]>--- security/selinux/hooks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)security/selinux/hooks.c +2
-2@@ -834,10 +834,14 @@ static int selinux_set_mnt_opts(struct super_block *sb, }/* -* If this is a user namespace mount, no contexts are allowed -* on the command line and security labels must be ignored. +* If this is a user namespace mount and the filesystem type is not +* explicitly whitelisted, then no contexts are allowed on the command security/selinux/hooks.c static int selinux_set_mnt_opts(struct super_block *sb, · line 847
Quoted 10 lines
security/selinux/hooks.c +5
-1+* line and security labels must be ignored. */ -if (sb->s_user_ns != &init_user_ns) { +if (sb->s_user_ns != &init_user_ns && +strcmp (sb->s_type->name,"tmpfs" ) && +strcmp (sb->s_type->name,"ramfs" ) && +strcmp (sb->s_type->name,"devpts" )) {if (context_sid || fscontext_sid || rootcontext_sid || defcontext_sid) { rc = -EACCES ;We have confirmed that this patch fixes the first issue, we are seeing other issues, but I am not sure
if SELinux/UserNamespace is the issue.
Quoted 1 line
Paul could you create a rpm kernel package with this patch?
I've been working on getting a new netlabel_tools release out today, among other things. I'm going to be looking at the patches posted today tomorrow and merging as appropriate. Early each week (usually Monday, sometimes Tuesday if there are conflicts/problems), I create a new Fedora Rawhide kernel build with all of the SELinux and audit patches that are in my next branches, more information can be found at the link below:
* https://copr.fedorainfracloud.org/coprs/pcmoore/kernel-secnext
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 20 lines · Stephen Smalley
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-onlyAfter:
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:c13 /tmp
Quoted 4 lines
Signed-off-by Stephen Smalley <[email protected]>--- security/selinux/hooks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Merged, thanks.
Quoted 25 lines
security/selinux/hooks.c +7
-4@@ -834,10 +834,14 @@ static int selinux_set_mnt_opts(struct super_block *sb, }/* -* If this is a user namespace mount, no contexts are allowed -* on the command line and security labels must be ignored. +* If this is a user namespace mount and the filesystem type is not +* explicitly whitelisted, then no contexts are allowed on the command +* line and security labels must be ignored. */ -if (sb->s_user_ns != &init_user_ns) { +if (sb->s_user_ns != &init_user_ns && +strcmp (sb->s_type->name,"tmpfs" ) && +strcmp (sb->s_type->name,"ramfs" ) && +strcmp (sb->s_type->name,"devpts" )) {if (context_sid || fscontext_sid || rootcontext_sid || defcontext_sid) { rc = -EACCES ; --2.7.4
Signature · 2 lines
paul moore www.paul-moore.com