]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Merge branch 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszer...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 28 Oct 2017 15:29:29 +0000 (08:29 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 28 Oct 2017 15:29:29 +0000 (08:29 -0700)
Pull overlayfs fixes from Miklos Szeredi:
 "Fix several issues, most of them introduced in the last release"

* 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs:
  ovl: do not cleanup unsupported index entries
  ovl: handle ENOENT on index lookup
  ovl: fix EIO from lookup of non-indexed upper
  ovl: Return -ENOMEM if an allocation fails ovl_lookup()
  ovl: add NULL check in ovl_alloc_inode

fs/overlayfs/inode.c
fs/overlayfs/namei.c
fs/overlayfs/overlayfs.h
fs/overlayfs/readdir.c
fs/overlayfs/super.c

index a619addecafcf05713b3a41e7e05a9e0866847a1..321511ed8c4235e102adfe84b98ac17c247eeadb 100644 (file)
@@ -598,18 +598,30 @@ static bool ovl_verify_inode(struct inode *inode, struct dentry *lowerdentry,
        return true;
 }
 
-struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry)
+struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry,
+                           struct dentry *index)
 {
        struct dentry *lowerdentry = ovl_dentry_lower(dentry);
        struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL;
        struct inode *inode;
+       /* Already indexed or could be indexed on copy up? */
+       bool indexed = (index || (ovl_indexdir(dentry->d_sb) && !upperdentry));
+
+       if (WARN_ON(upperdentry && indexed && !lowerdentry))
+               return ERR_PTR(-EIO);
 
        if (!realinode)
                realinode = d_inode(lowerdentry);
 
-       if (!S_ISDIR(realinode->i_mode) &&
-           (upperdentry || (lowerdentry && ovl_indexdir(dentry->d_sb)))) {
-               struct inode *key = d_inode(lowerdentry ?: upperdentry);
+       /*
+        * Copy up origin (lower) may exist for non-indexed upper, but we must
+        * not use lower as hash key in that case.
+        * Hash inodes that are or could be indexed by origin inode and
+        * non-indexed upper inodes that could be hard linked by upper inode.
+        */
+       if (!S_ISDIR(realinode->i_mode) && (upperdentry || indexed)) {
+               struct inode *key = d_inode(indexed ? lowerdentry :
+                                                     upperdentry);
                unsigned int nlink;
 
                inode = iget5_locked(dentry->d_sb, (unsigned long) key,
index 654bea1a5ac9f38c587919d1fac6d53fd6867ee0..a12dc10bf726351a4a47a75f92b66d3b87043174 100644 (file)
@@ -405,14 +405,13 @@ int ovl_verify_index(struct dentry *index, struct path *lowerstack,
         * be treated as stale (i.e. after unlink of the overlay inode).
         * We don't know the verification rules for directory and whiteout
         * index entries, because they have not been implemented yet, so return
-        * EROFS if those entries are found to avoid corrupting an index that
-        * was created by a newer kernel.
+        * EINVAL if those entries are found to abort the mount to avoid
+        * corrupting an index that was created by a newer kernel.
         */
-       err = -EROFS;
+       err = -EINVAL;
        if (d_is_dir(index) || ovl_is_whiteout(index))
                goto fail;
 
-       err = -EINVAL;
        if (index->d_name.len < sizeof(struct ovl_fh)*2)
                goto fail;
 
@@ -507,6 +506,10 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry,
        index = lookup_one_len_unlocked(name.name, ofs->indexdir, name.len);
        if (IS_ERR(index)) {
                err = PTR_ERR(index);
+               if (err == -ENOENT) {
+                       index = NULL;
+                       goto out;
+               }
                pr_warn_ratelimited("overlayfs: failed inode index lookup (ino=%lu, key=%*s, err=%i);\n"
                                    "overlayfs: mount with '-o index=off' to disable inodes index.\n",
                                    d_inode(origin)->i_ino, name.len, name.name,
@@ -516,18 +519,9 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry,
 
        inode = d_inode(index);
        if (d_is_negative(index)) {
-               if (upper && d_inode(origin)->i_nlink > 1) {
-                       pr_warn_ratelimited("overlayfs: hard link with origin but no index (ino=%lu).\n",
-                                           d_inode(origin)->i_ino);
-                       goto fail;
-               }
-
-               dput(index);
-               index = NULL;
+               goto out_dput;
        } else if (upper && d_inode(upper) != inode) {
-               pr_warn_ratelimited("overlayfs: wrong index found (index=%pd2, ino=%lu, upper ino=%lu).\n",
-                                   index, inode->i_ino, d_inode(upper)->i_ino);
-               goto fail;
+               goto out_dput;
        } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) ||
                   ((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) {
                /*
@@ -547,6 +541,11 @@ out:
        kfree(name.name);
        return index;
 
+out_dput:
+       dput(index);
+       index = NULL;
+       goto out;
+
 fail:
        dput(index);
        index = ERR_PTR(-EIO);
@@ -635,6 +634,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                }
 
                if (d.redirect) {
+                       err = -ENOMEM;
                        upperredirect = kstrdup(d.redirect, GFP_KERNEL);
                        if (!upperredirect)
                                goto out_put_upper;
@@ -709,7 +709,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                upperdentry = dget(index);
 
        if (upperdentry || ctr) {
-               inode = ovl_get_inode(dentry, upperdentry);
+               inode = ovl_get_inode(dentry, upperdentry, index);
                err = PTR_ERR(inode);
                if (IS_ERR(inode))
                        goto out_free_oe;
index c706a6f999288136b567d75777f5f6742682a9a2..d9a0edd4e57e40c6157613a652d0dffe86335c07 100644 (file)
@@ -286,7 +286,8 @@ int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);
 bool ovl_is_private_xattr(const char *name);
 
 struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
-struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry);
+struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry,
+                           struct dentry *index);
 static inline void ovl_copyattr(struct inode *from, struct inode *to)
 {
        to->i_uid = from->i_uid;
index 0f85ee9c3268adb320dcc6c4d37e88ae3ea92013..698b74dd750ee6a9fb2586d0f8d42853111e6bd1 100644 (file)
@@ -1021,13 +1021,12 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt,
                        break;
                }
                err = ovl_verify_index(index, lowerstack, numlower);
-               if (err) {
-                       if (err == -EROFS)
-                               break;
+               /* Cleanup stale and orphan index entries */
+               if (err && (err == -ESTALE || err == -ENOENT))
                        err = ovl_cleanup(dir, index);
-                       if (err)
-                               break;
-               }
+               if (err)
+                       break;
+
                dput(index);
                index = NULL;
        }
index 092d150643c12061407be0ecab554a38fe88d9fc..f5738e96a052fe06c892923b69cd4708d8b24f70 100644 (file)
@@ -174,6 +174,9 @@ static struct inode *ovl_alloc_inode(struct super_block *sb)
 {
        struct ovl_inode *oi = kmem_cache_alloc(ovl_inode_cachep, GFP_KERNEL);
 
+       if (!oi)
+               return NULL;
+
        oi->cache = NULL;
        oi->redirect = NULL;
        oi->version = 0;