This relaxes uuid checks for overlay index feature. It is only possible in case there is only one filesystem for all the work/upper/lower directories and bare file handles from this backing filesystem are uniq. In case we have multiple filesystems here just fall back to normal "index=on".
This is needed when overlayfs is/was mounted in a container with index enabled (e.g.: to be able to resolve inotify watch file handles on it to paths in CRIU), and this container is copied and started alongside with the original one. This way the "copy" container can't have the same uuid on the superblock and mounting the overlayfs from it later would fail. (see https://jira.sw.ru/browse/PSBM-11961 for more info why it is needed) https://jira.sw.ru/browse/PSBM-108115 To mainstream: https://lkml.org/lkml/2020/9/23/565 Signed-off-by: Pavel Tikhomirov <ptikhomi...@virtuozzo.com> --- .../kernel-3.10.0-x86_64-debug-minimal.config | 1 + configs/kernel-3.10.0-x86_64-debug.config | 1 + configs/kernel-3.10.0-x86_64-minimal.config | 1 + configs/kernel-3.10.0-x86_64.config | 1 + fs/overlayfs/Kconfig | 16 ++++++ fs/overlayfs/export.c | 6 ++- fs/overlayfs/namei.c | 35 ++++++++---- fs/overlayfs/overlayfs.h | 23 +++++--- fs/overlayfs/ovl_entry.h | 2 +- fs/overlayfs/super.c | 54 ++++++++++++++----- 10 files changed, 106 insertions(+), 34 deletions(-) diff --git a/configs/kernel-3.10.0-x86_64-debug-minimal.config b/configs/kernel-3.10.0-x86_64-debug-minimal.config index b7fc84975c5e..6d0fce8947bb 100644 --- a/configs/kernel-3.10.0-x86_64-debug-minimal.config +++ b/configs/kernel-3.10.0-x86_64-debug-minimal.config @@ -3792,6 +3792,7 @@ CONFIG_OVERLAY_FS=y # CONFIG_OVERLAY_FS_REDIRECT_DIR is not set CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW=y CONFIG_OVERLAY_FS_INDEX=y +CONFIG_OVERLAY_FS_INDEX_NOUUID=y CONFIG_OVERLAY_FS_NFS_EXPORT=y # CONFIG_OVERLAY_FS_XINO_AUTO is not set CONFIG_OVERLAY_FS_DYNAMIC_RESOLVE_PATH_OPTIONS=y diff --git a/configs/kernel-3.10.0-x86_64-debug.config b/configs/kernel-3.10.0-x86_64-debug.config index f1f83f69aa0c..8b77ad652b23 100644 --- a/configs/kernel-3.10.0-x86_64-debug.config +++ b/configs/kernel-3.10.0-x86_64-debug.config @@ -5784,6 +5784,7 @@ CONFIG_OVERLAY_FS=m # CONFIG_OVERLAY_FS_REDIRECT_DIR is not set # CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW is not set CONFIG_OVERLAY_FS_INDEX=y +CONFIG_OVERLAY_FS_INDEX_NOUUID=y CONFIG_OVERLAY_FS_NFS_EXPORT=y # CONFIG_OVERLAY_FS_XINO_AUTO is not set CONFIG_GENERIC_ACL=y diff --git a/configs/kernel-3.10.0-x86_64-minimal.config b/configs/kernel-3.10.0-x86_64-minimal.config index 8dc256b1e4bc..879a9ad21c96 100644 --- a/configs/kernel-3.10.0-x86_64-minimal.config +++ b/configs/kernel-3.10.0-x86_64-minimal.config @@ -3793,6 +3793,7 @@ CONFIG_OVERLAY_FS=y # CONFIG_OVERLAY_FS_REDIRECT_DIR is not set CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW=y CONFIG_OVERLAY_FS_INDEX=y +CONFIG_OVERLAY_FS_INDEX_NOUUID=y CONFIG_OVERLAY_FS_NFS_EXPORT=y # CONFIG_OVERLAY_FS_XINO_AUTO is not set CONFIG_OVERLAY_FS_DYNAMIC_RESOLVE_PATH_OPTIONS=y diff --git a/configs/kernel-3.10.0-x86_64.config b/configs/kernel-3.10.0-x86_64.config index 8e285b0d31c7..8b91f73c5484 100644 --- a/configs/kernel-3.10.0-x86_64.config +++ b/configs/kernel-3.10.0-x86_64.config @@ -5783,6 +5783,7 @@ CONFIG_OVERLAY_FS=m # CONFIG_OVERLAY_FS_REDIRECT_DIR is not set # CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW is not set CONFIG_OVERLAY_FS_INDEX=y +CONFIG_OVERLAY_FS_INDEX_NOUUID=y CONFIG_OVERLAY_FS_NFS_EXPORT=y # CONFIG_OVERLAY_FS_XINO_AUTO is not set CONFIG_GENERIC_ACL=y diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig index 32e8195a0cbe..05dc2906d60d 100644 --- a/fs/overlayfs/Kconfig +++ b/fs/overlayfs/Kconfig @@ -60,6 +60,22 @@ config OVERLAY_FS_INDEX If unsure, say N. +config OVERLAY_FS_INDEX_NOUUID + bool "Overlayfs: relax uuid checks of inodes index feature" + depends on OVERLAY_FS + depends on OVERLAY_FS_INDEX + help + If this config option is enabled then overlay will skip uuid checks + for index lower to upper inode map, this only can be done if all + upper and lower directories are on the same filesystem where basic + fhandles are uniq. + + It is needed to overcome possible change of uuid on superblock of the + backing filesystem, e.g. when you copied the virtual disk and mount + both the copy of the disk and the original one at the same time. + + If unsure, say N. + config OVERLAY_FS_NFS_EXPORT bool "Overlayfs: turn on NFS export feature by default" depends on OVERLAY_FS diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 03acd05ba642..c32ba29c86fd 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c @@ -683,11 +683,12 @@ static struct dentry *ovl_upper_fh_to_d(struct super_block *sb, struct ovl_fs *ofs = sb->s_fs_info; struct dentry *dentry; struct dentry *upper; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; if (!ofs->upper_mnt) return ERR_PTR(-EACCES); - upper = ovl_decode_real_fh(fh, ofs->upper_mnt, true); + upper = ovl_decode_real_fh(fh, ofs->upper_mnt, true, nouuid); if (IS_ERR_OR_NULL(upper)) return upper; @@ -707,6 +708,7 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, struct dentry *index = NULL; struct inode *inode; int err; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; /* First lookup overlay inode in inode cache by origin fh */ err = ovl_check_origin_fh(ofs, fh, false, NULL, &stack); @@ -759,7 +761,7 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, goto out_err; } if (index) { - err = ovl_verify_origin(index, origin.dentry, false); + err = ovl_verify_origin(index, origin.dentry, false, nouuid); if (err) goto out_err; } diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 449596daab32..ee2f50501a16 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -181,7 +181,7 @@ static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name) } struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, - bool connected) + bool connected, bool nouuid) { struct dentry *real; int bytes; @@ -190,7 +190,7 @@ struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, * Make sure that the stored uuid matches the uuid of the lower * layer where file handle will be decoded. */ - if (!uuid_equal(&fh->uuid, (uuid_t *) &mnt->mnt_sb->s_uuid)) + if (!nouuid && !uuid_equal(&fh->uuid, (uuid_t *) &mnt->mnt_sb->s_uuid)) return NULL; bytes = (fh->len - offsetof(struct ovl_fh, fid)); @@ -338,10 +338,11 @@ int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, { struct dentry *origin = NULL; int i; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; for (i = 0; i < ofs->numlower; i++) { origin = ovl_decode_real_fh(fh, ofs->lower_layers[i].mnt, - connected); + connected, nouuid); if (origin) break; } @@ -406,7 +407,7 @@ static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry, * Return 0 on match, -ESTALE on mismatch, < 0 on error. */ static int ovl_verify_fh(struct dentry *dentry, const char *name, - const struct ovl_fh *fh) + const struct ovl_fh *fh, bool nouuid) { struct ovl_fh *ofh = ovl_get_fh(dentry, name); int err = 0; @@ -417,8 +418,14 @@ static int ovl_verify_fh(struct dentry *dentry, const char *name, if (IS_ERR(ofh)) return PTR_ERR(ofh); - if (fh->len != ofh->len || memcmp(fh, ofh, fh->len)) + if (fh->len != ofh->len) { err = -ESTALE; + } else { + if (nouuid && !uuid_equal(&fh->uuid, &ofh->uuid)) + ofh->uuid = fh->uuid; + if (memcmp(fh, ofh, fh->len)) + err = -ESTALE; + } kfree(ofh); return err; @@ -433,7 +440,8 @@ static int ovl_verify_fh(struct dentry *dentry, const char *name, * Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error. */ int ovl_verify_set_fh(struct dentry *dentry, const char *name, - struct dentry *real, bool is_upper, bool set) + struct dentry *real, bool is_upper, bool set, + bool nouuid) { struct inode *inode; struct ovl_fh *fh; @@ -446,7 +454,7 @@ int ovl_verify_set_fh(struct dentry *dentry, const char *name, goto fail; } - err = ovl_verify_fh(dentry, name, fh); + err = ovl_verify_fh(dentry, name, fh, nouuid); if (set && err == -ENODATA) err = ovl_do_setxattr(dentry, name, fh, fh->len, 0); if (err) @@ -469,6 +477,7 @@ struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index) { struct ovl_fh *fh; struct dentry *upper; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; if (!d_is_dir(index)) return dget(index); @@ -477,7 +486,7 @@ struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index) if (IS_ERR_OR_NULL(fh)) return ERR_CAST(fh); - upper = ovl_decode_real_fh(fh, ofs->upper_mnt, true); + upper = ovl_decode_real_fh(fh, ofs->upper_mnt, true, nouuid); kfree(fh); if (IS_ERR_OR_NULL(upper)) @@ -512,6 +521,7 @@ int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index) struct ovl_path *stack = &origin; struct dentry *upper = NULL; int err; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; if (!d_inode(index)) return 0; @@ -577,7 +587,7 @@ int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index) goto fail; } - err = ovl_verify_fh(upper, OVL_XATTR_ORIGIN, fh); + err = ovl_verify_fh(upper, OVL_XATTR_ORIGIN, fh, nouuid); dput(upper); if (err) goto fail; @@ -695,6 +705,7 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, struct qstr name; bool is_dir = d_is_dir(origin); int err; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; err = ovl_get_index_name(origin, &name); if (err) @@ -748,7 +759,7 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, } /* Verify that dir index 'upper' xattr points to upper dir */ - err = ovl_verify_upper(index, upper, false); + err = ovl_verify_upper(index, upper, false, nouuid); if (err) { if (err == -ESTALE) { pr_warn_ratelimited("overlayfs: suspected multiply redirected dir found (upper=%pd2, origin=%pd2, index=%pd2).\n", @@ -844,6 +855,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, .last = ofs->config.redirect_follow ? false : !poe->numlower, .redirect = NULL, }; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; if (dentry->d_name.len > ofs->namelen) return ERR_PTR(-ENAMETOOLONG); @@ -929,7 +941,8 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, * case, only verified origin is used for index lookup. */ if (upperdentry && !ctr && ovl_verify_lower(dentry->d_sb)) { - err = ovl_verify_origin(upperdentry, this, false); + err = ovl_verify_origin(upperdentry, this, false, + nouuid); if (err) { dput(this); break; diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 1b3a2c9d8a12..70529380d812 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -17,6 +17,12 @@ enum ovl_path_type { __OVL_PATH_ORIGIN = (1 << 2), }; +enum ovl_index_type { + OVL_INDEX_OFF = 0, + OVL_INDEX_ON, + OVL_INDEX_NOUUID, +}; + #define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER) #define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE) #define OVL_TYPE_ORIGIN(type) ((type) & __OVL_PATH_ORIGIN) @@ -277,11 +283,12 @@ static inline unsigned int ovl_xino_bits(struct super_block *sb) /* namei.c */ int ovl_check_fh_len(struct ovl_fh *fh, int fh_len); struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, - bool connected); + bool connected, bool nouuid); int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, struct dentry *upperdentry, struct ovl_path **stackp); int ovl_verify_set_fh(struct dentry *dentry, const char *name, - struct dentry *real, bool is_upper, bool set); + struct dentry *real, bool is_upper, bool set, + bool nouuid); struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); int ovl_get_index_name(struct dentry *origin, struct qstr *name); @@ -294,15 +301,19 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, bool ovl_lower_positive(struct dentry *dentry); static inline int ovl_verify_origin(struct dentry *upper, - struct dentry *origin, bool set) + struct dentry *origin, bool set, + bool nouuid) { - return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set); + return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set, + nouuid); } static inline int ovl_verify_upper(struct dentry *index, - struct dentry *upper, bool set) + struct dentry *upper, bool set, + bool nouuid) { - return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set); + return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set, + nouuid); } /* readdir.c */ diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h index a2738e950f20..2a51c7894d7b 100644 --- a/fs/overlayfs/ovl_entry.h +++ b/fs/overlayfs/ovl_entry.h @@ -16,7 +16,7 @@ struct ovl_config { bool redirect_dir; bool redirect_follow; const char *redirect_mode; - bool index; + int index; bool nfs_export; int xino; }; diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 6b6227b9bff3..fcb3f7aae217 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -42,10 +42,12 @@ module_param_named(redirect_always_follow, ovl_redirect_always_follow, MODULE_PARM_DESC(ovl_redirect_always_follow, "Follow redirects even if redirect_dir feature is turned off"); -static bool ovl_index_def = IS_ENABLED(CONFIG_OVERLAY_FS_INDEX); -module_param_named(index, ovl_index_def, bool, 0644); +static int ovl_index_def = IS_ENABLED(CONFIG_OVERLAY_FS_INDEX_NOUUID) ? + OVL_INDEX_NOUUID : + IS_ENABLED(CONFIG_OVERLAY_FS_INDEX); +module_param_named(index, ovl_index_def, int, 0644); MODULE_PARM_DESC(ovl_index_def, - "Default to on or off for the inodes index feature"); + "Default to on, off or nouuid for the inodes index feature"); static bool ovl_nfs_export_def = IS_ENABLED(CONFIG_OVERLAY_FS_NFS_EXPORT); module_param_named(nfs_export, ovl_nfs_export_def, bool, 0644); @@ -414,8 +416,18 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry) seq_puts(m, ",default_permissions"); if (strcmp(ofs->config.redirect_mode, ovl_redirect_mode_def()) != 0) seq_printf(m, ",redirect_dir=%s", ofs->config.redirect_mode); - if (ofs->config.index != ovl_index_def) - seq_printf(m, ",index=%s", ofs->config.index ? "on" : "off"); + if (ofs->config.index != ovl_index_def) { + switch (ofs->config.index) { + case OVL_INDEX_OFF: + seq_puts(m, ",index=off"); + break; + case OVL_INDEX_NOUUID: + seq_puts(m, ",index=nouuid"); + break; + default: + seq_puts(m, ",index=on"); + } + } if (ofs->config.nfs_export != ovl_nfs_export_def) seq_printf(m, ",nfs_export=%s", ofs->config.nfs_export ? "on" : "off"); @@ -453,6 +465,7 @@ enum { OPT_REDIRECT_DIR, OPT_INDEX_ON, OPT_INDEX_OFF, + OPT_INDEX_NOUUID, OPT_NFS_EXPORT_ON, OPT_NFS_EXPORT_OFF, OPT_XINO_ON, @@ -469,6 +482,7 @@ static const match_table_t ovl_tokens = { {OPT_REDIRECT_DIR, "redirect_dir=%s"}, {OPT_INDEX_ON, "index=on"}, {OPT_INDEX_OFF, "index=off"}, + {OPT_INDEX_NOUUID, "index=nouuid"}, {OPT_NFS_EXPORT_ON, "nfs_export=on"}, {OPT_NFS_EXPORT_OFF, "nfs_export=off"}, {OPT_XINO_ON, "xino=on"}, @@ -573,11 +587,15 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config) break; case OPT_INDEX_ON: - config->index = true; + config->index = OVL_INDEX_ON; break; case OPT_INDEX_OFF: - config->index = false; + config->index = OVL_INDEX_OFF; + break; + + case OPT_INDEX_NOUUID: + config->index = OVL_INDEX_NOUUID; break; case OPT_NFS_EXPORT_ON: @@ -819,7 +837,7 @@ static int ovl_lower_dir(const char *name, struct path *path, fh_type = ovl_can_decode_fh(path->dentry->d_sb); if ((ofs->config.nfs_export || (ofs->config.index && ofs->config.upperdir)) && !fh_type) { - ofs->config.index = false; + ofs->config.index = OVL_INDEX_OFF; ofs->config.nfs_export = false; pr_warn("overlayfs: fs on '%s' does not support file handles, falling back to index=off,nfs_export=off.\n", name); @@ -1092,7 +1110,7 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workbasepath) err = ovl_do_setxattr(ofs->workdir, OVL_XATTR_OPAQUE, "0", 1, 0); if (err) { ofs->noxattr = true; - ofs->config.index = false; + ofs->config.index = OVL_INDEX_OFF; pr_warn("overlayfs: upper fs does not support xattr, falling back to index=off.\n"); err = 0; } else { @@ -1102,7 +1120,7 @@ static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workbasepath) /* Check if upper/work fs supports file handles */ fh_type = ovl_can_decode_fh(ofs->workdir->d_sb); if (ofs->config.index && !fh_type) { - ofs->config.index = false; + ofs->config.index = OVL_INDEX_OFF; pr_warn("overlayfs: upper fs does not support file handles, falling back to index=off.\n"); } @@ -1163,6 +1181,7 @@ static int ovl_get_indexdir(struct ovl_fs *ofs, struct ovl_entry *oe, { struct vfsmount *mnt = ofs->upper_mnt; int err; + bool nouuid = ofs->config.index == OVL_INDEX_NOUUID; err = mnt_want_write(mnt); if (err) @@ -1170,7 +1189,7 @@ static int ovl_get_indexdir(struct ovl_fs *ofs, struct ovl_entry *oe, /* Verify lower root is upper root origin */ err = ovl_verify_origin(upperpath->dentry, oe->lowerstack[0].dentry, - true); + true, nouuid); if (err) { pr_err("overlayfs: failed to verify upper root origin\n"); goto out; @@ -1188,11 +1207,13 @@ static int ovl_get_indexdir(struct ovl_fs *ofs, struct ovl_entry *oe, */ if (ovl_check_origin_xattr(ofs->indexdir)) { err = ovl_verify_set_fh(ofs->indexdir, OVL_XATTR_ORIGIN, - upperpath->dentry, true, false); + upperpath->dentry, true, false, + nouuid); if (err) pr_err("overlayfs: failed to verify index dir 'origin' xattr\n"); } - err = ovl_verify_upper(ofs->indexdir, upperpath->dentry, true); + err = ovl_verify_upper(ofs->indexdir, upperpath->dentry, true, + nouuid); if (err) pr_err("overlayfs: failed to verify index dir 'upper' xattr\n"); @@ -1498,9 +1519,14 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) } + if (ofs->config.index == OVL_INDEX_NOUUID && ofs->numlowerfs) { + pr_warn("overlayfs: index=nouuid requires an single fs for lower and upper, falling back to index=on.\n"); + ofs->config.index = OVL_INDEX_ON; + } + /* Show index=off in /proc/mounts for forced r/o mount */ if (!ofs->indexdir) { - ofs->config.index = false; + ofs->config.index = OVL_INDEX_OFF; if (ofs->upper_mnt && ofs->config.nfs_export) { pr_warn("overlayfs: NFS export requires an index dir, falling back to nfs_export=off.\n"); ofs->config.nfs_export = false; -- 2.26.2 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel