Skip to content

Commit 169b803

Browse files
Al Virogregkh
authored andcommitted
cachefiles: fix the race between cachefiles_bury_object() and rmdir(2)
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: 9ae326a (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>
1 parent eb66ae0 commit 169b803

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/cachefiles/namei.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
343343
trap = lock_rename(cache->graveyard, dir);
344344

345345
/* do some checks before getting the grave dentry */
346-
if (rep->d_parent != dir) {
346+
if (rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) {
347347
/* the entry was probably culled when we dropped the parent dir
348348
* lock */
349349
unlock_rename(cache->graveyard, dir);

0 commit comments

Comments
 (0)