Skip to content

Commit

Permalink
ovl: make ovl_create_real() cope with vfs_mkdir() safely
Browse files Browse the repository at this point in the history
vfs_mkdir() may succeed and leave the dentry passed to it unhashed and
negative.  ovl_create_real() is the last caller breaking when that
happens.

[amir: split re-factoring of ovl_create_temp() to prep patch
       add comment about unhashed dir after mkdir
       add pr_warn() if mkdir succeeds and lookup fails]

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Al Viro authored and Miklos Szeredi committed May 31, 2018
1 parent 137ec52 commit f73cc77
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion fs/overlayfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir,
goto out;
}

static int ovl_mkdir_real(struct inode *dir, struct dentry **newdentry,
umode_t mode)
{
int err;
struct dentry *d, *dentry = *newdentry;

err = ovl_do_mkdir(dir, dentry, mode);
if (err)
return err;

if (likely(!d_unhashed(dentry)))
return 0;

/*
* vfs_mkdir() may succeed and leave the dentry passed
* to it unhashed and negative. If that happens, try to
* lookup a new hashed and positive dentry.
*/
d = lookup_one_len(dentry->d_name.name, dentry->d_parent,
dentry->d_name.len);
if (IS_ERR(d)) {
pr_warn("overlayfs: failed lookup after mkdir (%pd2, err=%i).\n",
dentry, err);
return PTR_ERR(d);
}
dput(dentry);
*newdentry = d;

return 0;
}

struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry,
struct ovl_cattr *attr)
{
Expand All @@ -135,7 +166,8 @@ struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry,
break;

case S_IFDIR:
err = ovl_do_mkdir(dir, newdentry, attr->mode);
/* mkdir is special... */
err = ovl_mkdir_real(dir, &newdentry, attr->mode);
break;

case S_IFCHR:
Expand Down

0 comments on commit f73cc77

Please sign in to comment.