summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2018-10-17 15:23:26 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-11-10 07:43:00 -0800
commit186c5856dc5ac1f80655c58a2dfefa1d187f6417 (patch)
treeeca66fc0fc64f2c0f1398010403998fb767d9755
parent9bb68aaf6436ef43f2f4ceb00149aaa82474648c (diff)
downloadlinux-stable-186c5856dc5ac1f80655c58a2dfefa1d187f6417.tar.gz
linux-stable-186c5856dc5ac1f80655c58a2dfefa1d187f6417.tar.bz2
linux-stable-186c5856dc5ac1f80655c58a2dfefa1d187f6417.zip
cachefiles: fix the race between cachefiles_bury_object() and rmdir(2)
commit 169b803397499be85bdd1e3d07d6f5e3d4bd669e upstream. the victim might've been rmdir'ed just before the lock_rename(); unlike the normal callers, we do not look the source up after the parents are locked - we know it beforehand and just recheck that it's still the child of what used to be its parent. Unfortunately, the check is too weak - we don't spot a dead directory since its ->d_parent is unchanged, dentry is positive, etc. So we sail all the way to ->rename(), with hosting filesystems _not_ expecting to be asked renaming an rmdir'ed subdirectory. The fix is easy, fortunately - the lock on parent is sufficient for making IS_DEADDIR() on child safe. Cc: stable@vger.kernel.org Fixes: 9ae326a69004 (CacheFiles: A cache that backs onto a mounted filesystem) Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/cachefiles/namei.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 2026885702a2..3fb95e3d20d6 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -340,7 +340,7 @@ try_again:
trap = lock_rename(cache->graveyard, dir);
/* do some checks before getting the grave dentry */
- if (rep->d_parent != dir) {
+ if (rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) {
/* the entry was probably culled when we dropped the parent dir
* lock */
unlock_rename(cache->graveyard, dir);