summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs/dir.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2018-05-16 18:19:53 +0300
committerMiklos Szeredi <mszeredi@redhat.com>2018-05-31 11:06:11 +0200
commitf73cc77c3afffc9a90fad972fe34af52cdb72979 (patch)
tree025f4c46514313a2ec0c09f35d652ebdbad7f6b7 /fs/overlayfs/dir.c
parent137ec526a20c4e4d21d658a6581b471d39860911 (diff)
downloadlinux-f73cc77c3afffc9a90fad972fe34af52cdb72979.tar.bz2
ovl: make ovl_create_real() cope with vfs_mkdir() safely
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>
Diffstat (limited to 'fs/overlayfs/dir.c')
-rw-r--r--fs/overlayfs/dir.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 1b181292a624..1d59c466d199 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -114,6 +114,37 @@ kill_whiteout:
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)
{
@@ -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: