Skip to content

Commit 9c3e902

Browse files
author
Al Viro
committed
cachefiles: vfs_mkdir() might succeed leaving dentry negative unhashed
That can (and does, on some filesystems) happen - ->mkdir() (and thus vfs_mkdir()) can legitimately leave its argument negative and just unhash it, counting upon the lookup to pick the object we'd created next time we try to look at that name. Some vfs_mkdir() callers forget about that possibility... Signed-off-by: Al Viro <[email protected]>
1 parent 7b745a4 commit 9c3e902

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/cachefiles/namei.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
572572
if (ret < 0)
573573
goto create_error;
574574

575+
if (unlikely(d_unhashed(next))) {
576+
dput(next);
577+
inode_unlock(d_inode(dir));
578+
goto lookup_again;
579+
}
575580
ASSERT(d_backing_inode(next));
576581

577582
_debug("mkdir -> %p{%p{ino=%lu}}",
@@ -764,6 +769,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
764769
/* search the current directory for the element name */
765770
inode_lock(d_inode(dir));
766771

772+
retry:
767773
start = jiffies;
768774
subdir = lookup_one_len(dirname, dir, strlen(dirname));
769775
cachefiles_hist(cachefiles_lookup_histogram, start);
@@ -793,6 +799,10 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
793799
if (ret < 0)
794800
goto mkdir_error;
795801

802+
if (unlikely(d_unhashed(subdir))) {
803+
dput(subdir);
804+
goto retry;
805+
}
796806
ASSERT(d_backing_inode(subdir));
797807

798808
_debug("mkdir -> %p{%p{ino=%lu}}",

0 commit comments

Comments
 (0)