Skip to contentSkip to conversation

Why do we block context="foobar" from User Namespace

DISCUSSION Daniel J Walsh 3 participants 6 messages Dec 6, 2016 – Dec 7, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

Currently in SELinux and UserNamespace can not be enabled with Docker/runc at the same time.

Runc mounts tmpfs directories with --context="system_u:object_r:container_file_t:s0:c1,c2" type labels but the following patch blocks the use of context mounts when using user namespace.

http://kernel.suse.com/cgit/kernel/commit/?id=aad82892af261b9903cc11c55be3ecf5f0b0b4f8

User Namespace has to be established before tmpfs are mounted so we are unable to mount a tmpfs with a context=flag and UserNamespace enabled.

Controlling the ability to change the label of a mounted file systemd should be a MAC decision not a DAC, or UserNamespace. Setting the SELinux labels on an object like a file system mount point should be controlled by SELinux. SELinux should check if the label of the process doing the mount is able to relabel from the label of the mount point, and labelto the specified label.

SELinux does this for privileged processes (running with SYS_ADMIN) so use namespace should not be any different. Also the process doing the mount would be allowed by DAC to set the label of the tmpfs after it is mounted (As long as SELinux allowed).

There is no security difference between:

mount -o tmpfs context="foobar" none /dev

And

mount -o tmpfs none /dev

chcon foobar -R /dev

The second would not be blocked by usernamespace.

Bottom line this patch should be reverted so container runtimes like docker can use both User Namespace and SELinux at the same time.

#1 lore raw
Quoted 28 lines · Daniel J Walsh

Currently in SELinux and UserNamespace can not be enabled with Docker/runc at the same time.

Runc mounts tmpfs directories with --context="system_u:object_r:container_file_t:s0:c1,c2" type labels but the following patch blocks the use of context mounts when using user namespace.

http://kernel.suse.com/cgit/kernel/commit/?id=aad82892af261b9903cc11c55be3ecf5f0b0b4f8

User Namespace has to be established before tmpfs are mounted so we are unable to mount a tmpfs with a context=flag and UserNamespace enabled.

Controlling the ability to change the label of a mounted file systemd should be a MAC decision not a DAC, or UserNamespace. Setting the SELinux labels on an object like a file system mount point should be controlled by SELinux. SELinux should check if the label of the process doing the mount is able to relabel from the label of the mount point, and labelto the specified label.

SELinux does this for privileged processes (running with SYS_ADMIN) so use namespace should not be any different. Also the process doing the mount would be allowed by DAC to set the label of the tmpfs after it is mounted (As long as SELinux allowed).

There is no security difference between:

mount -o tmpfs context="foobar" none /dev

And

mount -o tmpfs none /dev

Quoted 7 lines

chcon foobar -R /dev

The second would not be blocked by usernamespace.

Bottom line this patch should be reverted so container runtimes like docker can use both User Namespace and SELinux at the same time.

