Commit 4d57edcd authored by Al Viro's avatar Al Viro Committed by Greg Kroah-Hartman

lock_parent: don't step on stale ->d_parent of all-but-freed one

commit c2338f2d upstream.

Dentry that had been through (or into) __dentry_kill() might be seen
by shrink_dentry_list(); that's normal, it'll be taken off the shrink
list and freed if __dentry_kill() has already finished.  The problem
is, its ->d_parent might be pointing to already freed dentry, so
lock_parent() needs to be careful.

We need to check that dentry hasn't already gone into __dentry_kill()
*and* grab rcu_read_lock() before dropping ->d_lock - the latter makes
sure that whatever we see in ->d_parent after dropping ->d_lock it
won't be freed until we drop rcu_read_lock().
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 001869c3
...@@ -530,10 +530,12 @@ static inline struct dentry *lock_parent(struct dentry *dentry) ...@@ -530,10 +530,12 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
struct dentry *parent = dentry->d_parent; struct dentry *parent = dentry->d_parent;
if (IS_ROOT(dentry)) if (IS_ROOT(dentry))
return NULL; return NULL;
if (unlikely((int)dentry->d_lockref.count < 0))
return NULL;
if (likely(spin_trylock(&parent->d_lock))) if (likely(spin_trylock(&parent->d_lock)))
return parent; return parent;
spin_unlock(&dentry->d_lock);
rcu_read_lock(); rcu_read_lock();
spin_unlock(&dentry->d_lock);
again: again:
parent = ACCESS_ONCE(dentry->d_parent); parent = ACCESS_ONCE(dentry->d_parent);
spin_lock(&parent->d_lock); spin_lock(&parent->d_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment