LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Neil Brown <neilb@suse.de>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 002 of 6] md: Fix use-after-free bug when dropping an rdev from an md array.
Date: Mon, 14 Jan 2008 15:48:56 +1100	[thread overview]
Message-ID: <18314.59832.14451.334084@notabene.brown> (raw)
In-Reply-To: message from Al Viro on Monday January 14

On Monday January 14, viro@ZenIV.linux.org.uk wrote:
> On Mon, Jan 14, 2008 at 02:21:45PM +1100, Neil Brown wrote:
> 
> > Maybe it isn't there any more....
> > 
> > Once upon a time, when I 
> >    echo remove > /sys/block/mdX/md/dev-YYY/state
> 
> Egads.  And just what will protect you from parallel callers
> of state_store()?  buffer->mutex does *not* do that - it only
> gives you exclusion on given struct file.  Run the command
> above from several shells and you've got independent open
> from each redirect => different struct file *and* different
> buffer for each => no exclusion whatsoever.

well in -mm, rdev_attr_store gets a lock on
rdev->mddev->reconfig_mutex. 
It doesn't test is rdev->mddev is NULL though, so if the write happens
after unbind_rdev_from_array, we lose.
A test for NULL would be easy enough.  And I think that the mddev
won't actually disappear until the rdevs are all gone (you subsequent
comment about kobject_del ordering seems to confirm that) so a simple test
for NULL should be sufficient.

> 
> And _that_ is present right in the mainline tree - it's unrelated
> to -mm kobject changes.
> 
> BTW, yes, you do have a deadlock there - kobject_del() will try to evict
> children, which will include waiting for currently running ->store()
> to finish, which will include the caller since .../state *is* a child of
> that sucker.
> 
> The real problem is the lack of any kind of exclusion considerations in
> md.c itself, AFAICS.  Fun with ordering is secondary (BTW, yes, it is
> a problem - will sysfs ->store() to attribute between export_rdev() and
> kobject_del() work correctly?)

Probably not.  The possibility that rdev->mddev could be NULL would
break a lot of these.  Maybe I should delay setting rdev->mddev to
NULL until after the kobject_del.  Then audit them all.

Thanks.  I'll see what I can some up with.

NeilBrown

  reply	other threads:[~2008-01-14  4:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-14  1:45 [PATCH 000 of 6] md: various fixes for md NeilBrown
2008-01-14  1:45 ` [PATCH 001 of 6] md: Fix an occasional deadlock in raid5 NeilBrown
2008-01-16  5:01   ` dean gaudet
2008-01-16  5:54     ` Andrew Morton
2008-01-16  6:13       ` dean gaudet
2008-01-16  7:09         ` Dan Williams
2008-01-16  7:15           ` Andrew Morton
2008-01-16 21:54             ` Neil Brown
2008-01-14  1:45 ` [PATCH 002 of 6] md: Fix use-after-free bug when dropping an rdev from an md array NeilBrown
2008-01-14  2:04   ` Al Viro
2008-01-14  3:21     ` Neil Brown
2008-01-14  3:43       ` Al Viro
2008-01-14  4:48         ` Neil Brown [this message]
2008-01-14  6:28           ` Neil Brown
2008-01-14 12:59             ` Al Viro
2008-01-14 13:56               ` Al Viro
2008-01-14  1:45 ` [PATCH 003 of 6] md: Change a few 'int' to 'size_t' in md NeilBrown
2008-01-14  1:45 ` [PATCH 004 of 6] md: Change INTERATE_MDDEV to for_each_mddev NeilBrown
2008-01-14  1:45 ` [PATCH 005 of 6] md: Change ITERATE_RDEV to rdev_for_each NeilBrown
2008-01-14  1:45 ` [PATCH 006 of 6] md: Change ITERATE_RDEV_GENERIC to rdev_for_each_list, and remove ITERATE_RDEV_PENDING NeilBrown

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=18314.59832.14451.334084@notabene.brown \
    --to=neilb@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    --subject='Re: [PATCH 002 of 6] md: Fix use-after-free bug when dropping an rdev from an md array.' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).