]> Git Repo - linux.git/commitdiff
Merge tag 'ovl-update-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs
authorLinus Torvalds <[email protected]>
Wed, 10 Jan 2024 18:48:22 +0000 (10:48 -0800)
committerLinus Torvalds <[email protected]>
Wed, 10 Jan 2024 18:48:22 +0000 (10:48 -0800)
Pull overlayfs updates from Amir Goldstein:
 "This is a very small update with no bug fixes and no new features.

  The larger update of overlayfs for this cycle, the re-factoring of
  overlayfs code into generic backing_file helpers, was already merged
  via Christian.

  Summary:

   - Simplify/clarify some code

     No bug fixes here, just some changes following questions from Al
     about overlayfs code that could be a little more simple to follow.

   - Overlayfs documentation style fixes

     Mainly fixes for ReST formatting suggested by documentation
     developers"

* tag 'ovl-update-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs:
  overlayfs.rst: fix ReST formatting
  overlayfs.rst: use consistent feature names
  ovl: initialize ovl_copy_up_ctx.destname inside ovl_do_copy_up()
  ovl: remove redundant ofs->indexdir member

1  2 
fs/overlayfs/copy_up.c
fs/overlayfs/super.c

diff --combined fs/overlayfs/copy_up.c
index 45cadc3aed85d6c1caa1e4bbd4e55fe210334e8a,500c555792ff68b8b0bd5f1e1b0b63a3584a2d14..696478f09cc1b459cbe26502ae4db81ec91300b3
@@@ -230,19 -230,6 +230,19 @@@ static int ovl_copy_fileattr(struct ino
        return ovl_real_fileattr_set(new, &newfa);
  }
  
 +static int ovl_verify_area(loff_t pos, loff_t pos2, loff_t len, loff_t totlen)
 +{
 +      loff_t tmp;
 +
 +      if (WARN_ON_ONCE(pos != pos2))
 +              return -EIO;
 +      if (WARN_ON_ONCE(pos < 0 || len < 0 || totlen < 0))
 +              return -EIO;
 +      if (WARN_ON_ONCE(check_add_overflow(pos, len, &tmp)))
 +              return -EIO;
 +      return 0;
 +}
 +
  static int ovl_copy_up_file(struct ovl_fs *ofs, struct dentry *dentry,
                            struct file *new_file, loff_t len)
  {
        int error = 0;
  
        ovl_path_lowerdata(dentry, &datapath);
 -      if (WARN_ON(datapath.dentry == NULL))
 +      if (WARN_ON_ONCE(datapath.dentry == NULL) ||
 +          WARN_ON_ONCE(len < 0))
                return -EIO;
  
        old_file = ovl_path_open(&datapath, O_LARGEFILE | O_RDONLY);
        if (IS_ERR(old_file))
                return PTR_ERR(old_file);
  
 +      error = rw_verify_area(READ, old_file, &old_pos, len);
 +      if (!error)
 +              error = rw_verify_area(WRITE, new_file, &new_pos, len);
 +      if (error)
 +              goto out_fput;
 +
        /* Try to use clone_file_range to clone up within the same fs */
        ovl_start_write(dentry);
        cloned = do_clone_file_range(old_file, 0, new_file, 0, len, 0);
  
        while (len) {
                size_t this_len = OVL_COPY_UP_CHUNK_SIZE;
 -              long bytes;
 +              ssize_t bytes;
  
                if (len < this_len)
                        this_len = len;
                        }
                }
  
 -              ovl_start_write(dentry);
 +              error = ovl_verify_area(old_pos, new_pos, this_len, len);
 +              if (error)
 +                      break;
 +
                bytes = do_splice_direct(old_file, &old_pos,
                                         new_file, &new_pos,
                                         this_len, SPLICE_F_MOVE);
 -              ovl_end_write(dentry);
                if (bytes <= 0) {
                        error = bytes;
                        break;
@@@ -775,16 -753,15 +775,16 @@@ static int ovl_copy_up_workdir(struct o
        path.dentry = temp;
        err = ovl_copy_up_data(c, &path);
        /*
 -       * We cannot hold lock_rename() throughout this helper, because or
 +       * We cannot hold lock_rename() throughout this helper, because of
         * lock ordering with sb_writers, which shouldn't be held when calling
         * ovl_copy_up_data(), so lock workdir and destdir and make sure that
         * temp wasn't moved before copy up completion or cleanup.
 -       * If temp was moved, abort without the cleanup.
         */
        ovl_start_write(c->dentry);
        if (lock_rename(c->workdir, c->destdir) != NULL ||
            temp->d_parent != c->workdir) {
 +              /* temp or workdir moved underneath us? abort without cleanup */
 +              dput(temp);
                err = -EIO;
                goto unlock;
        } else if (err) {
@@@ -952,6 -929,13 +952,13 @@@ static int ovl_do_copy_up(struct ovl_co
                err = -EIO;
                goto out_free_fh;
        } else {
+               /*
+                * c->dentry->d_name is stabilzed by ovl_copy_up_start(),
+                * because if we got here, it means that c->dentry has no upper
+                * alias and changing ->d_name means going through ovl_rename()
+                * that will call ovl_copy_up() on source and target dentry.
+                */
+               c->destname = c->dentry->d_name;
                /*
                 * Mark parent "impure" because it may now contain non-pure
                 * upper
@@@ -1132,7 -1116,6 +1139,6 @@@ static int ovl_copy_up_one(struct dentr
        if (parent) {
                ovl_path_upper(parent, &parentpath);
                ctx.destdir = parentpath.dentry;
-               ctx.destname = dentry->d_name;
  
                err = vfs_getattr(&parentpath, &ctx.pstat,
                                  STATX_ATIME | STATX_MTIME,
diff --combined fs/overlayfs/super.c
index 7131e3f5b9f56c4c8f6adf9c8b48dfe026586740,f78161cf838813553c59f5c92687eb1cae66d6c4..0bbbe4818f676c954abc99c3a0e052834a2fbdd9
@@@ -853,10 -853,8 +853,8 @@@ static int ovl_get_indexdir(struct supe
        if (IS_ERR(indexdir)) {
                err = PTR_ERR(indexdir);
        } else if (indexdir) {
-               ofs->indexdir = indexdir;
-               ofs->workdir = dget(indexdir);
-               err = ovl_setup_trap(sb, ofs->indexdir, &ofs->indexdir_trap,
+               ofs->workdir = indexdir;
+               err = ovl_setup_trap(sb, indexdir, &ofs->workdir_trap,
                                     "indexdir");
                if (err)
                        goto out;
                 * ".overlay.upper" to indicate that index may have
                 * directory entries.
                 */
-               if (ovl_check_origin_xattr(ofs, ofs->indexdir)) {
-                       err = ovl_verify_origin_xattr(ofs, ofs->indexdir,
+               if (ovl_check_origin_xattr(ofs, indexdir)) {
+                       err = ovl_verify_origin_xattr(ofs, indexdir,
                                                      OVL_XATTR_ORIGIN,
                                                      upperpath->dentry, true,
                                                      false);
                        if (err)
                                pr_err("failed to verify index dir 'origin' xattr\n");
                }
-               err = ovl_verify_upper(ofs, ofs->indexdir, upperpath->dentry,
-                                      true);
+               err = ovl_verify_upper(ofs, indexdir, upperpath->dentry, true);
                if (err)
                        pr_err("failed to verify index dir 'upper' xattr\n");
  
                if (!err)
                        err = ovl_indexdir_cleanup(ofs);
        }
-       if (err || !ofs->indexdir)
+       if (err || !indexdir)
                pr_warn("try deleting index dir or mounting with '-o index=off' to disable inodes index.\n");
  
  out:
@@@ -1406,7 -1403,7 +1403,7 @@@ int ovl_fill_super(struct super_block *
                        goto out_free_oe;
  
                /* Force r/o mount with no index dir */
-               if (!ofs->indexdir)
+               if (!ofs->workdir)
                        sb->s_flags |= SB_RDONLY;
        }
  
                goto out_free_oe;
  
        /* Show index=off in /proc/mounts for forced r/o mount */
-       if (!ofs->indexdir) {
+       if (!ofs->workdir) {
                ofs->config.index = false;
                if (ovl_upper_mnt(ofs) && ofs->config.nfs_export) {
                        pr_warn("NFS export requires an index dir, falling back to nfs_export=off.\n");
         * lead to unexpected results.
         */
        sb->s_iflags |= SB_I_NOUMASK;
 +      sb->s_iflags |= SB_I_EVM_UNSUPPORTED;
  
        err = -ENOMEM;
        root_dentry = ovl_get_root(sb, ctx->upper.dentry, oe);
@@@ -1502,10 -1498,14 +1499,10 @@@ static int __init ovl_init(void
        if (ovl_inode_cachep == NULL)
                return -ENOMEM;
  
 -      err = ovl_aio_request_cache_init();
 -      if (!err) {
 -              err = register_filesystem(&ovl_fs_type);
 -              if (!err)
 -                      return 0;
 +      err = register_filesystem(&ovl_fs_type);
 +      if (!err)
 +              return 0;
  
 -              ovl_aio_request_cache_destroy();
 -      }
        kmem_cache_destroy(ovl_inode_cachep);
  
        return err;
@@@ -1521,6 -1521,7 +1518,6 @@@ static void __exit ovl_exit(void
         */
        rcu_barrier();
        kmem_cache_destroy(ovl_inode_cachep);
 -      ovl_aio_request_cache_destroy();
  }
  
  module_init(ovl_init);
This page took 0.074478 seconds and 4 git commands to generate.