summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2018-02-23 20:47:17 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-03-22 09:37:18 +0100
commite4353660cf59d49f2c75789081e97c9da21631ec (patch)
tree22039c11294182cc2d6c34ee74dfe902ae28ee77 /fs
parentb62e31c1c9bcf25b03225f44823e1d759a83a22d (diff)
downloadlinux-stable-e4353660cf59d49f2c75789081e97c9da21631ec.tar.gz
linux-stable-e4353660cf59d49f2c75789081e97c9da21631ec.tar.bz2
linux-stable-e4353660cf59d49f2c75789081e97c9da21631ec.zip
lock_parent() needs to recheck if dentry got __dentry_kill'ed under it
commit 3b821409632ab778d46e807516b457dfa72736ed upstream. In case when dentry passed to lock_parent() is protected from freeing only by the fact that it's on a shrink list and trylock of parent fails, we could get hit by __dentry_kill() (and subsequent dentry_kill(parent)) between unlocking dentry and locking presumed parent. We need to recheck that dentry is alive once we lock both it and parent *and* postpone rcu_read_unlock() until after that point. Otherwise we could return a pointer to struct dentry that already is rcu-scheduled for freeing, with ->d_lock held on it; caller's subsequent attempt to unlock it can end up with memory corruption. Cc: stable@vger.kernel.org # 3.12+, counting backports Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/dcache.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index ae7106123047..c064eea24c4a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -581,11 +581,16 @@ again:
spin_unlock(&parent->d_lock);
goto again;
}
- rcu_read_unlock();
- if (parent != dentry)
+ if (parent != dentry) {
spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
- else
+ if (unlikely(dentry->d_lockref.count < 0)) {
+ spin_unlock(&parent->d_lock);
+ parent = NULL;
+ }
+ } else {
parent = NULL;
+ }
+ rcu_read_unlock();
return parent;
}