Skip to content

Commit

Permalink
cachefiles: fix the race between cachefiles_bury_object() and rmdir(2)
Browse files Browse the repository at this point in the history
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: [email protected]
Fixes: 9ae326a (CacheFiles: A cache that backs onto a mounted filesystem)
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: David Howells <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Al Viro authored and gregkh committed Oct 18, 2018
1 parent eb66ae0 commit 169b803
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/cachefiles/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
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);
Expand Down

0 comments on commit 169b803

Please sign in to comment.