From: Hugh Dickins <hughd@google.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Nick Piggin <npiggin@kernel.dk>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] vfs: fix race in rcu lookup of pruned dentry
Date: Mon, 18 Jul 2011 15:43:29 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.00.1107181533590.3909@sister.anvils> (raw)
In-Reply-To: <CA+55aFxq1KZycxXCwLARv0WOYG_-aim=e9kt=eLcNuymmeoyiA@mail.gmail.com>
On Mon, 18 Jul 2011, Linus Torvalds wrote:
> On Mon, Jul 18, 2011 at 2:19 PM, Hugh Dickins <hughd@google.com> wrote:
> >
> > __d_lookup_rcu() is being careful about *inode, yes.
> >
> > But I'd forgotten it was even setting it: doesn't that setting get
> > overridden later by the more careless *inode = path->d_entry->d_inode
> > at the head of __follow_mount_rcu()'s loop?
> >
> > Perhaps that line just needs to be moved to the tail of the loop?
>
> Ahh. Bingo. Yes, I think you found it.
>
> I don't think it should touch that *inode value in
> __follow_mount_rcu() unless we actually followed a mount, exactly
> because it will overwrite the thing that we were so careful about in
> __d_lookup_rcu().
>
> So how about this patch that replaces the earlier mount-point sequence
> number one. The only difference is (as you mention) to just do the
> *inode update at the end of the loop, so that we don't overwrite the
> valid inode data with a non-checked one when we don't do anything.
>
> Untested. But this should make my propised change to fs/dcache.c be
> irrelevant, because whether we clear d_inode or not, the existing
> sequence number checks will catch it. Agreed?
Yes, that looks like THE right fix to me, making others irrelevant.
But I haven't tested it either, won't begin to do so until tonight.
And I fear I won't notice if there's any silly little bug in there,
which forces every fast RCU lookup to go the slow way instead!
Inlined for the benefit of wider scrutiny:
fs/namei.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 5c867dd1c0b3..b9cd558a00be 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -938,11 +938,12 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
{
for (;;) {
struct vfsmount *mounted;
+ unsigned int seq;
+
/*
* Don't forget we might have a non-mountpoint managed dentry
* that wants to block transit.
*/
- *inode = path->dentry->d_inode;
if (unlikely(managed_dentry_might_block(path->dentry)))
return false;
@@ -952,9 +953,25 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
mounted = __lookup_mnt(path->mnt, path->dentry, 1);
if (!mounted)
break;
+ seq = read_seqcount_begin(&mounted->mnt_root->d_seq);
+
+ /*
+ * The memory barrier in read_seqcount_begin() is sufficient,
+ * so we can use __read_seqcount_retry() to check the prev
+ * sequence numbers.
+ */
+ if (!__read_seqcount_retry(&path->dentry->d_seq, nd->seq))
+ return false;
path->mnt = mounted;
path->dentry = mounted->mnt_root;
- nd->seq = read_seqcount_begin(&path->dentry->d_seq);
+ nd->seq = seq;
+
+ /*
+ * Update the inode too. We don't need to re-check the
+ * dentry sequence number here after this d_inode read,
+ * because a mount-point is always pinned.
+ */
+ *inode = path->dentry->d_inode;
}
return true;
}
next prev parent reply other threads:[~2011-07-18 22:43 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-17 21:03 Hugh Dickins
2011-07-17 22:00 ` Linus Torvalds
2011-07-17 22:59 ` Linus Torvalds
2011-07-17 23:26 ` Al Viro
2011-07-17 23:16 ` Al Viro
2011-07-17 23:38 ` Linus Torvalds
2011-07-17 23:47 ` Hugh Dickins
2011-07-18 0:25 ` Al Viro
2011-07-18 1:13 ` Hugh Dickins
2011-07-18 2:08 ` Al Viro
2011-07-18 6:31 ` Linus Torvalds
2011-07-18 14:41 ` Hugh Dickins
2011-07-18 18:11 ` Linus Torvalds
2011-07-18 18:20 ` Al Viro
2011-07-18 19:08 ` Linus Torvalds
2011-07-18 19:20 ` Al Viro
2011-07-18 19:23 ` Al Viro
2011-07-18 19:34 ` Linus Torvalds
2011-07-18 19:04 ` Hugh Dickins
2011-07-18 19:33 ` Linus Torvalds
2011-07-18 19:47 ` Al Viro
2011-07-18 20:24 ` Linus Torvalds
2011-07-18 21:19 ` Hugh Dickins
2011-07-18 21:42 ` Linus Torvalds
2011-07-18 22:43 ` Hugh Dickins [this message]
2011-07-18 23:17 ` Al Viro
2011-07-18 23:21 ` Al Viro
2011-07-18 23:27 ` Linus Torvalds
2011-07-18 23:40 ` Al Viro
2011-07-19 2:07 ` Hugh Dickins
2011-07-19 2:14 ` Linus Torvalds
2011-07-19 2:17 ` Linus Torvalds
2011-07-19 2:23 ` Al Viro
2011-07-19 2:37 ` Chris Ball
2011-07-19 4:41 ` Nicolas Pitre
2011-07-19 2:21 ` Al Viro
2011-07-19 23:45 ` Al Viro
2011-07-19 23:52 ` Al Viro
2011-07-19 23:55 ` Al Viro
2011-07-20 0:47 ` NeilBrown
2011-07-20 1:40 ` Al Viro
2011-07-20 4:52 ` Linus Torvalds
2011-07-19 23:56 ` Linus Torvalds
2011-07-20 0:04 ` Al Viro
2011-07-17 23:53 ` Al Viro
2011-07-17 23:31 ` Hugh Dickins
2011-07-17 23:52 ` Linus Torvalds
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=alpine.LSU.2.00.1107181533590.3909@sister.anvils \
--to=hughd@google.com \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@kernel.dk \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®