public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
	paulmck@linux.vnet.ibm.com, Ingo Molnar <mingo@elte.hu>,
	Vegard Nossum <vegard.nossum@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: kmemcheck caught read from freed memory (cfq_free_io_context)
Date: Wed, 02 Apr 2008 14:26:02 +0200	[thread overview]
Message-ID: <1207139162.8514.806.camel@twins> (raw)
In-Reply-To: <20080402115337.GD12774@kernel.dk>

On Wed, 2008-04-02 at 13:53 +0200, Jens Axboe wrote:
> On Wed, Apr 02 2008, Peter Zijlstra wrote:
> > On Wed, 2008-04-02 at 13:42 +0200, Jens Axboe wrote:
> > > On Wed, Apr 02 2008, Peter Zijlstra wrote:
> > > > On Wed, 2008-04-02 at 13:32 +0200, Jens Axboe wrote:
> > > > > On Wed, Apr 02 2008, Peter Zijlstra wrote:
> > > > > > On Wed, 2008-04-02 at 13:14 +0200, Jens Axboe wrote:
> > > > > > > On Wed, Apr 02 2008, Peter Zijlstra wrote:
> > > > > > > > On Wed, 2008-04-02 at 13:07 +0200, Jens Axboe wrote:
> > > > > > > > > On Wed, Apr 02 2008, Pekka Enberg wrote:
> > > > > > > > > > Hi Paul,
> > > > > > > > > > 
> > > > > > > > > > On Wed, Apr 2, 2008 at 1:55 PM, Paul E. McKenney
> > > > > > > > > > <paulmck@linux.vnet.ibm.com> wrote:
> > > > > > > > > > >  I will check this when I get back to some bandwidth -- but in the meantime,
> > > > > > > > > > >  does kmemcheck special-case SLAB_DESTROY_BY_RCU?  It is legal to access
> > > > > > > > > > >  newly-freed items in that case, as long as you did rcu_read_lock()
> > > > > > > > > > >  before gaining a reference to them and don't hold the reference past
> > > > > > > > > > >  the matching rcu_read_unlock().
> > > > > > > > > > 
> > > > > > > > > > No, kmemcheck is work in progress and does not know about
> > > > > > > > > > SLAB_DESTROY_BY_RCU yet. The reason I asked Vegard to post the warning
> > > > > > > > > > was because Peter, Vegard, and myself identified this particular
> > > > > > > > > > warning as a real problem. But yeah, kmemcheck can cause false
> > > > > > > > > > positives for RCU for now.
> > > > > > > > > 
> > > > > > > > > Makes sense, and to me Pauls analysis of the code looks totally correct
> > > > > > > > > - there's no bug there, at least related to hlist traversal and
> > > > > > > > > kmem_cache_free(), since we are under rcu_read_lock() and thus hold off
> > > > > > > > > the grace for freeing.
> > > > > > > > 
> > > > > > > > but what holds off the slab allocator re-issueing that same object and
> > > > > > > > someone else writing other stuff into it?
> > > > > > > 
> > > > > > > Nothing, that's how rcu destry works here. But for the validation to be
> > > > > > > WRONG radix_tree_lookup(..., old_key) must return cic for new_key, not
> > > > > > > NULL.
> > > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 	A				B			C
> > > > > > 
> > > > > > cfq_cic_lookup(cfqd_1, ioc)
> > > > > > 
> > > > > >   rcu_read_lock()
> > > > > >   cic = radix_tree_lookup(, cfqd_q);
> > > > > > 
> > > > > > 					cfq_cic_free()
> > > > > >   					
> > > > > > 								cfq_cic_link(cfqd_2, ioc,)
> > > > > > 
> > > > > >   rcu_read_unlock()
> > > > > > 
> > > > > > 
> > > > > > and now we have that:
> > > > > > 
> > > > > >   cic->key == cfqd_2
> > > > > > 
> > > > > > 
> > > > > > I'm not seeing anything stopping this from happening.
> > > > > 
> > > > > I don't follow your A-B-C here, what do they refer to?
> > > > 
> > > > A does a radix_tree_lookup() of cfqd_1 (darn typos)
> > > > B does a kfree of the same cic found by A
> > > > C does an alloc and gets the same cic as freed by B and inserts it
> > > >   in a different location.
> > > > 
> > > > So that when we return to A, cic->key == cfqd_2 even though we did a
> > > > lookup for cfqd_1.
> > > 
> > > That I follow, my question was if A, B, and C refer to different
> > > processes but with a shared io context? I'm assuming that is correct...
> > 
> > Ah, yeah, whatever is needed to make this race happen :-)
> 
> The only place where you'll have multiple processes involved with this
> at all is if they share io contexts. That is also why the bug isn't that
> critical, since it's not possible right now (CLONE_IO flag must be
> used).

