Skip to contentSkip to conversation

cgroup/cpuset: Creating or adding CPUs to partition not allowed without privilege

PATCH In review Waiman Long 3 participants 7 messages Apr 28 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Waiman Long

author maintainer
#0 lore raw

PATCH 1/1 cgroup/cpuset: Creating or adding CPUs to partition not allowed without privilege

Creation of a cpuset partition or adding more CPUs to an existing partition will take CPUs away from other cpusets outside of the partition leaving less CPUs for the others. So it is a privileged operation that non-privileged users shouldn't be allowed to do.

Currently, remote partition code has check for CAP_SYS_ADMIN capability before allowing such operations, but not for local partition. This leaves a security hole in case cpuset.cpus.partition of a cpuset is chown'ed to a non-root user and its parent cpuset happens to be a partition root.

Add such privilege check for local partition too to close such a hole. Also update Documentation/admin-guide/cgroup-v2.rst to clarify the intention.

With this patch applied, any attempt to enable partition or add CPUs to an existing local or remote partition by an unprivileged user will invalidate the partition even if writing to cpuset control files are allowed.

Fixes ee8dde0cd2ce ("cpuset: Add new v2 cpuset.sched.partition flag")
---
 Documentation/admin-guide/cgroup-v2.rst |  6 ++++--
 kernel/cgroup/cpuset.c                  | 16 +++++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +4 -2
index 6efd0095ed99..df58557902db 100644
@@ -2599,8 +2599,10 @@ Cpuset Interface Files
 
   cpuset.cpus.partition
 	A read-write single value file which exists on non-root
-	cpuset-enabled cgroups.  This flag is owned by the parent cgroup
-	and is not delegatable.
+	cpuset-enabled cgroups. This file is owned by the parent cgroup
+	and is not delegatable. Any partition operations that take CPUs
+	away from other cpusets outside of a partition is not allowed
+	without privilege.
 
 	It accepts only the following input values when written to.
 
