Skip to contentSkip to conversation

Why does devices cgroup check for CAP_SYS_ADMIN explicitly?

DISCUSSION Tejun Heo 4 participants 36 messages Nov 6, 2012 11 messages not in the archive cgroup

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

Hello, guys.

Why doesn't it follow the usual security enforced by cgroupfs permissions? Why is the explicit check necessary?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106023845.GI19354-9pTldWuhBndy/[email protected]

#2 lore raw
Quoted 4 lines · Tejun Heo

Hello, guys.

Why doesn't it follow the usual security enforced by cgroupfs permissions? Why is the explicit check necessary?

An almost more interesting question is why is cgroup one of the last pieces of code not using capabilities and instead lets you attach to any process simply if your uid == 0.

I don't know the history but the device cgroup testing for CAP_SYS_ADMIN makes a naive sort of sense to me.

Eric

A message that is not in the archive (sent off-list or not yet received): 877gpzrlir.fsf-aS9lmoZGLiVWk0Htik3J/[email protected]

author
#4 lore raw

Hey, Eric.

Quoted 6 lines · Eric W. Biederman
Quoted 2 lines

Why doesn't it follow the usual security enforced by cgroupfs permissions? Why is the explicit check necessary?

An almost more interesting question is why is cgroup one of the last pieces of code not using capabilities and instead lets you attach to any process simply if your uid == 0.

Because it has a filesystem as interface and most things w/ file system interface depend on VFS for access policies.

Quoted 2 lines

I don't know the history but the device cgroup testing for CAP_SYS_ADMIN makes a naive sort of sense to me.

If some different CAP_* is needed for cgroup (but why?), the right thing to do is enforcing it uniformly from cgroup core instead of doing it from individual controllers. If there's no actual good reason to keep this, I'll write up a patch to remove it.

Thanks.

Signature · 1 line
tejun
author
#5 lore raw
In reply to a message not in the archive

Hey, Eric.

Quoted 6 lines · Eric W. Biederman
Quoted 2 lines

Why doesn't it follow the usual security enforced by cgroupfs permissions? Why is the explicit check necessary?

An almost more interesting question is why is cgroup one of the last pieces of code not using capabilities and instead lets you attach to any process simply if your uid == 0.

Because it has a filesystem as interface and most things w/ file system interface depend on VFS for access policies.

Quoted 2 lines

I don't know the history but the device cgroup testing for CAP_SYS_ADMIN makes a naive sort of sense to me.

If some different CAP_* is needed for cgroup (but why?), the right thing to do is enforcing it uniformly from cgroup core instead of doing it from individual controllers. If there's no actual good reason to keep this, I'll write up a patch to remove it.

Thanks.

Signature · 1 line
tejun
#6 lore raw
In reply to a message not in the archive
Quoted 7 lines · Eric W. Biederman
Quoted 4 lines · Tejun Heo

Hello, guys.

Why doesn't it follow the usual security enforced by cgroupfs permissions? Why is the explicit check necessary?

Quoted 6 lines

An almost more interesting question is why is cgroup one of the last pieces of code not using capabilities and instead lets you attach to any process simply if your uid == 0.

I don't know the history but the device cgroup testing for CAP_SYS_ADMIN makes a naive sort of sense to me.

Right, it's possible to run a daemon with uid 0 but restricted capabilities (enforced by bounding set) for all its children, but not possible to run a non-uid-0 daemon with some capabilities across execs. (Of course that can be worked around with privileged helpers or to an extent inherited capabilities.) Capabilities make sense for the cgroup controls.

In other words, any code which equates uid 0 with posession of a capability is taking away from the usefulness of capabilities everywhere.

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

-serge

author
#7 lore raw

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

So, you don't really have any actual use case for the explicit CAP_* checks, right?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106150639.GB30069-9pTldWuhBndy/[email protected]

#9 lore raw
Quoted 10 lines · Tejun Heo

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Quoted 3 lines

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

I don't know if those who restrict CAP_SYS_ADMIN do so or not. We by default do not.