There are 3 races here:

 1) A continues with another object than intended
    (requires CLONE_IO)

 2) A does hlist_for_each_rcu() and races with B,C so that
    we continue the iteration on a possibly unrelated list.

 3) cic is freed after the !cic->key check.

I'm not familiar enough with the code yet to see if 3 really is an
possibility. But from what I can see there is nothing guarding its
existence.


  parent reply	other threads:[~2008-04-02 12:26 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-01 21:08 kmemcheck caught read from freed memory (cfq_free_io_context) Vegard Nossum
2008-04-01 21:36 ` Peter Zijlstra
2008-04-01 22:51   ` Paul E. McKenney
2008-04-02  6:15     ` Peter Zijlstra
2008-04-02  7:19       ` Jens Axboe
2008-04-02 10:24       ` Paul E. McKenney
2008-04-02  7:17   ` Jens Axboe
2008-04-02  7:20     ` Pekka J Enberg
2008-04-02  7:24       ` Jens Axboe
2008-04-02  7:28         ` Ingo Molnar
2008-04-02  7:31           ` Jens Axboe
2008-04-02 10:55           ` Paul E. McKenney
2008-04-02 10:59             ` Peter Zijlstra
2008-04-02 11:33               ` Fabio Checconi
2008-04-02 11:43                 ` Jens Axboe
2008-04-02 12:36                   ` Jens Axboe
2008-04-02 12:36                     ` Jens Axboe
2008-04-02 12:55                       ` Fabio Checconi
2008-04-02 12:58                         ` Jens Axboe
2008-04-02 12:58                           ` Jens Axboe
2008-04-02 13:16                             ` Fabio Checconi
2008-04-02 16:14                               ` Paul E. McKenney
2008-04-02 13:37                           ` Paul E. McKenney
2008-04-02 13:41                             ` Jens Axboe
2008-04-02 15:33                               ` Paul E. McKenney
2008-04-02 16:31                                 ` Jens Axboe
2008-04-02 17:00                                   ` Paul E. McKenney
2008-04-02 13:32                 ` Paul E. McKenney
2008-04-02 13:40                   ` Jens Axboe
2008-04-02 16:15                     ` Paul E. McKenney
2008-04-02 11:01             ` Pekka Enberg
2008-04-02 11:07               ` Jens Axboe
2008-04-02 11:08                 ` Peter Zijlstra
2008-04-02 11:11                   ` Pekka Enberg
2008-04-02 11:14                     ` Peter Zijlstra
2008-04-02 11:18                       ` Pekka Enberg
2008-04-02 17:36                     ` Christoph Lameter
2008-04-02 11:14                   ` Jens Axboe
2008-04-02 11:20                     ` Peter Zijlstra
2008-04-02 11:25                       ` Peter Zijlstra
2008-04-02 11:32                       ` Jens Axboe
2008-04-02 11:37                         ` Peter Zijlstra
2008-04-02 11:42                           ` Jens Axboe
2008-04-02 11:47                             ` Peter Zijlstra
2008-04-02 11:53                               ` Jens Axboe
2008-04-02 12:13                                 ` Peter Zijlstra
2008-04-02 12:28                                   ` Jens Axboe
2008-04-02 13:26                                   ` Paul E. McKenney
2008-04-02 13:43                                   ` Andi Kleen
2008-04-02 12:26                                 ` Peter Zijlstra [this message]
2008-04-02 12:34                                   ` Jens Axboe
2008-04-02 16:08               ` Paul E. McKenney
2008-04-02 16:15                 ` Vegard Nossum
2008-04-02 16:32                   ` Pekka J Enberg
2008-04-02 18:23                     ` Paul E. McKenney
2008-04-02 19:53                       ` Pekka Enberg
2008-04-02 20:15                         ` Paul E. McKenney
2008-04-03 15:18                           ` Paul E. McKenney
2008-04-03 19:49                             ` Pekka J Enberg
2008-04-03 21:27                               ` Paul E. McKenney
2008-04-02 16:59                   ` Paul E. McKenney
2008-04-02 17:31                     ` Vegard Nossum
2008-04-02 10:40     ` Paul E. McKenney
2008-04-02 10:46       ` Pekka Enberg
2008-04-02 10:49         ` Peter Zijlstra
2008-04-02 10:54           ` Pekka J Enberg
2008-04-02 17:35           ` Christoph Lameter
2008-04-02 10:53       ` Peter Zijlstra
2008-04-02 11:13         ` Jens Axboe

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=1207139162.8514.806.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penberg@cs.helsinki.fi \
    --cc=vegard.nossum@gmail.com \
    /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