All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: linux-unionfs@vger.kernel.org
Cc: miklos@szeredi.hu, amir73il@gmail.com, vgoyal@redhat.com
Subject: [PATCH v15 04/30] ovl: Provide a mount option metacopy=on/off for metadata copyup
Date: Mon,  7 May 2018 13:40:36 -0400	[thread overview]
Message-ID: <20180507174102.24086-5-vgoyal@redhat.com> (raw)
In-Reply-To: <20180507174102.24086-1-vgoyal@redhat.com>

By default metadata only copy up is disabled. Provide a mount option so
that users can choose one way or other.

Also provide a kernel config and module option to enable/disable
metacopy feature.

metacopy feature requires redirect_dir=on when upper is present. Otherwise,
it requires redirect_dir=follow atleast.

As of now, metacopy does not work with nfs_export=on. So if both metacopy=on
and nfs_export=on then nfs_export is disabled.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 Documentation/filesystems/overlayfs.txt | 30 ++++++++++++++++++++-
 fs/overlayfs/Kconfig                    | 19 ++++++++++++++
 fs/overlayfs/ovl_entry.h                |  1 +
 fs/overlayfs/super.c                    | 46 ++++++++++++++++++++++++++++++---
 4 files changed, 92 insertions(+), 4 deletions(-)

diff --git a/Documentation/filesystems/overlayfs.txt b/Documentation/filesystems/overlayfs.txt
index 97eae826adf9..35f9b7f40aff 100644
--- a/Documentation/filesystems/overlayfs.txt
+++ b/Documentation/filesystems/overlayfs.txt
@@ -262,6 +262,30 @@ rightmost one and going left.  In the above example lower1 will be the
 top, lower2 the middle and lower3 the bottom layer.
 
 
+Metadata only copy up
+--------------------
+
+When metadata only copy up feature is enabled, overlayfs will only copy
+up metadata (as opposed to whole file), when a metadata specific operation
+like chown/chmod is performed. Full file will be copied up later when
+file is opened for WRITE operation.
+
+In other words, this is delayed data copy up operation and data is copied
+up when there is a need to actually modify data.
+
+There are multiple ways to enable/disable this feature. A config option
+CONFIG_OVERLAY_FS_METACOPY can be set/unset to enable/disable this feature
+by default. Or one can enable/disable it at module load time with module
+parameter metacopy=on/off. Lastly, there is also a per mount option
+metacopy=on/off to enable/disable this feature per mount.
+
+Do not use metacopy=on with untrusted upper/lower directories. Otherwise
+it is possible that an attacker can create an handcrafted file with
+appropriate REDIRECT and METACOPY xattrs, and gain access to file on lower
+pointed by REDIRECT. This should not be possible on local system as setting
+"trusted." xattrs will require CAP_SYS_ADMIN. But it should be possible
+for untrusted layers like from a pen drive.
+
 Sharing and copying layers
 --------------------------
 
@@ -280,7 +304,7 @@ though it will not result in a crash or deadlock.
 Mounting an overlay using an upper layer path, where the upper layer path
 was previously used by another mounted overlay in combination with a
 different lower layer path, is allowed, unless the "inodes index" feature
-is enabled.
+or "metadata only copy up" feature is enabled.
 
 With the "inodes index" feature, on the first time mount, an NFS file
 handle of the lower layer root directory, along with the UUID of the lower
@@ -293,6 +317,10 @@ lower root origin, mount will fail with ESTALE.  An overlayfs mount with
 does not support NFS export, lower filesystem does not have a valid UUID or
 if the upper filesystem does not support extended attributes.
 
+For "metadata only copy up" feature there is no verification mechanism at
+mount time. So if same upper is mouted with different set of lower, mount
+probably will succeed but expect the unexpected later on. So don't do it.
+
 It is quite a common practice to copy overlay layers to a different
 directory tree on the same or different underlying filesystem, and even
 to a different machine.  With the "inodes index" feature, trying to mount
diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig
index 991c0a5a0e00..2e75a35e2726 100644
--- a/fs/overlayfs/Kconfig
+++ b/fs/overlayfs/Kconfig
@@ -64,6 +64,7 @@ config OVERLAY_FS_NFS_EXPORT
 	bool "Overlayfs: turn on NFS export feature by default"
 	depends on OVERLAY_FS
 	depends on OVERLAY_FS_INDEX
