Skip to content

Commit

Permalink
NFS: fix two problems in lookup_revalidate in RCU-walk
Browse files Browse the repository at this point in the history
1/ rcu_dereference isn't correct: that field isn't
   RCU protected.   It could potentially change at any time
   so ACCESS_ONCE might be justified.

   changes to ->d_parent are protected by ->d_seq.  However
   that isn't always checked after ->d_revalidate is called,
   so it is safest to keep the double-check that ->d_parent
   hasn't changed at the end of these functions.

2/ in nfs4_lookup_revalidate, "->d_parent" was forgotten.
   So 'parent' was not the parent of 'dentry'.
   This fails safe is the context is that dentry->d_inode is
   NULL, and the result of parent->d_inode being NULL is
   that ECHILD is returned, which is always safe.

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
  • Loading branch information
NeilBrown authored and Trond Myklebust committed Aug 4, 2014
1 parent f682a39 commit 50d7773
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
int error;

if (flags & LOOKUP_RCU) {
parent = rcu_dereference(dentry->d_parent);
parent = ACCESS_ONCE(dentry->d_parent);
dir = ACCESS_ONCE(parent->d_inode);
if (!dir)
return -ECHILD;
Expand Down Expand Up @@ -1184,7 +1184,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
nfs_advise_use_readdirplus(dir);
out_valid_noent:
if (flags & LOOKUP_RCU) {
if (parent != rcu_dereference(dentry->d_parent))
if (parent != ACCESS_ONCE(dentry->d_parent))
return -ECHILD;
} else
dput(parent);
Expand Down Expand Up @@ -1585,7 +1585,7 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
struct inode *dir;

if (flags & LOOKUP_RCU) {
parent = rcu_dereference(dentry);
parent = ACCESS_ONCE(dentry->d_parent);
dir = ACCESS_ONCE(parent->d_inode);
if (!dir)
return -ECHILD;
Expand All @@ -1599,7 +1599,7 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
ret = -ECHILD;
if (!(flags & LOOKUP_RCU))
dput(parent);
else if (parent != rcu_dereference(dentry))
else if (parent != ACCESS_ONCE(dentry->d_parent))
return -ECHILD;
goto out;
}
Expand Down

0 comments on commit 50d7773

Please sign in to comment.