]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
cachefiles: vfs_mkdir() might succeed leaving dentry negative unhashed
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 11 May 2018 02:59:45 +0000 (22:59 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 21 May 2018 18:30:10 +0000 (14:30 -0400)
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 <viro@zeniv.linux.org.uk>
fs/cachefiles/namei.c

index 0daa1e3fe0df837e3cbbade70184287aa129c294..ab0bbe93b398ce68dd0dc04652a626635d2c7c23 100644 (file)
@@ -572,6 +572,11 @@ lookup_again:
                        if (ret < 0)
                                goto create_error;
 
+                       if (unlikely(d_unhashed(next))) {
+                               dput(next);
+                               inode_unlock(d_inode(dir));
+                               goto lookup_again;
+                       }
                        ASSERT(d_backing_inode(next));
 
                        _debug("mkdir -> %p{%p{ino=%lu}}",
@@ -764,6 +769,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
        /* search the current directory for the element name */
        inode_lock(d_inode(dir));
 
+retry:
        start = jiffies;
        subdir = lookup_one_len(dirname, dir, strlen(dirname));
        cachefiles_hist(cachefiles_lookup_histogram, start);
@@ -793,6 +799,10 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
                if (ret < 0)
                        goto mkdir_error;
 
+               if (unlikely(d_unhashed(subdir))) {
+                       dput(subdir);
+                       goto retry;
+               }
                ASSERT(d_backing_inode(subdir));
 
                _debug("mkdir -> %p{%p{ino=%lu}}",