lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191029115000.GA11194@google.com>
Date:   Tue, 29 Oct 2019 11:50:00 +0000
From:   Quentin Perret <qperret@...gle.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     linux-kernel@...r.kernel.org, aaron.lwe@...il.com,
        valentin.schneider@....com, mingo@...nel.org, pauld@...hat.com,
        jdesfossez@...italocean.com, naravamudan@...italocean.com,
        vincent.guittot@...aro.org, dietmar.eggemann@....com,
        juri.lelli@...hat.com, rostedt@...dmis.org, bsegall@...gle.com,
        mgorman@...e.de, kernel-team@...roid.com, john.stultz@...aro.org
Subject: Re: NULL pointer dereference in pick_next_task_fair

On Tuesday 29 Oct 2019 at 12:34:11 (+0100), Peter Zijlstra wrote:
> On Mon, Oct 28, 2019 at 05:46:03PM +0000, Quentin Perret wrote:
> > The issue is very transient and relatively hard to reproduce.
> > 
> > After digging a bit, the offending commit seems to be:
> > 
> >     67692435c411 ("sched: Rework pick_next_task() slow-path")
> > 
> > By 'offending' I mean that reverting it makes the issue go away. The
> > issue comes from the fact that pick_next_entity() returns a NULL se in
> > the 'simple' path of pick_next_task_fair(), which causes obvious
> > problems in the subsequent call to set_next_entity().
> > 
> > I'll dig more, but if anybody understands the issue in the meatime feel
> > free to send me a patch to try out :)
> 
> Can you please see if this makes any difference?
> 
> ---
>  kernel/sched/core.c | 6 ++++--
>  kernel/sched/fair.c | 2 +-
>  kernel/sched/idle.c | 3 +--
>  3 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7880f4f64d0e..abd2d4f80381 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3922,8 +3922,10 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
>  			goto restart;
> 
>  		/* Assumes fair_sched_class->next == idle_sched_class */
> -		if (unlikely(!p))
> -			p = idle_sched_class.pick_next_task(rq, prev, rf);
> +		if (unlikely(!p)) {
> +			prev->sched_class->put_prev_task(rq, prev, rf);
> +			p = idle_sched_class.pick_next_task(rq, NULL, NULL);
> +		}
> 
>  		return p;
>  	}
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 83ab35e2374f..2aad94bb7165 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6820,7 +6820,7 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf
>  simple:
>  #endif
>  	if (prev)
> -		put_prev_task(rq, prev);
> +		prev->sched_class->put_prev_task(rq, prev, rf);
> 
>  	do {
>  		se = pick_next_entity(cfs_rq, NULL);
> diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
> index 8dad5aa600ea..e8dfc84f375a 100644
> --- a/kernel/sched/idle.c
> +++ b/kernel/sched/idle.c
> @@ -390,8 +390,7 @@ pick_next_task_idle(struct rq *rq, struct task_struct *prev, struct rq_flags *rf
>  {
>  	struct task_struct *next = rq->idle;
> 
> -	if (prev)
> -		put_prev_task(rq, prev);
> +	WARN_ON_ONCE(prev || rf);
> 
>  	set_next_task_idle(rq, next);
> 
> 

Unfortunately the issue went into hiding this morning and I struggle to
reproduce it (this is turning bordeline nightmare now TBH).

I'll try the patch once my reproducer is fixed :/

Thank you very much for the help,
Quentin

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