Skip to contentSkip to conversation

sched/fair: Add null pointer check to pick_next_entity()

PATCH Steven Rostedt 1 participant 1 message Mar 24, 2025 1 message not in the archive

lore
Share & tools
lore

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

#1 lore raw
Quoted 6 lines · On Thu, 20 Mar 2025 10:34:39 -0700 Pat Cody <[email protected]> wrote:

pick_eevdf() can return null, resulting in a null pointer dereference crash in pick_next_entity()

The other call site of pick_eevdf() can already handle a null pointer, and pick_next_entity() can already return null as well. Add an extra check to handle the null return here.

Have you actually triggered this?

Quoted 3 lines
Fixes f12e148892ed ("sched/fair: Prepare pick_next_task() for delayed dequeue")

No signed-off-by.

Quoted 9 lines
---
 kernel/sched/fair.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/fair.c +0 -0
index a553181dc764..f2157298cbce 100644

kernel/sched/fair.c pick_next_entity(struct rq *rq, struct cfs_rq *cfs_rq) · line 5564

Quoted 5 lines
kernel/sched/fair.c +2 -0
@@ -5560,6 +5560,8 @@ pick_next_entity(struct rq *rq, struct cfs_rq *cfs_rq)
 	}
 
 	struct sched_entity *se = pick_eevdf(cfs_rq);
+	if (!se)
+		return NULL;

So the place that this is called is in pick_task_fair() which has:

	cfs_rq = &rq->cfs;
	if (!cfs_rq->nr_queued)
		return NULL;

Where I believe it's a bug if cfs_rq->nr_queued > 0 and pick_eevdf() returns NULL.

Which means in should never happen. Now, to be more robust, we could add a check for NULL, but this is not a fix, nor should it go to stable.

-- Steve

Quoted 3 lines
kernel/sched/fair.c +0 -0
 	if (se->sched_delayed) {
 		dequeue_entities(rq, se, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
 		/*