linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, Josef Bacik <jbacik@fb.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	"J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 2/9] dcache: close d_move race in d_splice_alias
Date: Tue, 18 Feb 2014 15:28:58 -0500	[thread overview]
Message-ID: <1392755345-12830-2-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <1392755345-12830-1-git-send-email-bfields@redhat.com>

From: "J. Bruce Fields" <bfields@redhat.com>

d_splice_alias will d_move an IS_ROOT() directory dentry into place if
one exists.  This should be safe as long as the dentry remains IS_ROOT,
but I can't see what guarantees that: once we drop the i_lock all we
hold here is the i_mutex on an unrelated parent directory.

Instead copy the logic of d_materialise_unique.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
 fs/dcache.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 332b58c..fd50e52 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2695,9 +2695,14 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
 		new = __d_find_alias(inode, 1);
 		if (new) {
 			BUG_ON(!(new->d_flags & DCACHE_DISCONNECTED));
+			write_seqlock(&rename_lock);
+			__d_materialise_dentry(dentry, new);
+			write_sequnlock(&rename_lock);
+			__d_drop(new);
+			_d_rehash(new);
+			spin_unlock(&new->d_lock);
 			spin_unlock(&inode->i_lock);
 			security_d_instantiate(new, inode);
-			d_move(new, dentry);
 			iput(inode);
 		} else {
 			/* already taking inode->i_lock, so d_add() by hand */
-- 
1.8.5.3


  reply	other threads:[~2014-02-18 20:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 18:43 [PATCH] Btrfs: unset DCACHE_DISCONNECTED when mounting default subvol Josef Bacik
2014-02-14 18:55 ` Eric W. Biederman
2014-02-14 22:05 ` J. Bruce Fields
2014-02-15  1:40   ` Eric W. Biederman
2014-02-15  2:45     ` J. Bruce Fields
2014-02-18 20:26       ` J. Bruce Fields
2014-02-18 20:28         ` [PATCH 1/9] dcache: move d_splice_alias J. Bruce Fields
2014-02-18 20:28           ` J. Bruce Fields [this message]
2014-02-21  1:43             ` [PATCH 2/9] dcache: close d_move race in d_splice_alias Christoph Hellwig
2014-02-18 20:28           ` [PATCH 3/9] dcache: d_splice_alias mustn't create directory aliases J. Bruce Fields
2014-02-18 20:29           ` [PATCH 4/9] dcache: d_splice_alias should ignore DCACHE_DISCONNECTED J. Bruce Fields
2014-02-18 20:29           ` [PATCH 5/9] dcache: d_obtain_alias callers don't all want DISCONNECTED J. Bruce Fields
2014-02-21  1:44             ` Christoph Hellwig
2014-02-24 20:23               ` J. Bruce Fields
2014-02-18 20:29           ` [PATCH 6/9] dcache: remove unused d_find_alias parameter J. Bruce Fields
2014-02-18 20:29           ` [PATCH 7/9] dcache: d_find_alias needn't recheck IS_ROOT && DCACHE_DISCONNECTED J. Bruce Fields
2014-02-18 20:29           ` [PATCH 8/9] exportfs: update Exporting documentation J. Bruce Fields
2014-02-18 20:29           ` [PATCH 9/9] dcache: rename DCACHE_DISCONNECTED -> DCACHE_CONNECTING J. Bruce Fields
2014-02-21  1:42           ` [PATCH 1/9] dcache: move d_splice_alias Christoph Hellwig
2014-02-18 21:32         ` [PATCH] Btrfs: unset DCACHE_DISCONNECTED when mounting default subvol Eric W. Biederman

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=1392755345-12830-2-git-send-email-bfields@redhat.com \
    --to=bfields@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.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).