+	depends on !OVERLAY_FS_METACOPY
 	help
 	  If this config option is enabled then overlay filesystems will use
 	  the inodes index dir to decode overlay NFS file handles by default.
@@ -124,3 +125,21 @@ config OVERLAY_FS_COPY_UP_SHARED
 	 To get a maximally backward compatible kernel, disable this option.
 
 	 If unsure, say N.
+
+config OVERLAY_FS_METACOPY
+	bool "Overlayfs: turn on metadata only copy up feature by default"
+	depends on OVERLAY_FS
+	select OVERLAY_FS_REDIRECT_DIR
+	help
+	  If this config option is enabled then overlay filesystems will
+	  copy up only metadata where appropriate and data copy up will
+	  happen when a file is opended for WRITE operation. It is still
+	  possible to turn off this feature globally with the "metacopy=off"
+	  module option or on a filesystem instance basis with the
+	  "metacopy=off" mount option.
+
+	  Note, that this feature is not backward compatible.  That is,
+	  mounting an overlay which has metacopy only inodes on a kernel
+	  that doesn't support this feature will have unexpected results.
+
+	  If unsure, say N.
diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
index 07b8cb2785c8..422896406048 100644
--- a/fs/overlayfs/ovl_entry.h
+++ b/fs/overlayfs/ovl_entry.h
@@ -20,6 +20,7 @@ struct ovl_config {
 	bool nfs_export;
 	bool copy_up_shared;
 	int xino;
+	bool metacopy;
 };
 
 struct ovl_sb {
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 492d534058ae..2c5cc94e1c5f 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -70,6 +70,11 @@ static void ovl_entry_stack_free(struct ovl_entry *oe)
 		dput(oe->lowerstack[i].dentry);
 }
 
+static bool ovl_metacopy_def = IS_ENABLED(CONFIG_OVERLAY_FS_METACOPY);
+module_param_named(metacopy, ovl_metacopy_def, bool, 0644);
+MODULE_PARM_DESC(ovl_metacopy_def,
+		 "Default to on or off for the metadata only copy up feature");
+
 static void ovl_dentry_release(struct dentry *dentry)
 {
 	struct ovl_entry *oe = dentry->d_fsdata;
@@ -356,6 +361,9 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
 	if (ofs->config.copy_up_shared != ovl_copy_up_shared_def)
 		seq_printf(m, ",copy_up_shared=%s",
 			   ofs->config.copy_up_shared ? "on" : "off");
+	if (ofs->config.metacopy != ovl_metacopy_def)
+		seq_printf(m, ",metacopy=%s",
+			   ofs->config.metacopy ? "on" : "off");
 	return 0;
 }
 
@@ -395,6 +403,8 @@ enum {
 	OPT_XINO_AUTO,
 	OPT_COPY_UP_SHARED_ON,
 	OPT_COPY_UP_SHARED_OFF,
+	OPT_METACOPY_ON,
+	OPT_METACOPY_OFF,
 	OPT_ERR,
 };
 
@@ -413,6 +423,8 @@ static const match_table_t ovl_tokens = {
 	{OPT_XINO_AUTO,			"xino=auto"},
 	{OPT_COPY_UP_SHARED_ON,		"copy_up_shared=on"},
 	{OPT_COPY_UP_SHARED_OFF,	"copy_up_shared=off"},
+	{OPT_METACOPY_ON,		"metacopy=on"},
+	{OPT_METACOPY_OFF,		"metacopy=off"},
 	{OPT_ERR,			NULL}
 };
 
@@ -465,6 +477,7 @@ static int ovl_parse_redirect_mode(struct ovl_config *config, const char *mode)
 static int ovl_parse_opt(char *opt, struct ovl_config *config)
 {
 	char *p;
+	int err;
 
 	config->redirect_mode = kstrdup(ovl_redirect_mode_def(), GFP_KERNEL);
 	if (!config->redirect_mode)
@@ -547,6 +560,14 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
 			config->copy_up_shared = false;
 			break;
 
+		case OPT_METACOPY_ON:
+			config->metacopy = true;
+			break;
+
+		case OPT_METACOPY_OFF:
+			config->metacopy = false;
+			break;
+
 		default:
 			pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p);
 			return -EINVAL;
@@ -561,7 +582,20 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
 		config->workdir = NULL;
 	}
 
-	return ovl_parse_redirect_mode(config, config->redirect_mode);
+	err = ovl_parse_redirect_mode(config, config->redirect_mode);
+	if (err)
+		return err;
+
+	/* metacopy feature with upper requires redirect_dir=on */
+	if (config->upperdir && config->metacopy && !config->redirect_dir) {
+		pr_warn("overlayfs: metadata only copy up requires \"redirect_dir=on\", falling back to metacopy=off.\n");
+		config->metacopy = false;
+	} else if (config->metacopy && !config->redirect_follow) {
+		pr_warn("overlayfs: metadata only copy up requires \"redirect_dir=follow\" on non-upper mount, falling back to metacopy=off.\n");
+		config->metacopy = false;
+	}
+
+	return 0;
 }
 
 #define OVL_WORKDIR_NAME "work"
@@ -1035,7 +1069,8 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath)
 	if (err) {
 		ofs->noxattr = true;
 		ofs->config.index = false;
-		pr_warn("overlayfs: upper fs does not support xattr, falling back to index=off.\n");
+		ofs->config.metacopy = false;
+		pr_warn("overlayfs: upper fs does not support xattr, falling back to index=off and metacopy=off.\n");
 		err = 0;
 	} else {
 		vfs_removexattr(ofs->workdir, OVL_XATTR_OPAQUE);
@@ -1057,7 +1092,6 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath)
 		pr_warn("overlayfs: NFS export requires \"index=on\", falling back to nfs_export=off.\n");
 		ofs->config.nfs_export = false;
 	}
-
 out:
 	mnt_drop_write(mnt);
 	return err;
@@ -1369,6 +1403,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 	ofs->config.nfs_export = ovl_nfs_export_def;
 	ofs->config.xino = ovl_xino_def();
 	ofs->config.copy_up_shared = ovl_copy_up_shared_def;
+	ofs->config.metacopy = ovl_metacopy_def;
 	err = ovl_parse_opt((char *) data, &ofs->config);
 	if (err)
 		goto out_err;
@@ -1439,6 +1474,11 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 		}
 	}
 
+	if (ofs->config.metacopy && ofs->config.nfs_export) {
+		pr_warn("overlayfs: NFS export is not supported with metadata only copy up, falling back to nfs_export=off.\n");
+		ofs->config.nfs_export = false;
+	}
+
 	if (ofs->config.nfs_export)
 		sb->s_export_op = &ovl_export_operations;
 
-- 
2.13.6

  parent reply	other threads:[~2018-05-07 17:40 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-07 17:40 [PATCH v15 00/30] overlayfs: Delayed copy up of data Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 01/30] ovl: Pass argument to ovl_get_inode() in a structure Vivek Goyal
2018-05-07 19:26   ` Amir Goldstein
2018-05-07 20:37     ` Vivek Goyal
2018-05-08  4:45       ` Amir Goldstein
2018-05-08 13:45     ` Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 02/30] ovl: Initialize ovl_inode->redirect in ovl_get_inode() Vivek Goyal
2018-05-08 13:56   ` Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 03/30] ovl: Move the copy up helpers to copy_up.c Vivek Goyal
2018-05-07 17:40 ` Vivek Goyal [this message]
2018-05-07 17:40 ` [PATCH v15 05/30] ovl: During copy up, first copy up metadata and then data Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 06/30] ovl: Copy up only metadata during copy up where it makes sense Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 07/30] ovl: Add helper ovl_already_copied_up() Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 08/30] ovl: A new xattr OVL_XATTR_METACOPY for file on upper Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 09/30] ovl: Use out_err instead of out_nomem Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 10/30] ovl: Modify ovl_lookup() and friends to lookup metacopy dentry Vivek Goyal
2018-05-07 19:14   ` Amir Goldstein
2018-05-10  9:19   ` Miklos Szeredi
2018-05-10  9:36     ` Miklos Szeredi
2018-05-10  9:52       ` Miklos Szeredi
2018-05-10 13:17       ` Vivek Goyal
2018-05-10 15:32       ` Vivek Goyal
2018-05-10 20:21         ` Miklos Szeredi
2018-05-10 13:14     ` Vivek Goyal
2018-05-10 14:43       ` Amir Goldstein
2018-05-10 19:42         ` Vivek Goyal
2018-05-10 19:39     ` Vivek Goyal
2018-05-10 20:13       ` Miklos Szeredi
2018-05-11  7:29         ` Miklos Szeredi
2018-05-11  7:52           ` Amir Goldstein
2018-05-11  8:13             ` Miklos Szeredi
2018-05-11 12:28               ` Vivek Goyal
2018-05-11 14:30   ` Vivek Goyal
2018-05-11 15:05     ` Amir Goldstein
2018-05-11 15:14       ` Vivek Goyal
2018-05-11 15:52   ` Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 11/30] ovl: Copy up meta inode data from lowest data inode Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 12/30] ovl: Add helper ovl_dentry_lowerdata() to get lower data dentry Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 13/30] ovl: Add an helper to get real " Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 14/30] ovl: Fix ovl_getattr() to get number of blocks from lower Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 15/30] ovl: Store lower data inode in ovl_inode Vivek Goyal
2018-05-07 18:59   ` Amir Goldstein
2018-05-08 13:47     ` Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 16/30] ovl: Add helper ovl_inode_real_data() Vivek Goyal
2018-05-07 18:18   ` Amir Goldstein
2018-05-07 17:40 ` [PATCH v15 17/30] ovl: Open file with data except for the case of fsync Vivek Goyal
2018-05-07 19:47   ` Amir Goldstein
2018-05-07 20:59     ` Vivek Goyal
2018-05-08  5:26       ` Amir Goldstein
2018-05-08 12:50         ` Vivek Goyal
2018-05-08 14:14           ` Amir Goldstein
2018-05-08 14:26             ` Vivek Goyal
2018-05-08 15:04               ` Amir Goldstein
2018-05-07 17:40 ` [PATCH v15 18/30] ovl: Do not expose metacopy only dentry from d_real() Vivek Goyal
2018-05-07 19:39   ` Amir Goldstein
2018-05-07 17:40 ` [PATCH v15 19/30] ovl: Move some dir related ovl_lookup_single() code in else block Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 20/30] ovl: Check redirects for metacopy files Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 21/30] ovl: Treat metacopy dentries as type OVL_PATH_MERGE Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 22/30] ovl: Add an inode flag OVL_CONST_INO Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 23/30] ovl: Do not set dentry type ORIGIN for broken hardlinks Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 24/30] ovl: Set redirect on metacopy files upon rename Vivek Goyal
2018-05-07 18:21   ` Amir Goldstein
2018-05-07 17:40 ` [PATCH v15 25/30] ovl: Set redirect on upper inode when it is linked Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 26/30] ovl: Check redirect on index as well Vivek Goyal
2018-05-07 18:43   ` Amir Goldstein
2018-05-08 12:58     ` Vivek Goyal
2018-05-07 17:40 ` [PATCH v15 27/30] ovl: Disbale metacopy for MAP_SHARED mmap() Vivek Goyal
2018-05-07 17:41 ` [PATCH v15 28/30] ovl: Do not do metadata only copy-up for truncate operation Vivek Goyal
2018-05-07 17:41 ` [PATCH v15 29/30] ovl: Do not do metacopy only for ioctl modifying file attr Vivek Goyal
2018-05-07 17:41 ` [PATCH v15 30/30] ovl: Enable metadata only feature Vivek Goyal
2018-05-07 18:10 ` [PATCH v15 00/30] overlayfs: Delayed copy up of data Amir Goldstein
2018-05-07 18:24   ` Vivek Goyal
2018-05-07 18:33     ` Amir Goldstein
2018-05-07 19:14       ` Vivek Goyal
2018-05-08 13:42 ` Vivek Goyal
2018-05-08 14:16   ` Amir Goldstein
2018-05-23 20:00     ` Vivek Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180507174102.24086-5-vgoyal@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.