sched: Fix Null pointer derefrence
Subsystems (2)
The 'curr' variable could be NULL and derefrenced by pick_next_entity. Fix this by adding a check that prevent the invocation of pick_next_entity with a NULL passed argument.
Addresses-Coverity: ("Explicit null dereferenced")
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -7075,7 +7075,7 @@ static struct task_struct *pick_task_fair(struct rq *rq)else curr =NULL ; -if (unlikely (check_cfs_rq_runtime (cfs_rq))) +if (unlikely (check_cfs_rq_runtime (cfs_rq) || !curr)) goto again; }
Signature · 1 line
2.17.1
Peter Zijlstra
maintainerQuoted 3 lines · Khaled ROMDHANI
The 'curr' variable could be NULL and derefrenced by
pick_next_entity. Fix this by adding a check that prevent the invocation ofpick_next_entitywith a NULL passed argument.
And why exactly is that a problem?
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Khaled ROMDHANI
The 'curr' variable could be NULL and derefrenced by
pick_next_entity. Fix this by adding a check that prevent the invocation ofpick_next_entitywith a NULL passed argument.And why exactly is that a problem?
Within pick_next_entity, we could have 'left = curr'. Thus the function wakeup_preempt_entity which is invoked from pick_next_entity, derefrence the the sched entity 'left' that may be a NULL passed argument.
Peter Zijlstra
maintainerQuoted 6 lines · Khaled Romdhani
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Khaled ROMDHANI
The 'curr' variable could be NULL and derefrenced by
pick_next_entity. Fix this by adding a check that prevent the invocation ofpick_next_entitywith a NULL passed argument.
Quoted 6 lines
Quoted 2 lines
And why exactly is that a problem?
Within
pick_next_entity, we could have 'left = curr'. Thus the functionwakeup_preempt_entitywhich is invoked frompick_next_entity, derefrence the the sched entity 'left' that may be a NULL passed argument.
We call pick_next_entity() from pick_task_fair() (or pick_next_task_fair(), same argument for both), we only call it when cfs_rq->nr_running != 0. IOW we *know* there is at least one task.
Therefore, if curr == NULL, we *must* have left.
If you can't read code, stay away from Coverity, it's crap.