Skip to content

Commit eb4c238

Browse files
Dennis KreinPaul E. McKenney
authored andcommitted
srcu: Lock srcu_data structure in srcu_gp_start()
The srcu_gp_start() function is called with the srcu_struct structure's ->lock held, but not with the srcu_data structure's ->lock. This is problematic because this function accesses and updates the srcu_data structure's ->srcu_cblist, which is protected by that lock. Failing to hold this lock can result in corruption of the SRCU callback lists, which in turn can result in arbitrarily bad results. This commit therefore makes srcu_gp_start() acquire the srcu_data structure's ->lock across the calls to rcu_segcblist_advance() and rcu_segcblist_accelerate(), thus preventing this corruption. Reported-by: Bart Van Assche <bvanassche@acm.org> Reported-by: Christoph Hellwig <hch@infradead.org> Reported-by: Sebastian Kuzminsky <seb.kuzminsky@gmail.com> Signed-off-by: Dennis Krein <Dennis.Krein@netapp.com> Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com> Tested-by: Dennis Krein <Dennis.Krein@netapp.com> Cc: <stable@vger.kernel.org> # 4.16.x
1 parent 0607ba8 commit eb4c238

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎kernel/rcu/srcutree.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,12 @@ static void srcu_gp_start(struct srcu_struct *sp)
451451

452452
lockdep_assert_held(&ACCESS_PRIVATE(sp, lock));
453453
WARN_ON_ONCE(ULONG_CMP_GE(sp->srcu_gp_seq, sp->srcu_gp_seq_needed));
454+
spin_lock_rcu_node(sdp); /* Interrupts already disabled. */
454455
rcu_segcblist_advance(&sdp->srcu_cblist,
455456
rcu_seq_current(&sp->srcu_gp_seq));
456457
(void)rcu_segcblist_accelerate(&sdp->srcu_cblist,
457458
rcu_seq_snap(&sp->srcu_gp_seq));
459+
spin_unlock_rcu_node(sdp); /* Interrupts remain disabled. */
458460
smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
459461
rcu_seq_start(&sp->srcu_gp_seq);
460462
state = rcu_seq_state(READ_ONCE(sp->srcu_gp_seq));

0 commit comments

Comments
 (0)