kernel/cgroup/cpuset.c +13 -3
index e3a081a07c6d..5fc8555f2046 100644
@@ -57,7 +57,7 @@ static const char * const perr_strings[] = {
 	[PERR_HOTPLUG]   = "No cpu available due to hotplug",
 	[PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are empty",
 	[PERR_HKEEPING]  = "partition config conflicts with housekeeping setup",
-	[PERR_ACCESS]    = "Enable partition not permitted",
+	[PERR_ACCESS]    = "Partition operation not permitted",
 	[PERR_REMOTE]    = "Have remote partition underneath",
 };
 
@@ -1740,6 +1740,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
 	nocpu = tasks_nocpu_error(parent, cs, xcpus);
 
 	if ((cmd == partcmd_enable) || (cmd == partcmd_enablei)) {
+		if (!capable(CAP_SYS_ADMIN))
+			return PERR_ACCESS;
 		/*
 		 * Need to call compute_excpus() in case
 		 * exclusive_cpus not set. Sibling conflict should only happen
@@ -1833,12 +1835,18 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
 					       parent->effective_xcpus);
 		}
 
+		/*
+		 * Taking CPUs away from parent is not allowed without privilege
+		 */
+		if (deleting && !capable(CAP_SYS_ADMIN))
+			part_error = PERR_ACCESS;
+
 		/*
 		 * TBD: Invalidate a currently valid child root partition may
 		 * still break isolated_cpus_can_update() rule if parent is an
 		 * isolated partition.
 		 */
-		if (is_partition_valid(cs) && (old_prs != parent_prs)) {
+		else if (is_partition_valid(cs) && (old_prs != parent_prs)) {
 			if ((parent_prs == PRS_ROOT) &&
 			    /* Adding to parent means removing isolated CPUs */
 			    !isolated_cpus_can_update(tmp->delmask, tmp->addmask))
@@ -1919,8 +1927,10 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
 	}
 
 write_error:
-	if (part_error)
+	if (part_error) {
 		WRITE_ONCE(cs->prs_err, part_error);
+		adding = deleting = false;
+	}
 
 	if (cmd == partcmd_update) {
 		/*
Signature · 1 line
2.53.0
maintainer
#1 lore raw

Hi Waiman.

Quoted 7 lines · Waiman Long

Creation of a cpuset partition or adding more CPUs to an existing partition will take CPUs away from other cpusets outside of the partition leaving less CPUs for the others. So it is a privileged operation that non-privileged users shouldn't be allowed to do.

Currently, remote partition code has check for CAP_SYS_ADMIN capability before allowing such operations, but not for local partition.

Remote partitions need such a check because their CPUs are sourced from the global supply (top level) without

Quoted 3 lines

This leaves a security hole in case cpuset.cpus.partition of a cpuset is chown'ed to a non-root user and its parent cpuset happens to be a partition root.

I wouldn't say this difference between remote and local partitions is a security hole [1].

Consider this -- cgroup a is created by root (admin) and its resources are constrained by root's policy. However, what happens in a subtree is irrelevant from that top level view.

# setup // owner
a/cpuset.partition=root // root
a/cpuset.cpus=0-3 // root
a/cgroup.procs // user, they can organize subtree as needed

For example the user may want to create a (sub)partition with some of the CPUs they got:

user$ mkdir a/b

a/b/cpuset.partition=root // user
a/b/cpuset.cpus=0-1 // user

This should be a valid configuration and behavior, no?

Thanks,
Michal

[1] And thanks to the need of cpuset.cpus.exclusive chain down the tree, the capability check for remote partitions may be too restrictive too. But I don't not plead for its removal now.

author maintainer
#2 lore raw
Quoted 10 lines · Michal Koutný

Hi Waiman.

Quoted 7 lines · Waiman Long

Creation of a cpuset partition or adding more CPUs to an existing partition will take CPUs away from other cpusets outside of the partition leaving less CPUs for the others. So it is a privileged operation that non-privileged users shouldn't be allowed to do.

Currently, remote partition code has check for CAP_SYS_ADMIN capability before allowing such operations, but not for local partition.

Quoted 8 lines

Remote partitions need such a check because their CPUs are sourced from the global supply (top level) without

Quoted 3 lines

This leaves a security hole in case cpuset.cpus.partition of a cpuset is chown'ed to a non-root user and its parent cpuset happens to be a partition root.

I wouldn't say this difference between remote and local partitions is a security hole [1].

OK, I will tone down the description.

Quoted 13 lines

Consider this -- cgroup a is created by root (admin) and its resources are constrained by root's policy. However, what happens in a subtree is irrelevant from that top level view.

# setup // owner
a/cpuset.partition=root // root
a/cpuset.cpus=0-3 // root
a/cgroup.procs // user, they can organize subtree as needed

For example the user may want to create a (sub)partition with some of the CPUs they got:

Quoted 6 lines

user$ mkdir a/b

a/b/cpuset.partition=root // user
a/b/cpuset.cpus=0-1 // user

This should be a valid configuration and behavior, no?

Thank for the comment. Yes, that can be a valid configuration.

One possible workaround may be to see if the current user has write access to its parent partition root. If so, we can allow it to create a sub-partition, if not, we will forbid it.

Cheers,
Longman

maintainer
#3 lore raw

Hello,

On Tue, Apr 28, 2026 at 11:19:16AM -0400, Waiman Long wrote:
...

Quoted 5 lines

Thank for the comment. Yes, that can be a valid configuration.

One possible workaround may be to see if the current user has write access to its parent partition root. If so, we can allow it to create a sub-partition, if not, we will forbid it.

I think this whole thing is a confusion. First of all, resource knobs in any given cgroup is owned by the parent. Delegations where the perm to a resource knob is given to delegatee is not supported and expected to affect resource distribution w.r.t. its siblings. Partition isn't special in this regard. memory.low or min can create similar effects. Maybe I'm missing something but I don't see anything happening that's not supposed to happen.

Thanks.

Signature · 1 line
tejun
author maintainer
#4 lore raw
Quoted 9 lines · Tejun Heo

Hello,

On Tue, Apr 28, 2026 at 11:19:16AM -0400, Waiman Long wrote:
...

Quoted 5 lines

Thank for the comment. Yes, that can be a valid configuration.

One possible workaround may be to see if the current user has write access to its parent partition root. If so, we can allow it to create a sub-partition, if not, we will forbid it.

Quoted 6 lines

I think this whole thing is a confusion. First of all, resource knobs in any given cgroup is owned by the parent. Delegations where the perm to a resource knob is given to delegatee is not supported and expected to affect resource distribution w.r.t. its siblings. Partition isn't special in this regard. memory.low or min can create similar effects. Maybe I'm missing something but I don't see anything happening that's not supposed to happen.

You are right. I am a bit confused about the exact delegation rules. After reading the delegation section of the cgroup-v2.rst file, I realize that the current behavior should be OK. For clarity, I am planning to send a documentation patch to clarify the current partition delegation behavior.

Thanks,
Longman

author maintainer
#5 lore raw
In reply to Waiman Long
Quoted 35 lines · Waiman Long
Quoted 10 lines · Michal Koutný

Hi Waiman.

Quoted 7 lines · Waiman Long

Creation of a cpuset partition or adding more CPUs to an existing partition will take CPUs away from other cpusets outside of the partition leaving less CPUs for the others. So it is a privileged operation that non-privileged users shouldn't be allowed to do.

Currently, remote partition code has check for CAP_SYS_ADMIN capability before allowing such operations, but not for local partition.

Quoted 8 lines

Remote partitions need such a check because their CPUs are sourced from the global supply (top level) without

Quoted 3 lines

This leaves a security hole in case cpuset.cpus.partition of a cpuset is chown'ed to a non-root user and its parent cpuset happens to be a partition root.

I wouldn't say this difference between remote and local partitions is a security hole [1].

OK, I will tone down the description.

Quoted 15 lines

Consider this -- cgroup a is created by root (admin) and its resources are constrained by root's policy. However, what happens in a subtree is irrelevant from that top level view.

# setup            // owner
a/cpuset.partition=root    // root
a/cpuset.cpus=0-3    // root
a/cgroup.procs        // user, they can organize subtree as needed

For example the user may want to create a (sub)partition with some of the CPUs they got:

user$ mkdir a/b

Quoted 8 lines
Quoted 4 lines

a/b/cpuset.partition=root    // user
a/b/cpuset.cpus=0-1        // user

This should be a valid configuration and behavior, no?

Thank for the comment. Yes, that can be a valid configuration.

One possible workaround may be to see if the current user has write access to its parent partition root. If so, we can allow it to create a sub-partition, if not, we will forbid it.

It is not that simple to check if the user can write to its parent. So I will put it down as a TODO item, but will still forbid such a configuration for now.

Cheers,
Longman

A message that is not in the archive (sent off-list or not yet received): [email protected]

author maintainer
#7 lore raw
Quoted 36 lines · On 4/28/26 12:03 AM, [email protected] wrote:

Sashiko AI review found 2 potential issue(s):
- [High] Unconditionally clearing adding and deleting flags on partition error permanently leaks CPUs from the parent.
- [High] Unprivileged users can bypass the new CAP_SYS_ADMIN checks and steal CPUs from the parent cpuset by exploiting auto-promotion during hierarchical updates. --

commit 1214158b7ede4552eb3f704b911775642a66d632
Author: Waiman Long <[email protected]>

cgroup/cpuset: Creating or adding CPUs to partition not allowed without privilege

This commit restricts creating cpuset partitions or adding CPUs to an existing local partition to privileged users with CAP_SYS_ADMIN.

Quoted 4 lines
kernel/cgroup/cpuset.c +0 -0
index e3a081a07c6d..5fc8555f2046 100644

[ ... ]

kernel/cgroup/cpuset.c static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, · line 1843

Quoted 10 lines
kernel/cgroup/cpuset.c +6 -0
@@ -1833,12 +1835,18 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
  					       parent->effective_xcpus);
  		}
 
+		/*
+		 * Taking CPUs away from parent is not allowed without privilege
+		 */
+		if (deleting && !capable(CAP_SYS_ADMIN))
+			part_error = PERR_ACCESS;
+

Is it possible for unprivileged users to bypass this check?

If part_error is set to PERR_ACCESS during partcmd_update, the function transitions the partition to invalid but still returns 0 to the caller. This means the unauthorized CPU mask is saved to cs->cpus_allowed and cs->effective_xcpus.

Quoted 7 lines

Later, if a privileged user modifies the parent's cpuset or a CPU hotplug event occurs, update_cpumasks_hier() is triggered and calls update_parent_effective_cpumask() with newmask == NULL.

Since there is no capable(CAP_SYS_ADMIN) check in the newmask == NULL path, and the update runs under a privileged context, won't the system auto-promote the partition and officially steal the unauthorized CPUs from the parent?

It is a good point. Auto-promotion should be disabled if the current error code is PERR_ACCESS.

Quoted 18 lines

[ ... ]

kernel/cgroup/cpuset.c static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, · line 1933

Quoted 9 lines
kernel/cgroup/cpuset.c +3 -1
@@ -1919,8 +1927,10 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
  	}
 
  write_error:
-	if (part_error)
+	if (part_error) {
  		WRITE_ONCE(cs->prs_err, part_error);
+		adding = deleting = false;
+	}

Does clearing the adding flag here leak CPUs from the parent?

When a valid partition becomes invalid due to an error, such as PERR_NOCPUS or the new PERR_ACCESS, it must return its exclusively held CPUs to the parent's effective_cpus.

Quoted 7 lines

The pre-patch code computed the rollback mask in tmp->addmask and left adding = true so that partition_xcpus_del() would be called later.

By unconditionally clearing the adding flag here, the partition transitions to an invalid state, but the required partition_xcpus_del() call is skipped. Are these CPUs permanently leaked from the parent cpuset and the system's scheduling domains?

Right the clearing should be done in the same place where PERR_ACCESS error is set.

Regards,
LOngman

Quoted 1 line