I doubt we want to revert it entirely. Looks like Smack has an explicit exemption for tmpfs/ramfs (and sysfs, but it wouldn't really make sense to do it there). We could do something similar.

maintainer
#2 lore raw
Quoted 32 lines · Stephen Smalley
Quoted 31 lines · Daniel J Walsh

Currently in SELinux and UserNamespace can not be enabled with Docker/runc at the same time.

Runc mounts tmpfs directories with --context="system_u:object_r:container_file_t:s0:c1,c2" type labels but the following patch blocks the use of context mounts when using user namespace.

http://kernel.suse.com/cgit/kernel/commit/?id=aad82892af261b9903cc11c55be3ecf5f0b0b4f8

User Namespace has to be established before tmpfs are mounted so we are unable to mount a tmpfs with a context=flag and UserNamespace enabled.

Controlling the ability to change the label of a mounted file systemd should be a MAC decision not a DAC, or UserNamespace. Setting the SELinux labels on an object like a file system mount point should be controlled by SELinux. SELinux should check if the label of the process doing the mount is able to relabel from the label of the mount point, and labelto the specified label.

SELinux does this for privileged processes (running with SYS_ADMIN) so use namespace should not be any different. Also the process doing the mount would be allowed by DAC to set the label of the tmpfs after it is mounted (As long as SELinux allowed).

There is no security difference between:

mount -o tmpfs context="foobar" none /dev

And

mount -o tmpfs none /dev

chcon foobar -R /dev

Quoted 8 lines
Quoted 4 lines

The second would not be blocked by usernamespace.

Bottom line this patch should be reverted so container runtimes like docker can use both User Namespace and SELinux at the same time.

I doubt we want to revert it entirely. Looks like Smack has an explicit exemption for tmpfs/ramfs (and sysfs, but it wouldn't really make sense to do it there). We could do something similar.

Yes, I still think the restriction makes sense for persistent filesystems, but for things like tmpfs it does seem silly.

Signature · 2 lines
paul moore
www.paul-moore.com
#3 lore raw
Quoted 38 lines · Paul Moore
Quoted 37 lines · Stephen Smalley
Quoted 35 lines · Daniel J Walsh

Currently in SELinux and UserNamespace can not be enabled with Docker/runc at the same time.

Runc mounts tmpfs directories with --context="system_u:object_r:container_file_t:s0:c1,c2" type labels but the following patch blocks the use of context mounts when using user namespace.

http://kernel.suse.com/cgit/kernel/commit/?id=aad82892af261b9903cc11c55be3ecf5f0b0b4f8

User Namespace has to be established before tmpfs are mounted so we are unable to mount a tmpfs with a context=flag and UserNamespace enabled.

Controlling the ability to change the label of a mounted file systemd should be a MAC decision not a DAC, or UserNamespace. Setting the SELinux labels on an object like a file system mount point should be controlled by SELinux. SELinux should check if the label of the process doing the mount is able to relabel from the label of the mount point, and labelto the specified label.

SELinux does this for privileged processes (running with SYS_ADMIN) so use namespace should not be any different. Also the process doing the mount would be allowed by DAC to set the label of the tmpfs after it is mounted (As long as SELinux allowed).

There is no security difference between:

mount -o tmpfs context="foobar" none /dev

And

mount -o tmpfs none /dev

chcon foobar -R /dev

The second would not be blocked by usernamespace.

Bottom line this patch should be reverted so container runtimes like docker can use both User Namespace and SELinux at the same time.

Quoted 6 lines
Quoted 3 lines

I doubt we want to revert it entirely. Looks like Smack has an explicit exemption for tmpfs/ramfs (and sysfs, but it wouldn't really make sense to do it there). We could do something similar.

Yes, I still think the restriction makes sense for persistent filesystems, but for things like tmpfs it does seem silly.

Looking further at this, the set of filesystems that presently allow userns mounting are mqueue, tmpfs, cgroup/cgroup2, sysfs, ramfs, proc, and devpts. I could see allowing context mounts for mqueue, tmpfs, ramfs, and devpts within the user namespace. For cgroup/cgroup2, sysfs and proc we don't want the process to be able to override the policy-defined labels. Make sense?

#4 lore raw
Quoted 46 lines · Stephen Smalley
Quoted 38 lines · Paul Moore
Quoted 37 lines · Stephen Smalley
Quoted 35 lines · Daniel J Walsh

Currently in SELinux and UserNamespace can not be enabled with Docker/runc at the same time.

Runc mounts tmpfs directories with --context="system_u:object_r:container_file_t:s0:c1,c2" type labels but the following patch blocks the use of context mounts when using user namespace.

http://kernel.suse.com/cgit/kernel/commit/?id=aad82892af261b9903cc11c55be3ecf5f0b0b4f8

User Namespace has to be established before tmpfs are mounted so we are unable to mount a tmpfs with a context=flag and UserNamespace enabled.

Controlling the ability to change the label of a mounted file systemd should be a MAC decision not a DAC, or UserNamespace. Setting the SELinux labels on an object like a file system mount point should be controlled by SELinux. SELinux should check if the label of the process doing the mount is able to relabel from the label of the mount point, and labelto the specified label.

SELinux does this for privileged processes (running with SYS_ADMIN) so use namespace should not be any different. Also the process doing the mount would be allowed by DAC to set the label of the tmpfs after it is mounted (As long as SELinux allowed).

There is no security difference between:

mount -o tmpfs context="foobar" none /dev

And

mount -o tmpfs none /dev

chcon foobar -R /dev

The second would not be blocked by usernamespace.

Bottom line this patch should be reverted so container runtimes like docker can use both User Namespace and SELinux at the same time.

Quoted 6 lines
Quoted 3 lines

I doubt we want to revert it entirely. Looks like Smack has an explicit exemption for tmpfs/ramfs (and sysfs, but it wouldn't really make sense to do it there). We could do something similar.

Yes, I still think the restriction makes sense for persistent filesystems, but for things like tmpfs it does seem silly.

Quoted 6 lines

Looking further at this, the set of filesystems that presently allow userns mounting are mqueue, tmpfs, cgroup/cgroup2, sysfs, ramfs, proc, and devpts. I could see allowing context mounts for mqueue, tmpfs, ramfs, and devpts within the user namespace. For cgroup/cgroup2, sysfs and proc we don't want the process to be able to override the policy-defined labels. Make sense?

Sorry, never mind about mqueue - unless the process is also in its own IPC namespace, that could allow it to effectively relabel existing mqueues. So only tmpfs, ramfs, and devpts seem to be safe in this regard.

#5 lore raw
Quoted 55 lines · Stephen Smalley
Quoted 41 lines · Stephen Smalley
Quoted 40 lines · Paul Moore
Quoted 39 lines · Stephen Smalley
Quoted 28 lines · Daniel J Walsh

Currently in SELinux and UserNamespace can not be enabled with Docker/runc at the same time.

Runc mounts tmpfs directories with --context="system_u:object_r:container_file_t:s0:c1,c2" type labels but the following patch blocks the use of context mounts when using user namespace.

http://kernel.suse.com/cgit/kernel/commit/?id=aad82892af261b9903cc11c55be3ecf5f0b0b4f8

User Namespace has to be established before tmpfs are mounted so we are unable to mount a tmpfs with a context=flag and UserNamespace enabled.

Controlling the ability to change the label of a mounted file systemd should be a MAC decision not a DAC, or UserNamespace. Setting the SELinux labels on an object like a file system mount point should be controlled by SELinux. SELinux should check if the label of the process doing the mount is able to relabel from the label of the mount point, and labelto the specified label.

SELinux does this for privileged processes (running with SYS_ADMIN) so use namespace should not be any different. Also the process doing the mount would be allowed by DAC to set the label of the tmpfs after it is mounted (As long as SELinux allowed).

There is no security difference between:

mount -o tmpfs context="foobar" none /dev

And

mount -o tmpfs none /dev

Quoted 7 lines

chcon foobar -R /dev

The second would not be blocked by usernamespace.

Bottom line this patch should be reverted so container runtimes like docker can use both User Namespace and SELinux at the same time.

I doubt we want to revert it entirely. Looks like Smack has an explicit exemption for tmpfs/ramfs (and sysfs, but it wouldn't really make sense to do it there). We could do something similar.

Quoted 8 lines
Quoted 2 lines

Yes, I still think the restriction makes sense for persistent filesystems, but for things like tmpfs it does seem silly.

Looking further at this, the set of filesystems that presently allow userns mounting are mqueue, tmpfs, cgroup/cgroup2, sysfs, ramfs, proc, and devpts. I could see allowing context mounts for mqueue, tmpfs, ramfs, and devpts within the user namespace. For cgroup/cgroup2, sysfs and proc we don't want the process to be able to override the policy-defined labels. Make sense?

Sorry, never mind about mqueue - unless the process is also in its own IPC namespace, that could allow it to effectively relabel existing mqueues. So only tmpfs, ramfs, and devpts seem to be safe in this regard.

Quoted 7 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

That works for me. The mqueue one we might have to visit later. I think docker and
user namespace with mqueue is currently a problem.