(It's not relevant for this discussion as again we use apparmor to deny writes, but we *do* optionally bind mount cgroups into the containers, mounting /sys/fs/cgroup/$cgroup/lxc/$containername/$containername.real on the host to /sys/fs/cgroup/$cgroup in the container for each cgroup.)

Quoted 2 lines

So, you don't really have any actual use case for the explicit CAP_* checks, right?

No, especially since we will now have user namespaces.

We will want to be able to strictly enforce hierarchical limits - i.e. allow uid 100000 (which is uid 0 in the container) to change cgroup settings, but never exceed limits set on the parent directory. IIUC you are working toward anyway with the general hierarchy work? (thanks for that).

-serge

author
#10 lore raw

Hello,

Quoted 10 lines · Serge Hallyn
Quoted 2 lines

So, you don't really have any actual use case for the explicit CAP_* checks, right?

No, especially since we will now have user namespaces.

We will want to be able to strictly enforce hierarchical limits - i.e. allow uid 100000 (which is uid 0 in the container) to change cgroup settings, but never exceed limits set on the parent directory. IIUC you are working toward anyway with the general hierarchy work? (thanks for that).

Yeah, I'm working toward that but I'm not sure it would mean that containers would be able to directly bind mount cgroupfs subdirectory and have free reign on it. Maybe such thing can be made to work but I would be much more comfortable having something inbetween for impedance matching (in access policies, root cgroup behavior matching, whatnot). So, the functionality will be there but it probably would need something inbetween if you wanna give containers control over its own cgroup hierarchy.

There are some issues tho. As it currently stands, devices cgroup inherits configuration rather than enforcing hierarchy while checking for access permission. This means that changes in an ancestor have to be propagated downwards and *update* configurations of descendants, which is what I'm working on but it can be confusing for someone inside the container. Without breaking compatibility, I don't see any other way out tho. I suppose it's something we'll have to live with.

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106154105.GD30069-9pTldWuhBndy/[email protected]

#12 lore raw
Quoted 21 lines · Tejun Heo
Quoted 10 lines · Serge Hallyn
Quoted 2 lines

So, you don't really have any actual use case for the explicit CAP_* checks, right?

No, especially since we will now have user namespaces.

We will want to be able to strictly enforce hierarchical limits - i.e. allow uid 100000 (which is uid 0 in the container) to change cgroup settings, but never exceed limits set on the parent directory. IIUC you are working toward anyway with the general hierarchy work? (thanks for that).

Yeah, I'm working toward that but I'm not sure it would mean that containers would be able to directly bind mount cgroupfs subdirectory and have free reign on it. Maybe such thing can be made to work but I would be much more comfortable having something inbetween for impedance matching (in access policies, root cgroup behavior matching, whatnot). So, the functionality will be there but it probably would need something inbetween if you wanna give containers control over its own cgroup hierarchy.

Quoted 7 lines

There are some issues tho. As it currently stands, devices cgroup inherits configuration rather than enforcing hierarchy while checking for access permission. This means that changes in an ancestor have to be propagated downwards and *update* configurations of descendants, which is what I'm working on but it can be confusing for someone inside the container. Without breaking compatibility, I don't see any other way out tho. I suppose it's something we'll have to live with.

yes, but most of the changes will happen before the containers start. I've been working in a patchset (as promised) and it propagates down the changes and also keep 'local' rules. everytime a parent change something, the local rules are re-evaluated and reapplied if they're still valid.

Signature · 1 line
Aristeu
#13 lore raw
In reply to a message not in the archive
Quoted 21 lines · Tejun Heo
Quoted 10 lines · Serge Hallyn
Quoted 2 lines

So, you don't really have any actual use case for the explicit CAP_* checks, right?

No, especially since we will now have user namespaces.

We will want to be able to strictly enforce hierarchical limits - i.e. allow uid 100000 (which is uid 0 in the container) to change cgroup settings, but never exceed limits set on the parent directory. IIUC you are working toward anyway with the general hierarchy work? (thanks for that).

Yeah, I'm working toward that but I'm not sure it would mean that containers would be able to directly bind mount cgroupfs subdirectory and have free reign on it. Maybe such thing can be made to work but I would be much more comfortable having something inbetween for impedance matching (in access policies, root cgroup behavior matching, whatnot). So, the functionality will be there but it probably would need something inbetween if you wanna give containers control over its own cgroup hierarchy.

Quoted 7 lines

There are some issues tho. As it currently stands, devices cgroup inherits configuration rather than enforcing hierarchy while checking for access permission. This means that changes in an ancestor have to be propagated downwards and *update* configurations of descendants, which is what I'm working on but it can be confusing for someone inside the container. Without breaking compatibility, I don't see any other way out tho. I suppose it's something we'll have to live with.

yes, but most of the changes will happen before the containers start. I've been working in a patchset (as promised) and it propagates down the changes and also keep 'local' rules. everytime a parent change something, the local rules are re-evaluated and reapplied if they're still valid.

Signature · 1 line
Aristeu
author
#14 lore raw
In reply to Serge Hallyn

Hello,

Quoted 10 lines · Serge Hallyn
Quoted 2 lines

So, you don't really have any actual use case for the explicit CAP_* checks, right?

No, especially since we will now have user namespaces.

We will want to be able to strictly enforce hierarchical limits - i.e. allow uid 100000 (which is uid 0 in the container) to change cgroup settings, but never exceed limits set on the parent directory. IIUC you are working toward anyway with the general hierarchy work? (thanks for that).

Yeah, I'm working toward that but I'm not sure it would mean that containers would be able to directly bind mount cgroupfs subdirectory and have free reign on it. Maybe such thing can be made to work but I would be much more comfortable having something inbetween for impedance matching (in access policies, root cgroup behavior matching, whatnot). So, the functionality will be there but it probably would need something inbetween if you wanna give containers control over its own cgroup hierarchy.

There are some issues tho. As it currently stands, devices cgroup inherits configuration rather than enforcing hierarchy while checking for access permission. This means that changes in an ancestor have to be propagated downwards and *update* configurations of descendants, which is what I'm working on but it can be confusing for someone inside the container. Without breaking compatibility, I don't see any other way out tho. I suppose it's something we'll have to live with.

Thanks.

Signature · 1 line
tejun
#15 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tejun Heo

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Quoted 3 lines

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

I don't know if those who restrict CAP_SYS_ADMIN do so or not. We by default do not.

(It's not relevant for this discussion as again we use apparmor to deny writes, but we *do* optionally bind mount cgroups into the containers, mounting /sys/fs/cgroup/$cgroup/lxc/$containername/$containername.real on the host to /sys/fs/cgroup/$cgroup in the container for each cgroup.)

Quoted 2 lines

So, you don't really have any actual use case for the explicit CAP_* checks, right?

No, especially since we will now have user namespaces.

We will want to be able to strictly enforce hierarchical limits - i.e. allow uid 100000 (which is uid 0 in the container) to change cgroup settings, but never exceed limits set on the parent directory. IIUC you are working toward anyway with the general hierarchy work? (thanks for that).

-serge

#16 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tejun Heo

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Quoted 6 lines

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

So, you don't really have any actual use case for the explicit CAP_* checks, right?

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

update_access can allow access to previously unaccessible devices and so is equivalent to mknod and as such requires a capability call.

static int devcgroup_update_access(struct dev_cgroup *devcgroup,
int filetype, const char *buffer)
{
....

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

Likewise move to a different cgroup can give you a completely different set of devices you can use. And is roughly equivalent to mknod, and needs a capability call.

static int devcgroup_can_attach(struct cgroup *new_cgrp,
struct cgroup_taskset *set)

{
	struct task_struct *task = cgroup_taskset_first(set);

	if (current != task && !capable(CAP_SYS_ADMIN))
		return -EPERM;

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;

Eric

A message that is not in the archive (sent off-list or not yet received): 871ug6rbio.fsf-aS9lmoZGLiVWk0Htik3J/[email protected]

author
#18 lore raw

Hey, Eric.

Quoted 10 lines · Eric W. Biederman

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

You understand that the whole thing is gated by VFS permission check, right? I'm kinda lost what you're talking about.

Quoted 5 lines

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

Quoted 16 lines
{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;

This one isn't gated by VFS so we need to add CAP check to this function. No?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106154320.GE30069-9pTldWuhBndy/[email protected]

#20 lore raw
Quoted 10 lines · Tejun Heo

Hey, Eric.

Quoted 7 lines · Eric W. Biederman

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Quoted 6 lines
Quoted 3 lines

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

You understand that the whole thing is gated by VFS permission check, right? I'm kinda lost what you're talking about.

mknod is gated by the vfs with a capability call.

open does not perform the CAP_MKNOD check.

Since the device cgroup prevents opening of device nodes adding permission to access a new device node (update_access) is roughly equivalent to mknod when the device cgroup does not exist.

To preserve the notion that only a privileged user can grant access to device nodes we need a capability check. Especially since the device cgroup is designed to limit processes with uid == 0.

Without a capability check a process with CAP_DAC_OVERRIDE can go shopping for a device control group that happens to have the device it wants to use.

Similary without a capability check a process with CAP_DAD_OVERRIDE can add or remove any device node into a device control group.

I don't see how the device control group can limit uid == 0 with the device control group without making the operations require a capability you don't give to ever user who has uid == 0.

Quoted 22 lines
Quoted 5 lines

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

Quoted 16 lines
{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;
Quoted 2 lines

This one isn't gated by VFS so we need to add CAP check to this function. No?

correct. The check should read something like:

tcred = __task_cred(tsk);
if (!uid_eq(cred->euid, tcred->uid) &&
!uid_eq(cred->euid, tcred->suid) &&

                    !capable(CAP_SYS_ADMIN)) {

rcu_read_unlock();
ret = -EACCES;
goto out_unlock_cgroup;

Eric

A message that is not in the archive (sent off-list or not yet received): 87sj8mogpp.fsf-aS9lmoZGLiVWk0Htik3J/[email protected]

author
#22 lore raw

Hello, Eric.

Quoted 7 lines · Eric W. Biederman

mknod is gated by the vfs with a capability call.

open does not perform the CAP_MKNOD check.

Since the device cgroup prevents opening of device nodes adding permission to access a new device node (update_access) is roughly equivalent to mknod when the device cgroup does not exist.

I think that's a jump.

Quoted 8 lines

To preserve the notion that only a privileged user can grant access to device nodes we need a capability check. Especially since the device cgroup is designed to limit processes with uid == 0.

Without a capability check a process with CAP_DAC_OVERRIDE can go shopping for a device control group that happens to have the device it wants to use.

Quoted 6 lines

Similary without a capability check a process with CAP_DAD_OVERRIDE can add or remove any device node into a device control group.

I don't see how the device control group can limit uid == 0 with the device control group without making the operations require a capability you don't give to ever user who has uid == 0.

devices cgroup adds to restrictions what a group of tasks can do. Access to cgroup configuration is gated by cgroup core (currently by VFS permissions) and that's it. I really don't want each controller to develop its own permission checks. If a controller can't live with that, it probably shouldn't be a cgroup controller. So, if you think the CAP check is needed for cgroup in general (and can justify it), please feel free to move it to cgroup core; otherwise, the CAP check is going away from devices and if devices can't live with that, it probably shouldn't have been a cgroup controller from the beginning.

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106165246.GF30069-9pTldWuhBndy/[email protected]

#24 lore raw
Quoted 28 lines · Tejun Heo

Hello, Eric.

Quoted 7 lines · Eric W. Biederman

mknod is gated by the vfs with a capability call.

open does not perform the CAP_MKNOD check.

Since the device cgroup prevents opening of device nodes adding permission to access a new device node (update_access) is roughly equivalent to mknod when the device cgroup does not exist.

I think that's a jump.

Quoted 8 lines

To preserve the notion that only a privileged user can grant access to device nodes we need a capability check. Especially since the device cgroup is designed to limit processes with uid == 0.

Without a capability check a process with CAP_DAC_OVERRIDE can go shopping for a device control group that happens to have the device it wants to use.

Quoted 6 lines

Similary without a capability check a process with CAP_DAD_OVERRIDE can add or remove any device node into a device control group.

I don't see how the device control group can limit uid == 0 with the device control group without making the operations require a capability you don't give to ever user who has uid == 0.

Quoted 9 lines

devices cgroup adds to restrictions what a group of tasks can do. Access to cgroup configuration is gated by cgroup core (currently by VFS permissions) and that's it. I really don't want each controller to develop its own permission checks. If a controller can't live with that, it probably shouldn't be a cgroup controller. So, if you think the CAP check is needed for cgroup in general (and can justify it), please feel free to move it to cgroup core; otherwise, the CAP check is going away from devices and if devices can't live with that, it probably shouldn't have been a cgroup controller from the beginning.

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

-serge

author
#25 lore raw

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106173823.GK30069-9pTldWuhBndy/[email protected]

author
#27 lore raw

Just one more thing.

Quoted 7 lines · Tejun Heo

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Quoted 5 lines

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

As for using cgroup as !root user, I would advise not doing that. Again, we're moving toward a unified cgroup hierarchy. You wouldn't be creating multiple cgroup hierarchies and assigning different user accesses to them. Also, I would strongly discourage chowning sub directories in cgroupfs and letting non-priviledged users modify them directly.

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106174130.GL30069-9pTldWuhBndy/[email protected]

#29 lore raw
Quoted 16 lines · Tejun Heo

Just one more thing.

Quoted 7 lines · Tejun Heo

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Quoted 5 lines

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Quoted 6 lines

As for using cgroup as !root user, I would advise not doing that. Again, we're moving toward a unified cgroup hierarchy. You wouldn't be creating multiple cgroup hierarchies and assigning different user accesses to them. Also, I would strongly discourage chowning sub directories in cgroupfs and letting non-priviledged users modify them directly.

So to be clear, if I want a user to be able to confine his own compute-intensive tasks and freeze them, the recommended route will be with privileged (setuid-root) helpers?

-serge

author
#30 lore raw

Hello, Serge.

Quoted 3 lines · Serge Hallyn

So to be clear, if I want a user to be able to confine his own compute-intensive tasks and freeze them, the recommended route will be with privileged (setuid-root) helpers?

Something like that. I think we'll eventually need a policy manager in userland which controls the whole hierarchy. Not sure how that will look at this point tho, but cgroupfs will be an interface to just expose cgroup configuration directly rather than allow multiplexing userland / namespace / whatnot multiplexing on top of it.

Thanks.

Signature · 1 line
tejun
author
#31 lore raw
In reply to Serge Hallyn

Hello, Serge.

Quoted 3 lines · Serge Hallyn

So to be clear, if I want a user to be able to confine his own compute-intensive tasks and freeze them, the recommended route will be with privileged (setuid-root) helpers?

Something like that. I think we'll eventually need a policy manager in userland which controls the whole hierarchy. Not sure how that will look at this point tho, but cgroupfs will be an interface to just expose cgroup configuration directly rather than allow multiplexing userland / namespace / whatnot multiplexing on top of it.

Thanks.

Signature · 1 line
tejun
#32 lore raw
In reply to a message not in the archive
Quoted 16 lines · Tejun Heo

Just one more thing.

Quoted 7 lines · Tejun Heo

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Quoted 5 lines

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Quoted 6 lines

As for using cgroup as !root user, I would advise not doing that. Again, we're moving toward a unified cgroup hierarchy. You wouldn't be creating multiple cgroup hierarchies and assigning different user accesses to them. Also, I would strongly discourage chowning sub directories in cgroupfs and letting non-priviledged users modify them directly.

So to be clear, if I want a user to be able to confine his own compute-intensive tasks and freeze them, the recommended route will be with privileged (setuid-root) helpers?

-serge

#33 lore raw
In reply to a message not in the archive
Quoted 9 lines · Tejun Heo

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related

That would be the next step, yes.

Quoted 3 lines

controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Why meaningless? Many caps needed to "do everything", but moving a task into the freezer and freezing it, or reducing its allowed memory, would only requiring uid equiv or some limited bit of privilege.

Quoted 4 lines

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

That's the question :)

I feel like we need a list of the various uses people have in mind, so we can figure out which ones are supportable... but I know there is the whole long thread I've not had time to keep up with, and many answers are probably there.

-serge

author
#34 lore raw

Hello, Serge.

Quoted 10 lines · Serge Hallyn
Quoted 7 lines · Tejun Heo
Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related

That would be the next step, yes.

Hmmm... I don't know. What does that buy us? Fine grained CAP_* is to be able to give away privliedges in smaller pieces, right? If we're gonna be requiring root to modify cgroup, what difference does it make to have finer grained CAPs specified?

Quoted 8 lines
Quoted 3 lines

controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Why meaningless? Many caps needed to "do everything", but moving a task into the freezer and freezing it, or reducing its allowed memory, would only requiring uid equiv or some limited bit of privilege.

All controllers will be co-mounted and you'll need all CAPs needed by all controllers to move tasks between cgroups and there won't be an easy way to tell which CAP is missing. Doesn't sound too useful to me.

Quoted 11 lines
Quoted 4 lines

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

That's the question :)

I feel like we need a list of the various uses people have in mind, so we can figure out which ones are supportable... but I know there is the whole long thread I've not had time to keep up with, and many answers are probably there.

Care to give a pointer?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20121106181623.GO30069-9pTldWuhBndy/[email protected]

#36 lore raw
Quoted 23 lines · Tejun Heo

Hello, Serge.

Quoted 10 lines · Serge Hallyn
Quoted 7 lines · Tejun Heo
Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related

That would be the next step, yes.

Hmmm... I don't know. What does that buy us? Fine grained CAP_* is to be able to give away privliedges in smaller pieces, right? If we're gonna be requiring root to modify cgroup, what difference does it make to have finer grained CAPs specified?

Quoted 4 lines
Quoted 3 lines

controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Quoted 6 lines
Quoted 4 lines

Why meaningless? Many caps needed to "do everything", but moving a task into the freezer and freezing it, or reducing its allowed memory, would only requiring uid equiv or some limited bit of privilege.

All controllers will be co-mounted and you'll need all CAPs needed by

Oh. I thought each controller could only be mounted once, but not that all must be co-mounted.

Jinkeys.

Quoted 9 lines

all controllers to move tasks between cgroups and there won't be an easy way to tell which CAP is missing. Doesn't sound too useful to me.

Quoted 5 lines
Quoted 4 lines

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

Quoted 8 lines
Quoted 6 lines

That's the question :)

I feel like we need a list of the various uses people have in mind, so we can figure out which ones are supportable... but I know there is the whole long thread I've not had time to keep up with, and many answers are probably there.

Care to give a pointer?

I mean the recent thread you started on cgroup cleanups :)

-serge

author
#37 lore raw
In reply to Serge Hallyn

Hello, Serge.

Quoted 10 lines · Serge Hallyn
Quoted 7 lines · Tejun Heo
Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related

That would be the next step, yes.

Hmmm... I don't know. What does that buy us? Fine grained CAP_* is to be able to give away privliedges in smaller pieces, right? If we're gonna be requiring root to modify cgroup, what difference does it make to have finer grained CAPs specified?

Quoted 8 lines
Quoted 3 lines

controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Why meaningless? Many caps needed to "do everything", but moving a task into the freezer and freezing it, or reducing its allowed memory, would only requiring uid equiv or some limited bit of privilege.

All controllers will be co-mounted and you'll need all CAPs needed by all controllers to move tasks between cgroups and there won't be an easy way to tell which CAP is missing. Doesn't sound too useful to me.

Quoted 11 lines
Quoted 4 lines

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

That's the question :)

I feel like we need a list of the various uses people have in mind, so we can figure out which ones are supportable... but I know there is the whole long thread I've not had time to keep up with, and many answers are probably there.

Care to give a pointer?

Thanks.

Signature · 1 line
tejun
#38 lore raw
In reply to a message not in the archive
Quoted 9 lines · Tejun Heo

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related

That would be the next step, yes.

Quoted 3 lines

controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

Why meaningless? Many caps needed to "do everything", but moving a task into the freezer and freezing it, or reducing its allowed memory, would only requiring uid equiv or some limited bit of privilege.

Quoted 4 lines

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

That's the question :)

I feel like we need a list of the various uses people have in mind, so we can figure out which ones are supportable... but I know there is the whole long thread I've not had time to keep up with, and many answers are probably there.

-serge

author
#39 lore raw
In reply to Serge Hallyn

Hello,

Quoted 3 lines · Serge Hallyn

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

Sure, then just live with the cgroupfs based permission check. What next? Should we add CAP_SYS_RESOURCE check to all resource related controllers? Moreover, We're headed to unified hierarchy, so in the end that means only the user with almost all CAP_* can manipulate cgroups at all making the whole thing meaningless.

I don't think applying fine-grained CAP_* to cgroup controllers makes sense or would be useful in any real sense. We can introduce, say, CAP_CGROUP to control access cgroupfs but I think we already have enough access control to cgroupfs, don't we?

Thanks.

Signature · 1 line
tejun
#40 lore raw
In reply to a message not in the archive
Quoted 28 lines · Tejun Heo

Hello, Eric.

Quoted 7 lines · Eric W. Biederman

mknod is gated by the vfs with a capability call.

open does not perform the CAP_MKNOD check.

Since the device cgroup prevents opening of device nodes adding permission to access a new device node (update_access) is roughly equivalent to mknod when the device cgroup does not exist.

I think that's a jump.

Quoted 8 lines

To preserve the notion that only a privileged user can grant access to device nodes we need a capability check. Especially since the device cgroup is designed to limit processes with uid == 0.

Without a capability check a process with CAP_DAC_OVERRIDE can go shopping for a device control group that happens to have the device it wants to use.

Quoted 6 lines

Similary without a capability check a process with CAP_DAD_OVERRIDE can add or remove any device node into a device control group.

I don't see how the device control group can limit uid == 0 with the device control group without making the operations require a capability you don't give to ever user who has uid == 0.

Quoted 9 lines

devices cgroup adds to restrictions what a group of tasks can do. Access to cgroup configuration is gated by cgroup core (currently by VFS permissions) and that's it. I really don't want each controller to develop its own permission checks. If a controller can't live with that, it probably shouldn't be a cgroup controller. So, if you think the CAP check is needed for cgroup in general (and can justify it), please feel free to move it to cgroup core; otherwise, the CAP check is going away from devices and if devices can't live with that, it probably shouldn't have been a cgroup controller from the beginning.

We can't generally require a capability to move tasks between cgroups, as that will break currently intended uses. I can create two cgroups, chown them to serge, and let serge move between them.

-serge

#41 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tejun Heo

Hey, Eric.

Quoted 7 lines · Eric W. Biederman

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Quoted 6 lines
Quoted 3 lines

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

You understand that the whole thing is gated by VFS permission check, right? I'm kinda lost what you're talking about.

mknod is gated by the vfs with a capability call.

open does not perform the CAP_MKNOD check.

Since the device cgroup prevents opening of device nodes adding permission to access a new device node (update_access) is roughly equivalent to mknod when the device cgroup does not exist.

To preserve the notion that only a privileged user can grant access to device nodes we need a capability check. Especially since the device cgroup is designed to limit processes with uid == 0.

Without a capability check a process with CAP_DAC_OVERRIDE can go shopping for a device control group that happens to have the device it wants to use.

Similary without a capability check a process with CAP_DAD_OVERRIDE can add or remove any device node into a device control group.

I don't see how the device control group can limit uid == 0 with the device control group without making the operations require a capability you don't give to ever user who has uid == 0.

Quoted 22 lines
Quoted 5 lines

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

Quoted 16 lines
{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;
Quoted 2 lines

This one isn't gated by VFS so we need to add CAP check to this function. No?

correct. The check should read something like:

tcred = __task_cred(tsk);
if (!uid_eq(cred->euid, tcred->uid) &&
!uid_eq(cred->euid, tcred->suid) &&

                    !capable(CAP_SYS_ADMIN)) {

rcu_read_unlock();
ret = -EACCES;
goto out_unlock_cgroup;

Eric

#42 lore raw
In reply to a message not in the archive
Quoted 76 lines · Eric W. Biederman
Quoted 10 lines · Tejun Heo

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Quoted 6 lines

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

So, you don't really have any actual use case for the explicit CAP_* checks, right?

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

update_access can allow access to previously unaccessible devices and so is equivalent to mknod and as such requires a capability call.

static int devcgroup_update_access(struct dev_cgroup *devcgroup,
int filetype, const char *buffer)
{
....

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

Likewise move to a different cgroup can give you a completely different set of devices you can use. And is roughly equivalent to mknod, and needs a capability call.

static int devcgroup_can_attach(struct cgroup *new_cgrp,
struct cgroup_taskset *set)

{
	struct task_struct *task = cgroup_taskset_first(set);

	if (current != task && !capable(CAP_SYS_ADMIN))
		return -EPERM;

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;
Quoted 1 line

Eric

(full context kept, though long, bc it's all important)

Note that part of the problem is simply that the devices cgroup is serving as a stand-in for the lack of both user and device namespaces. If those both existed, we could get rid of the devices cgroup. Likewise, the presence of the devices cgroup makes a device namespace far less compelling :) We can play games with bind mounts into /dev and devcgroup to do most of what we want a devicens for.

-serge

#43 lore raw
In reply to a message not in the archive
Quoted 76 lines · Eric W. Biederman
Quoted 10 lines · Tejun Heo

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Quoted 6 lines

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

So, you don't really have any actual use case for the explicit CAP_* checks, right?

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

update_access can allow access to previously unaccessible devices and so is equivalent to mknod and as such requires a capability call.

static int devcgroup_update_access(struct dev_cgroup *devcgroup,
int filetype, const char *buffer)
{
....

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

Likewise move to a different cgroup can give you a completely different set of devices you can use. And is roughly equivalent to mknod, and needs a capability call.

static int devcgroup_can_attach(struct cgroup *new_cgrp,
struct cgroup_taskset *set)

{
	struct task_struct *task = cgroup_taskset_first(set);

	if (current != task && !capable(CAP_SYS_ADMIN))
		return -EPERM;

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;
Quoted 1 line

Eric

(full context kept, though long, bc it's all important)

Note that part of the problem is simply that the devices cgroup is serving as a stand-in for the lack of both user and device namespaces. If those both existed, we could get rid of the devices cgroup. Likewise, the presence of the devices cgroup makes a device namespace far less compelling :) We can play games with bind mounts into /dev and devcgroup to do most of what we want a devicens for.

-serge

#44 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tejun Heo

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Quoted 6 lines

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

So, you don't really have any actual use case for the explicit CAP_* checks, right?

Having thought about this a little more I can give a definitive answer.

Adding a process to the device control group is equivalent to calling mknod, as it allows that process to open device nodes, or equivalently not open device nodes. Therefore a capable check is absolutely required.

Without a capability check it would be possible to remove access to /dev/console for a suid root application keeping it from reporting attempts to hack it for example.

update_access can allow access to previously unaccessible devices and so is equivalent to mknod and as such requires a capability call.

static int devcgroup_update_access(struct dev_cgroup *devcgroup,
int filetype, const char *buffer)
{
....

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

Likewise move to a different cgroup can give you a completely different set of devices you can use. And is roughly equivalent to mknod, and needs a capability call.

static int devcgroup_can_attach(struct cgroup *new_cgrp,
struct cgroup_taskset *set)

{
	struct task_struct *task = cgroup_taskset_first(set);

	if (current != task && !capable(CAP_SYS_ADMIN))
		return -EPERM;

The generic cgroup check in attach_task_by_pid to see if you can move another process into a cgroup needs to be a capability call and not a test for uid == 0.

static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)

{
	if (pid) {
		tsk = find_task_by_vpid(pid);

		/*
		 * even if we're attaching all tasks in the thread group, we
		 * only need to check permissions on one of them.
		 */
		tcred = __task_cred(tsk);
		if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
                                        ^^^^^^^^^^^^^^^
		    !uid_eq(cred->euid, tcred->uid) &&
		    !uid_eq(cred->euid, tcred->suid)) {
			rcu_read_unlock();
			ret = -EACCES;
			goto out_unlock_cgroup;

Eric

author
#45 lore raw
In reply to Serge Hallyn

Hello, Serge.

Quoted 6 lines · Serge Hallyn

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

Do you even mount cgroupfs in containers? If you just bind-mount cgroupfs verbatim in containers, I don't think that's gonna work very well. If not, all this doesn't make any difference for containers.

So, you don't really have any actual use case for the explicit CAP_* checks, right?

Thanks.

Signature · 1 line
tejun
#46 lore raw
In reply to a message not in the archive
Quoted 7 lines · Eric W. Biederman
Quoted 4 lines · Tejun Heo

Hello, guys.

Why doesn't it follow the usual security enforced by cgroupfs permissions? Why is the explicit check necessary?

Quoted 6 lines

An almost more interesting question is why is cgroup one of the last pieces of code not using capabilities and instead lets you attach to any process simply if your uid == 0.

I don't know the history but the device cgroup testing for CAP_SYS_ADMIN makes a naive sort of sense to me.

Right, it's possible to run a daemon with uid 0 but restricted capabilities (enforced by bounding set) for all its children, but not possible to run a non-uid-0 daemon with some capabilities across execs. (Of course that can be worked around with privileged helpers or to an extent inherited capabilities.) Capabilities make sense for the cgroup controls.

In other words, any code which equates uid 0 with posession of a capability is taking away from the usefulness of capabilities everywhere.

More practically, lacking user namespaces you can create a full (i.e. ubuntu) container that doesn't have CAP_SYS_ADMIN, but not one without root. So this allows you to prevent containers from bypassing devices cgroup restrictions set by the parent. (In reality we are not using that in ubuntu - we grant CAP_SYS_ADMIN and use apparmor to restrict - but other distros do.)

-serge