[PATCH] sched_ext: Add NULL check in find_parent_sched()

Cui Jian posted 1 patch 1 month, 3 weeks ago
kernel/sched/ext/sub.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] sched_ext: Add NULL check in find_parent_sched()
Posted by Cui Jian 1 month, 3 weeks ago
find_parent_sched() dereferences cgrp->scx_sched without checking
for NULL. This is safe in practice because scx_sched is always
set for cgroups that can reach this function, but add a defensive
check for robustness.

Signed-off-by: Cui Jian <cjian720@163.com>
---
 kernel/sched/ext/sub.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index d7842a609d96..6395281bae71 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -1209,6 +1209,10 @@ static struct scx_sched *find_parent_sched(struct cgroup *cgrp)
 
 	lockdep_assert_held(&scx_sched_lock);
 
+	/* no SCX sched */
+	if (!parent)
+		return ERR_PTR(-ENODEV);
+
 	/* can't attach twice to the same cgroup */
 	if (parent->cgrp == cgrp)
 		return ERR_PTR(-EBUSY);
-- 
2.34.1