Skip to contentSkip to conversation

sched: Fix Null pointer derefrence

PATCH-next Khaled ROMDHANI 2 participants 4 messages May 15, 2021 – May 16, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 161b92aa1c79..490948df94fe 100644
@@ -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
maintainer
#1 lore raw
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 of pick_next_entity with a NULL passed argument.

And why exactly is that a problem?

#2 lore raw
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 of pick_next_entity with 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.

maintainer
#3 lore raw
Quoted 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 of pick_next_entity with 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 function wakeup_preempt_entity which is invoked from pick_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.