The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: rcu@vger.kernel.org
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH kernel] srcu: Fix static initialization
Date: Wed, 9 Sep 2020 19:24:11 +1000	[thread overview]
Message-ID: <cc25257d-804e-8cf7-150b-e6bdbaf184be@ozlabs.ru> (raw)
In-Reply-To: <20200908144306.33355-1-aik@ozlabs.ru>



On 09/09/2020 00:43, Alexey Kardashevskiy wrote:
> init_srcu_struct_nodes() is called with is_static==true only internally
> and when this happens, the srcu->sda is not initialized in
> init_srcu_struct_fields() and we crash on dereferencing @sdp.
> 
> This fixes the crash by moving "if (is_static)" out of the loop which
> only does useful work for is_static=false case anyway.
> 
> Found by syzkaller.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
>  kernel/rcu/srcutree.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index c100acf332ed..49b54a50bde8 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -135,6 +135,9 @@ static void init_srcu_struct_nodes(struct srcu_struct *ssp, bool is_static)
>  				   levelspread[level - 1];
>  	}
>  
> +	if (is_static)
> +		return;

Actually, this is needed here too:

 if (!ssp->sda)
         return;

as
ssp->sda = alloc_percpu(struct srcu_data)

can fail if the process is killed too soon - it is quite easy to get
this situation with syzkaller (syscalls fuzzer)

Makes sense?


> +
>  	/*
>  	 * Initialize the per-CPU srcu_data array, which feeds into the
>  	 * leaves of the srcu_node tree.
> @@ -161,8 +164,6 @@ static void init_srcu_struct_nodes(struct srcu_struct *ssp, bool is_static)
>  		timer_setup(&sdp->delay_work, srcu_delay_timer, 0);
>  		sdp->ssp = ssp;
>  		sdp->grpmask = 1 << (cpu - sdp->mynode->grplo);
> -		if (is_static)
> -			continue;
>  
>  		/* Dynamically allocated, better be no srcu_read_locks()! */
>  		for (i = 0; i < ARRAY_SIZE(sdp->srcu_lock_count); i++) {
> 

-- 
Alexey

  reply	other threads:[~2020-09-09  9:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 14:43 [PATCH kernel] srcu: Fix static initialization Alexey Kardashevskiy
2020-09-09  9:24 ` Alexey Kardashevskiy [this message]
2020-09-09 11:50   ` Paul E. McKenney
2020-09-09 12:31     ` Alexey Kardashevskiy
2020-09-10 18:53       ` Paul E. McKenney
2020-09-11  5:09         ` Alexey Kardashevskiy
2020-09-11 13:52           ` Paul E. McKenney
2020-09-16 16:12             ` Paul E. McKenney
2020-09-22  0:41               ` Alexey Kardashevskiy
2020-09-22 22:00                 ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc25257d-804e-8cf7-150b-e6bdbaf184be@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox