Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 227701e0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull overlayfs fixes from Miklos Szeredi:

 - fix incomplete syncing of filesystem

 - fix regression in readdir on ovl over 9p

 - only follow redirects when needed

 - misc fixes and cleanups

* 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs:
  ovl: fix overlay: warning prefix
  ovl: Use PTR_ERR_OR_ZERO()
  ovl: Sync upper dirty data when syncing overlayfs
  ovl: update ctx->pos on impure dir iteration
  ovl: Pass ovl_get_nlink() parameters in right order
  ovl: don't follow redirects if redirect_dir=off
parents 06f976ec da2e6b7e
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -156,6 +156,40 @@ handle it in two different ways:
   root of the overlay.  Finally the directory is moved to the new
   location.

There are several ways to tune the "redirect_dir" feature.

Kernel config options:

- OVERLAY_FS_REDIRECT_DIR:
    If this is enabled, then redirect_dir is turned on by  default.
- OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW:
    If this is enabled, then redirects are always followed by default. Enabling
    this results in a less secure configuration.  Enable this option only when
    worried about backward compatibility with kernels that have the redirect_dir
    feature and follow redirects even if turned off.

Module options (can also be changed through /sys/module/overlay/parameters/*):

- "redirect_dir=BOOL":
    See OVERLAY_FS_REDIRECT_DIR kernel config option above.
- "redirect_always_follow=BOOL":
    See OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW kernel config option above.
- "redirect_max=NUM":
    The maximum number of bytes in an absolute redirect (default is 256).

Mount options:

- "redirect_dir=on":
    Redirects are enabled.
- "redirect_dir=follow":
    Redirects are not created, but followed.
- "redirect_dir=off":
    Redirects are not created and only followed if "redirect_always_follow"
    feature is enabled in the kernel/module config.
- "redirect_dir=nofollow":
    Redirects are not created and not followed (equivalent to "redirect_dir=off"
    if "redirect_always_follow" feature is not enabled).

Non-directories
---------------

+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,16 @@ config OVERLAY_FS_REDIRECT_DIR
	  an overlay which has redirects on a kernel that doesn't support this
	  feature will have unexpected results.

config OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW
	bool "Overlayfs: follow redirects even if redirects are turned off"
	default y
	depends on OVERLAY_FS
	help
	  Disable this to get a possibly more secure configuration, but that
	  might not be backward compatible with previous kernels.

	  For more information, see Documentation/filesystems/overlayfs.txt

config OVERLAY_FS_INDEX
	bool "Overlayfs: turn on inodes index feature by default"
	depends on OVERLAY_FS
+2 −1
Original line number Diff line number Diff line
@@ -887,7 +887,8 @@ static int ovl_set_redirect(struct dentry *dentry, bool samedir)
		spin_unlock(&dentry->d_lock);
	} else {
		kfree(redirect);
		pr_warn_ratelimited("overlay: failed to set redirect (%i)\n", err);
		pr_warn_ratelimited("overlayfs: failed to set redirect (%i)\n",
				    err);
		/* Fall back to userspace copy-up */
		err = -EXDEV;
	}
+17 −1
Original line number Diff line number Diff line
@@ -435,7 +435,7 @@ int ovl_verify_index(struct dentry *index, struct ovl_path *lower,

	/* Check if index is orphan and don't warn before cleaning it */
	if (d_inode(index)->i_nlink == 1 &&
	    ovl_get_nlink(index, origin.dentry, 0) == 0)
	    ovl_get_nlink(origin.dentry, index, 0) == 0)
		err = -ENOENT;

	dput(origin.dentry);
@@ -681,6 +681,22 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
		if (d.stop)
			break;

		/*
		 * Following redirects can have security consequences: it's like
		 * a symlink into the lower layer without the permission checks.
		 * This is only a problem if the upper layer is untrusted (e.g
		 * comes from an USB drive).  This can allow a non-readable file
		 * or directory to become readable.
		 *
		 * Only following redirects when redirects are enabled disables
		 * this attack vector when not necessary.
		 */
		err = -EPERM;
		if (d.redirect && !ofs->config.redirect_follow) {
			pr_warn_ratelimited("overlay: refusing to follow redirect for (%pd2)\n", dentry);
			goto out_put;
		}

		if (d.redirect && d.redirect[0] == '/' && poe != roe) {
			poe = roe;

+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode)
{
	struct dentry *ret = vfs_tmpfile(dentry, mode, 0);
	int err = IS_ERR(ret) ? PTR_ERR(ret) : 0;
	int err = PTR_ERR_OR_ZERO(ret);

	pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err);
	return ret;
Loading