]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ovl: relax redirect/metacopy requirements for lower -> data redirect
authorMiklos Szeredi <mszeredi@redhat.com>
Fri, 7 Feb 2025 16:12:06 +0000 (17:12 +0100)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 30 Apr 2025 08:55:27 +0000 (10:55 +0200)
Allow the special case of a redirect from a lower layer to a data layer
without having to turn on metacopy.  This makes the feature work with
userxattr, which in turn allows data layers to be usable in user
namespaces.

Minimize the risk by only enabling redirect from a single lower layer to a
data layer iff a data layer is specified.  The only way to access a data
layer is to enable this, so there's really no reason not to enable this.

This can be used safely if the lower layer is read-only and the
user.overlay.redirect xattr cannot be modified.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Documentation/filesystems/overlayfs.rst
fs/overlayfs/namei.c
fs/overlayfs/params.c

index 2db379b4b31eee0e27687918b45eb937c8948538..4133a336486d503a65fe4518569509a54e875759 100644 (file)
@@ -443,6 +443,13 @@ Only the data of the files in the "data-only" lower layers may be visible
 when a "metacopy" file in one of the lower layers above it, has a "redirect"
 to the absolute path of the "lower data" file in the "data-only" lower layer.
 
+Instead of explicitly enabling "metacopy=on" it is sufficient to specify at
+least one data-only layer to enable redirection of data to a data-only layer.
+In this case other forms of metacopy are rejected.  Note: this way data-only
+layers may be used toghether with "userxattr", in which case careful attention
+must be given to privileges needed to change the "user.overlay.redirect" xattr
+to prevent misuse.
+
 Since kernel version v6.8, "data-only" lower layers can also be added using
 the "datadir+" mount options and the fsconfig syscall from new mount api.
 For example::
index f010e74566685489595c2276caef0bfba4fc6cd3..d489e80feb6f3a1622c0788243e4d25a45d185f4 100644 (file)
@@ -1066,6 +1066,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
        unsigned int ctr = 0;
        struct inode *inode = NULL;
        bool upperopaque = false;
+       bool check_redirect = (ovl_redirect_follow(ofs) || ofs->numdatalayer);
        struct dentry *this;
        unsigned int i;
        int err;
@@ -1078,7 +1079,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                .is_dir = false,
                .opaque = false,
                .stop = false,
-               .last = ovl_redirect_follow(ofs) ? false : !ovl_numlower(poe),
+               .last = check_redirect ? false : !ovl_numlower(poe),
                .redirect = NULL,
                .upperredirect = NULL,
                .metacopy = 0,
@@ -1146,7 +1147,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                        goto out_put;
                }
 
-               if (!ovl_redirect_follow(ofs))
+               if (!check_redirect)
                        d.last = i == ovl_numlower(poe) - 1;
                else if (d.is_dir || !ofs->numdatalayer)
                        d.last = lower.layer->idx == ovl_numlower(roe);
@@ -1221,15 +1222,16 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                }
        }
 
-       if (!ovl_check_follow_redirect(&d)) {
-               err = -EPERM;
-               goto out_put;
-       }
-
-       /* Defer lookup of lowerdata in data-only layers to first access */
+       /*
+        * Defer lookup of lowerdata in data-only layers to first access.
+        * Don't require redirect=follow and metacopy=on in this case.
+        */
        if (d.metacopy && ctr && ofs->numdatalayer && d.absolute_redirect) {
                d.metacopy = 0;
                ctr++;
+       } else if (!ovl_check_follow_redirect(&d)) {
+               err = -EPERM;
+               goto out_put;
        }
 
        /*
index 6759f7d040c89d3b3c01572579c854a900411157..2468b436bb13dc239eac34303875cd11c228e221 100644 (file)
@@ -1025,11 +1025,6 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
                 */
        }
 
-       if (ctx->nr_data > 0 && !config->metacopy) {
-               pr_err("lower data-only dirs require metacopy support.\n");
-               return -EINVAL;
-       }
-
        return 0;
 }