sched/fair: Add null pointer check to pick_next_entity()
A message that is not in the archive (sent off-list or not yet received): [email protected]
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 inpick_next_entity()The other call site of
pick_eevdf()can already handle a null pointer, andpick_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
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
-0if (se->sched_delayed) {dequeue_entities (rq, se,DEQUEUE_SLEEP |DEQUEUE_DELAYED );/*