The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH kernel] srcu: Fix static initialization
@ 2020-09-08 14:43 Alexey Kardashevskiy
  2020-09-09  9:24 ` Alexey Kardashevskiy
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Kardashevskiy @ 2020-09-08 14:43 UTC (permalink / raw)
  To: rcu
  Cc: Alexey Kardashevskiy, Paul E. McKenney, Josh Triplett,
	Lai Jiangshan, Mathieu Desnoyers, Steven Rostedt, linux-kernel

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;
+
 	/*
 	 * 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++) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-09-22 22:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-08 14:43 [PATCH kernel] srcu: Fix static initialization Alexey Kardashevskiy
2020-09-09  9:24 ` Alexey Kardashevskiy
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox