diff mbox series

[bionic,2/2] srcu: Lock srcu_data structure in srcu_gp_start()

Message ID 20190220232838.16778-3-marcelo.cerri@canonical.com
State New
Headers show
Series srcu: Lock srcu_data structure in srcu_gp_start() | expand

Commit Message

Marcelo Henrique Cerri Feb. 20, 2019, 11:28 p.m. UTC
From: Dennis Krein <Dennis.Krein@netapp.com>

BugLink: http://bugs.launchpad.net/bugs/1802021

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
(cherry picked from commit eb4c2382272ae7ae5d81fdfa5b7a6c86146eaaa4)
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
---
 kernel/rcu/srcutree.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Stefan Bader Feb. 27, 2019, 9:38 a.m. UTC | #1
On 21.02.19 00:28, Marcelo Henrique Cerri wrote:
> From: Dennis Krein <Dennis.Krein@netapp.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1802021
> 
> 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
> (cherry picked from commit eb4c2382272ae7ae5d81fdfa5b7a6c86146eaaa4)
> Acked-by: Stefan Bader <stefan.bader@canonical.com>
> Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
> Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
> ---

Cannot remember having acked this yet...

>  kernel/rcu/srcutree.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index d5cea81378cc..b3e5e9873582 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -441,10 +441,12 @@ static void srcu_gp_start(struct srcu_struct *sp)
>  
>  	lockdep_assert_held(&sp->lock);
>  	WARN_ON_ONCE(ULONG_CMP_GE(sp->srcu_gp_seq, sp->srcu_gp_seq_needed));
> +	spin_lock_rcu_node(sdp);  /* Interrupts already disabled. */
>  	rcu_segcblist_advance(&sdp->srcu_cblist,
>  			      rcu_seq_current(&sp->srcu_gp_seq));
>  	(void)rcu_segcblist_accelerate(&sdp->srcu_cblist,
>  				       rcu_seq_snap(&sp->srcu_gp_seq));
> +	spin_unlock_rcu_node(sdp);  /* Interrupts remain disabled. */
>  	smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
>  	rcu_seq_start(&sp->srcu_gp_seq);
>  	state = rcu_seq_state(READ_ONCE(sp->srcu_gp_seq));
>
Marcelo Henrique Cerri Feb. 27, 2019, 11:21 p.m. UTC | #2
My mistake. I used the patches that went into linux-azure to prepare it.

I will update it and re-submit it first thing in the morning.

On Wed, Feb 27, 2019 at 10:38:23AM +0100, Stefan Bader wrote:
> On 21.02.19 00:28, Marcelo Henrique Cerri wrote:
> > From: Dennis Krein <Dennis.Krein@netapp.com>
> > 
> > BugLink: http://bugs.launchpad.net/bugs/1802021
> > 
> > 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
> > (cherry picked from commit eb4c2382272ae7ae5d81fdfa5b7a6c86146eaaa4)
> > Acked-by: Stefan Bader <stefan.bader@canonical.com>
> > Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
> > Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
> > ---
> 
> Cannot remember having acked this yet...
> 
> >  kernel/rcu/srcutree.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> > index d5cea81378cc..b3e5e9873582 100644
> > --- a/kernel/rcu/srcutree.c
> > +++ b/kernel/rcu/srcutree.c
> > @@ -441,10 +441,12 @@ static void srcu_gp_start(struct srcu_struct *sp)
> >  
> >  	lockdep_assert_held(&sp->lock);
> >  	WARN_ON_ONCE(ULONG_CMP_GE(sp->srcu_gp_seq, sp->srcu_gp_seq_needed));
> > +	spin_lock_rcu_node(sdp);  /* Interrupts already disabled. */
> >  	rcu_segcblist_advance(&sdp->srcu_cblist,
> >  			      rcu_seq_current(&sp->srcu_gp_seq));
> >  	(void)rcu_segcblist_accelerate(&sdp->srcu_cblist,
> >  				       rcu_seq_snap(&sp->srcu_gp_seq));
> > +	spin_unlock_rcu_node(sdp);  /* Interrupts remain disabled. */
> >  	smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
> >  	rcu_seq_start(&sp->srcu_gp_seq);
> >  	state = rcu_seq_state(READ_ONCE(sp->srcu_gp_seq));
> > 
> 
>
Joshua R. Poulson Feb. 28, 2019, 1 a.m. UTC | #3
I did submit this one in
https://bugs.launchpad.net/ubuntu/+source/linux-azure/+bug/1802021 for
an Azure customer that was having an issue. This patch addressed their
problem, but later in that same bug was another user who was
experiencing issues that was looking for the same fix in the generic
kernels.

Thanks, --jrp

On Wed, Feb 27, 2019 at 3:22 PM Marcelo Henrique Cerri
<marcelo.cerri@canonical.com> wrote:
>
> My mistake. I used the patches that went into linux-azure to prepare it.
>
> I will update it and re-submit it first thing in the morning.
>
> On Wed, Feb 27, 2019 at 10:38:23AM +0100, Stefan Bader wrote:
> > On 21.02.19 00:28, Marcelo Henrique Cerri wrote:
> > > From: Dennis Krein <Dennis.Krein@netapp.com>
> > >
> > > BugLink: http://bugs.launchpad.net/bugs/1802021
> > >
> > > 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
> > > (cherry picked from commit eb4c2382272ae7ae5d81fdfa5b7a6c86146eaaa4)
> > > Acked-by: Stefan Bader <stefan.bader@canonical.com>
> > > Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
> > > Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
> > > ---
> >
> > Cannot remember having acked this yet...
> >
> > >  kernel/rcu/srcutree.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> > > index d5cea81378cc..b3e5e9873582 100644
> > > --- a/kernel/rcu/srcutree.c
> > > +++ b/kernel/rcu/srcutree.c
> > > @@ -441,10 +441,12 @@ static void srcu_gp_start(struct srcu_struct *sp)
> > >
> > >     lockdep_assert_held(&sp->lock);
> > >     WARN_ON_ONCE(ULONG_CMP_GE(sp->srcu_gp_seq, sp->srcu_gp_seq_needed));
> > > +   spin_lock_rcu_node(sdp);  /* Interrupts already disabled. */
> > >     rcu_segcblist_advance(&sdp->srcu_cblist,
> > >                           rcu_seq_current(&sp->srcu_gp_seq));
> > >     (void)rcu_segcblist_accelerate(&sdp->srcu_cblist,
> > >                                    rcu_seq_snap(&sp->srcu_gp_seq));
> > > +   spin_unlock_rcu_node(sdp);  /* Interrupts remain disabled. */
> > >     smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
> > >     rcu_seq_start(&sp->srcu_gp_seq);
> > >     state = rcu_seq_state(READ_ONCE(sp->srcu_gp_seq));
> > >
> >
> >
>
>
>
>
> --
> Regards,
> Marcelo
>
> --
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
diff mbox series

Patch

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index d5cea81378cc..b3e5e9873582 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -441,10 +441,12 @@  static void srcu_gp_start(struct srcu_struct *sp)
 
 	lockdep_assert_held(&sp->lock);
 	WARN_ON_ONCE(ULONG_CMP_GE(sp->srcu_gp_seq, sp->srcu_gp_seq_needed));
+	spin_lock_rcu_node(sdp);  /* Interrupts already disabled. */
 	rcu_segcblist_advance(&sdp->srcu_cblist,
 			      rcu_seq_current(&sp->srcu_gp_seq));
 	(void)rcu_segcblist_accelerate(&sdp->srcu_cblist,
 				       rcu_seq_snap(&sp->srcu_gp_seq));
+	spin_unlock_rcu_node(sdp);  /* Interrupts remain disabled. */
 	smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
 	rcu_seq_start(&sp->srcu_gp_seq);
 	state = rcu_seq_state(READ_ONCE(sp->srcu_gp_seq));