]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched/ext: Avoid null ptr traversal when ->put_prev_task() is called with NULL next
authorJohn Stultz <jstultz@google.com>
Sat, 6 Dec 2025 02:22:03 +0000 (02:22 +0000)
committerTejun Heo <tj@kernel.org>
Mon, 8 Dec 2025 17:18:13 +0000 (07:18 -1000)
Early when trying to get sched_ext and proxy-exe working together,
I kept tripping over NULL ptr in put_prev_task_scx() on the line:
  if (sched_class_above(&ext_sched_class, next->sched_class)) {

Which was due to put_prev_task() passes a NULL next, calling:
  prev->sched_class->put_prev_task(rq, prev, NULL);

put_prev_task_scx() already guards for a NULL next in the
switch_class case, but doesn't seem to have a guard for
sched_class_above() check.

I can't say I understand why this doesn't trip usually without
proxy-exec. And in newer kernels there are way fewer
put_prev_task(), and I can't easily reproduce the issue now
even with proxy-exec.

But we still have one put_prev_task() call left in core.c that
seems like it could trip this, so I wanted to send this out for
consideration.

tj: put_prev_task() can be called with NULL @next; however, when @p is
queued, that doesn't happen, so this condition shouldn't currently be
triggerable. The connection isn't straightforward or necessarily reliable,
so add the NULL check even if it can't currently be triggered.

Link: http://lkml.kernel.org/r/20251206022218.1541878-1-jstultz@google.com
Signed-off-by: John Stultz <jstultz@google.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext.c

index 073b669869cb0d8fdbb8008e6ee9a278e60e35cf..bd74b371f52d95d0bde5ba800f8a45795c59531e 100644 (file)
@@ -2402,7 +2402,7 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
                 * ops.enqueue() that @p is the only one available for this cpu,
                 * which should trigger an explicit follow-up scheduling event.
                 */
-               if (sched_class_above(&ext_sched_class, next->sched_class)) {
+               if (next && sched_class_above(&ext_sched_class, next->sched_class)) {
                        WARN_ON_ONCE(!(sch->ops.flags & SCX_OPS_ENQ_LAST));
                        do_enqueue_task(rq, p, SCX_ENQ_LAST, -1);
                } else {