]> git.itanic.dy.fi Git - linux-stable/commit
lock_parent() needs to recheck if dentry got __dentry_kill'ed under it
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 24 Feb 2018 01:47:17 +0000 (20:47 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Mar 2018 11:05:45 +0000 (12:05 +0100)
commit2fa76b885ece6d2b8aaaa3e28ff445d5527d4f27
tree72beef315348a1b18acb4b4aa69ee20e62c8e721
parent9c7b569aec95670a2d42f45d0327232b0d74af30
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>
fs/dcache.c