Skip to contentSkip to conversation

sched_ext: Remove redundant css_put()

PATCH Applied Cheng-Yang Chou 3 participants 4 messages Mar 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover sched_ext: Remove redundant css_put()

I noticed a redundant css_put() call in the error path of scx_cgroup_init() within ext.c.

According to the cgroup documentation, css_put() should only be used to release a reference obtained via css_get() or css_tryget_online().

The current iteration uses css_for_each_descendant_pre(), which walks the cgroup hierarchy under cgroup_lock(). This iterator does not implicitly acquire a reference on the yielded css structures.

Since there is no preceding css_get() or css_tryget_online() within the loop, calling css_put() when ops.cgroup_init() fails appears to cause a refcount underflow. This could potentially lead to a Use-After-Free (UAF) vulnerability.

I have tested this patch by building the kernel with make -j and CONFIG_EXT_GROUP_SCHED enabled. However, I do not have specific data or a reproducer to test if this error path triggers in a live environment.

Could anyone clarify if this css_put() is indeed an unbalanced refcount drop, or did I miss a reference acquisition somewhere? I have attached a patch that removes the unbalanced call.

Thanks,
Cheng-Yang

---

Cheng-Yang Chou (1):
sched/ext: Remove redundant css_put()

 kernel/sched/ext.c | 1 -
 1 file changed, 1 deletion(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/1 sched/ext: Remove redundant css_put()

The iterator css_for_each_descendant_pre() walks the cgroup hierarchy under cgroup_lock(). It does not increment the reference counts on yielded css structs.

According to the cgroup documentation, css_put() should only be used to release a reference obtained via css_get() or css_tryget_online(). Since the iterator does not use either of these to acquire a reference, calling css_put() in the error path of scx_cgroup_init() causes a refcount underflow.

Remove the unbalanced css_put() to prevent a potential Use-After-Free (UAF) vulnerability.

---
 kernel/sched/ext.c | 1 -
 1 file changed, 1 deletion(-)
kernel/sched/ext.c +0 -1
index 2ba69b302368..eab6e09b6442 100644
@@ -3589,7 +3589,6 @@ static int scx_cgroup_init(struct scx_sched *sch)
 		ret = SCX_CALL_OP_RET(sch, SCX_KF_UNLOCKED, cgroup_init, NULL,
 				      css->cgroup, &args);
 		if (ret) {
-			css_put(css);
 			scx_error(sch, "ops.cgroup_init() failed (%d)", ret);
 			return ret;
 		}
Signature · 1 line
2.48.1
reviewer Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH 1/1] sched/ext: Remove redundant css_put()

Quoted 10 lines · Cheng-Yang Chou

The iterator css_for_each_descendant_pre() walks the cgroup hierarchy under cgroup_lock(). It does not increment the reference counts on yielded css structs.

According to the cgroup documentation, css_put() should only be used to release a reference obtained via css_get() or css_tryget_online(). Since the iterator does not use either of these to acquire a reference, calling css_put() in the error path of scx_cgroup_init() causes a refcount underflow.

Quoted 4 lines

Remove the unbalanced css_put() to prevent a potential Use-After-Free (UAF) vulnerability.

Looks like a valid fix to me, we're holding cgroup_lock(), so we don't need css_get() and this css_put() should be removed.

Thanks,
-Andrea

Quoted 19 lines
---
 kernel/sched/ext.c | 1 -
 1 file changed, 1 deletion(-)
kernel/sched/ext.c +0 -1
index 2ba69b302368..eab6e09b6442 100644
@@ -3589,7 +3589,6 @@ static int scx_cgroup_init(struct scx_sched *sch)
 		ret = SCX_CALL_OP_RET(sch, SCX_KF_UNLOCKED, cgroup_init, NULL,
 				      css->cgroup, &args);
 		if (ret) {
-			css_put(css);
 			scx_error(sch, "ops.cgroup_init() failed (%d)", ret);
 			return ret;
 		}
Signature · 1 line
2.48.1
reviewer Applied
#3 lore raw

Re: [PATCH 1/1] sched/ext: Remove redundant css_put()

In reply to Cheng-Yang Chou

Applied to sched_ext/for-7.0-fixes with the following updates:

- Subject updated to "sched_ext: Remove redundant css_put() in scx_cgroup_init()"
- Added Fixes and Cc stable tags

Thanks.

--
tejun