* [PATCH-next] sched: Fix Null pointer derefrence
@ 2021-05-15 16:46 Khaled ROMDHANI
2021-05-15 21:02 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Khaled ROMDHANI @ 2021-05-15 16:46 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, bristot
Cc: Khaled ROMDHANI, linux-kernel, kernel-janitors
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")
Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>
---
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 161b92aa1c79..490948df94fe 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -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;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH-next] sched: Fix Null pointer derefrence 2021-05-15 16:46 [PATCH-next] sched: Fix Null pointer derefrence Khaled ROMDHANI @ 2021-05-15 21:02 ` Peter Zijlstra 2021-05-16 13:01 ` Khaled Romdhani 0 siblings, 1 reply; 4+ messages in thread From: Peter Zijlstra @ 2021-05-15 21:02 UTC (permalink / raw) To: Khaled ROMDHANI Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman, bristot, linux-kernel, kernel-janitors On Sat, May 15, 2021 at 05:46:45PM +0100, Khaled ROMDHANI wrote: > 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? ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH-next] sched: Fix Null pointer derefrence 2021-05-15 21:02 ` Peter Zijlstra @ 2021-05-16 13:01 ` Khaled Romdhani 2021-05-16 15:37 ` Peter Zijlstra 0 siblings, 1 reply; 4+ messages in thread From: Khaled Romdhani @ 2021-05-16 13:01 UTC (permalink / raw) To: Peter Zijlstra Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman, bristot, linux-kernel, kernel-janitors On Sat, May 15, 2021 at 11:02:38PM +0200, Peter Zijlstra wrote: > On Sat, May 15, 2021 at 05:46:45PM +0100, Khaled ROMDHANI wrote: > > 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. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH-next] sched: Fix Null pointer derefrence 2021-05-16 13:01 ` Khaled Romdhani @ 2021-05-16 15:37 ` Peter Zijlstra 0 siblings, 0 replies; 4+ messages in thread From: Peter Zijlstra @ 2021-05-16 15:37 UTC (permalink / raw) To: Khaled Romdhani Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman, bristot, linux-kernel, kernel-janitors On Sun, May 16, 2021 at 02:01:29PM +0100, Khaled Romdhani wrote: > On Sat, May 15, 2021 at 11:02:38PM +0200, Peter Zijlstra wrote: > > On Sat, May 15, 2021 at 05:46:45PM +0100, Khaled ROMDHANI wrote: > > > 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. 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. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-16 15:37 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-05-15 16:46 [PATCH-next] sched: Fix Null pointer derefrence Khaled ROMDHANI 2021-05-15 21:02 ` Peter Zijlstra 2021-05-16 13:01 ` Khaled Romdhani 2021-05-16 15:37 ` Peter Zijlstra
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox