linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb-l3A5Bk7waGM@public.gmane.org>
To: "J. Bruce Fields" <bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
Cc: Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>,
	Nick Piggin <npiggin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Nick Piggin <npiggin-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] fs/dcache: allow __d_obtain_alias() to return unhashed dentries
Date: Mon, 20 Feb 2012 13:55:37 +1100	[thread overview]
Message-ID: <20120220135537.3078e20b@notabene.brown> (raw)
In-Reply-To: <20120216223011.GA23997-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 4740 bytes --]

On Thu, 16 Feb 2012 17:30:11 -0500 "J. Bruce Fields" <bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
wrote:

> On Thu, Feb 16, 2012 at 02:06:03PM +1100, NeilBrown wrote:
> > I was going ask how you managed to get an 'unhashed' dentry which was not
> > DISCONNECTED, and belonged to a directory that could be the subject of
> > d_splice_alias (that implies it has a name).
> > 
> > The bug sounds like a race between lookup and rmdir, which should be
> > prevented by i_mutex.
> > 
> > I think that using __d_find_any_alias would just be papering over the
> > problem, and would trigger a BUG_ON when it returned a non-DISCONNECTED alias.
> 
> Looking through the latest upstream code, I can't come up with another
> obvious reproducer.
> 
> But I also can't see the code making any particular effort to ensure
> that dentries are removed from inode's alias lists at the same time
> they're unhashed.
> 
> E.g., trace up through the callers of d_drop/__d_drop and try to
> convince yourselves that they all end up removing the dentry from the
> alias list.
> 
> Can you see any reason why the following would actually create a
> problem?

No, I don't think that would cause problems, so it is probably a good clean
up and as Peng says it means we can remove the want_discon arg as well.

However I cannot help thinking that something else must be going wrong before
we get to this point.
When you rmdir a directory it must be empty and it will never be linked again.
So how does 'lookup' find the inode and want to attach a dentry to it?

So I still think this is just papering over some other problem.

I think that looking at when aliases are removed is missing the point.

A directory can only have one name so it can only have one dentry.
If that dentry gets unhashed, that is because the directory was deleted.  So
now it must have zero names.  So there is no way that lookup can possibly
find it, so there is no way that d_splice_alias can be asked to attach an
alias to it.


NeilBrown


> 
> --b.
> 
> commit fcfef6b7319c5d19ea5064317528ff994343b011
> Author: J. Bruce Fields <bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Date:   Mon Feb 13 13:38:33 2012 -0500
> 
>     exports: stop d_splice_alias creating directory aliases
>     
>     A directory should never have more than one dentry pointing to it.
>     
>     But d_splice_alias() does so in the case of a directory with an
>     already-existing non-DISCONNECTED dentry.
>     
>     Prior to the removal of dentry_unhash() from vfs_rmdir(), around v3.0,
>     this could cause an nfsd deadlock like this:
>     
>     	- Somebody attempts to remove a non-empty directory.
>     	- The dentry_unhash() in vfs_rmdir() unhashes the dentry
>     	  pointing to the non-empty directory.
>     	- ->rmdir() then fails with -ENOTEMPTY
>     	- Before the vfs_rmdir() caller reaches dput(), an nfsd process
>     	  in rename looks up the directory by filehandle; at the end of
>     	  that lookup, this dentry is found by d_alloc_anon(), and a
>     	  reference is taken on it, preventing dput() from removing it.
>     	- A regular lookup of the directory calls d_splice_alias(),
>     	  finds only an unhashed (not a DISCONNECTED) dentry, and
>     	  insteads adds a new one, so the directory now has two
>     	  dentries.
>     	- The nfsd process in rename, which was previously looking up
>     	  the source directory of the rename, now looks up the target
>     	  directory (which is the same), and gets the dentry newly
>     	  created by the previous lookup.
>     	- The rename, seeing two different dentries, assumes this is a
>     	  cross-directory rename and attempts to take the i_mutex on the
>     	  directory twice.
>     
>     I don't see as obvious a reproducer now, but I also don't see the
>     existing code taking care to remove dentries from the alias list
>     whenever they're unhashed.
>     
>     It therefore seems safest to allow d_splice_alias to use any dentry it
>     finds.
>     
>     Signed-off-by: J. Bruce Fields <bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> 
> diff --git a/fs/dcache.c b/fs/dcache.c
> index f68e193..1fd2256 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1602,9 +1602,8 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
>  
>  	if (inode && S_ISDIR(inode->i_mode)) {
>  		spin_lock(&inode->i_lock);
> -		new = __d_find_alias(inode, 1);
> +		new = __d_find_any_alias(inode);
>  		if (new) {
> -			BUG_ON(!(new->d_flags & DCACHE_DISCONNECTED));
>  			spin_unlock(&inode->i_lock);
>  			security_d_instantiate(new, inode);
>  			d_move(new, dentry);


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  parent reply	other threads:[~2012-02-20  2:55 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-12 18:43 lifetime of DCACHE_DISCONECTED dentries J. Bruce Fields
2010-11-13 11:53 ` Nick Piggin
2010-11-15 17:48   ` J. Bruce Fields
     [not found]     ` <20101115174837.GB10044-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-11-16  6:45       ` Nick Piggin
2010-11-29  3:56         ` Nick Piggin
2010-11-29 19:32           ` J. Bruce Fields
     [not found]             ` <20101129193248.GA9897-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-11-30  1:00               ` Nick Piggin
     [not found]                 ` <AANLkTikwzDJ_q65==uxDsAhp3h8bU7Rkt7U9gVgRAK0D-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-11-30 18:39                   ` J. Bruce Fields
2010-12-03 22:33                   ` [PATCH] nfsd4: allow __d_obtain_alias() to return unhashed dentries J. Bruce Fields
2010-12-13  5:19                     ` Nick Piggin
2010-12-14 22:01                       ` J. Bruce Fields
     [not found]                         ` <20101214220102.GM24828-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-12-17 17:53                           ` [PATCH] fs/dcache: use standard list macro for d_find_alias J. Bruce Fields
2010-12-17 18:00                           ` [PATCH 2/2] fs/dcache: allow __d_obtain_alias() to return unhashed dentries J. Bruce Fields
2010-12-18  2:01                             ` Nick Piggin
2010-12-18 16:16                               ` J. Bruce Fields
     [not found]                                 ` <20101218161609.GA22150-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-12-19 14:53                                   ` Nick Piggin
     [not found]                                     ` <AANLkTingRv_gtRSctGzMfYrKg02M_sKj97HSQPRm_mA_-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-27 23:46                                       ` [PATCH] " J. Bruce Fields
     [not found]                                         ` <20101227234641.GA22248-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-01-18 20:45                                           ` J. Bruce Fields
     [not found]                                             ` <20110118204509.GA10903-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-01-18 22:02                                               ` Nick Piggin
     [not found]                                                 ` <AANLkTikL2CDSWQJ1QH_Y4G-j70Vd=VesNMMnYTmMGHC9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-01-18 22:08                                                   ` J. Bruce Fields
     [not found]                                                     ` <20110118220817.GF10903-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-03-08 18:13                                                       ` J. Bruce Fields
     [not found]                                                         ` <20110308181320.GA15566-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-03-10 10:58                                                           ` Al Viro
     [not found]                                                             ` <20110310105821.GE22723-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2011-03-11  4:07                                                               ` NeilBrown
     [not found]                                                                 ` <20110311150749.2fa2be66-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-02-14 17:03                                                                   ` J. Bruce Fields
     [not found]                                                                     ` <20120214170300.GA4309-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-15 16:56                                                                       ` J. Bruce Fields
     [not found]                                                                         ` <20120215165633.GE12490-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-16  3:06                                                                           ` NeilBrown
     [not found]                                                                             ` <20120216140603.08cb4900-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-02-16 11:51                                                                               ` J. Bruce Fields
     [not found]                                                                                 ` <20120216115133.GA20279-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-16 16:08                                                                                   ` J. Bruce Fields
2012-02-16 22:30                                                                             ` J. Bruce Fields
     [not found]                                                                               ` <20120216223011.GA23997-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-17 16:34                                                                                 ` Peng Tao
2012-03-13 20:55                                                                                   ` J. Bruce Fields
2012-03-13 20:58                                                                                     ` [PATCH 1/2] vfs: stop d_splice_alias creating directory aliases J. Bruce Fields
2012-03-13 20:58                                                                                     ` [PATCH 2/2] vfs: remove unused __d_splice_alias argument J. Bruce Fields
2012-02-20  2:55                                                                                 ` NeilBrown [this message]
     [not found]                                                                                   ` <20120220135537.3078e20b-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-02-29 23:10                                                                                     ` [PATCH] fs/dcache: allow __d_obtain_alias() to return unhashed dentries J. Bruce Fields
2012-06-28 13:59                                                                   ` J. Bruce Fields
     [not found]                                                                     ` <20120628135927.GA6406-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-06-29 20:10                                                                       ` J. Bruce Fields
     [not found]                                                                         ` <20120629201034.GA17103-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-06-29 20:29                                                                           ` J. Bruce Fields
2012-07-01 23:15                                                                             ` 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=20120220135537.3078e20b@notabene.brown \
    --to=neilb-l3a5bk7wagm@public.gmane.org \
    --cc=bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=npiggin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=npiggin-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
    --cc=viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).