All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] overlay: always follow metacopy into data-only layers
@ 2026-11-05 14:31 Giuseppe Scrivano
  2026-11-06  6:21 ` Amir Goldstein
  0 siblings, 1 reply; 6+ messages in thread
From: Giuseppe Scrivano @ 2026-11-05 14:31 UTC (permalink / raw)
  To: linux-unionfs

A metacopy file with an absolute redirect to a data-only layer is followed
without metacopy=on and redirect_dir=on only when it is in the last lower
layer.  In any other lower layer, the next iteration of the loop in
ovl_lookup_layers() calls ovl_check_follow_redirect() with d->metacopy set
and fails with -EPERM.

A mount with userxattr cannot have metacopy=on and redirect_dir=on, so a
user namespace mount that stacks several metadata-only layers over a
data-only layer can use the metacopy files of the last lower layer only:

  mount -t overlay none -o userxattr,lowerdir+=l3,lowerdir+=l2,\
        lowerdir+=l1,datadir+=data,upperdir=u,workdir=w m
  cat m/low   # metacopy file in l1: works
  cat m/mid   # metacopy file in l2: Operation not permitted

Skip the check inside the loop for a metacopy file of a lower layer with an
absolute redirect, on a mount that has data-only layers.  The lookup of the
data stays lazy and happens only in the data-only layers.  A metacopy file
or a redirect in the upper layer is still refused.  With metacopy=on and
redirect_dir=on the loop already continues after such a file, so only
mounts that failed with -EPERM are affected.

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
---
 fs/overlayfs/namei.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index ca899fdfaafd..02c64a5652a0 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -1087,6 +1087,14 @@ struct ovl_lookup_ctx {
 	unsigned int ctr;
 };
 
+/* A metacopy file of a lower layer whose lowerdata is in a data-only layer */
+static bool ovl_is_datalayer_redirect(struct ovl_lookup_ctx *ctx,
+				      struct ovl_lookup_data *d)
+{
+	return d->metacopy && ctx->ctr && OVL_FS(d->sb)->numdatalayer &&
+	       d->absolute_redirect;
+}
+
 static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data *d)
 {
 	struct dentry *dentry = ctx->dentry;
@@ -1154,7 +1162,8 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data
 	for (i = 0; !d->stop && i < ovl_numlower(poe); i++) {
 		struct ovl_path lower = ovl_lowerstack(poe)[i];
 
-		if (!ovl_check_follow_redirect(d)) {
+		if (!ovl_is_datalayer_redirect(ctx, d) &&
+		    !ovl_check_follow_redirect(d)) {
 			err = -EPERM;
 			return err;
 		}
@@ -1238,7 +1247,7 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data
 	 * 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 && ctx->ctr && ofs->numdatalayer && d->absolute_redirect) {
+	if (ovl_is_datalayer_redirect(ctx, d)) {
 		d->metacopy = 0;
 		ctx->ctr++;
 	} else if (!ovl_check_follow_redirect(d)) {
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-06 14:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 14:31 [RFC][PATCH] overlay: always follow metacopy into data-only layers Giuseppe Scrivano
2026-11-06  6:21 ` Amir Goldstein
2026-11-06  9:40   ` Giuseppe Scrivano
2026-11-06 12:25     ` Amir Goldstein
2026-11-06 13:32       ` Giuseppe Scrivano
2026-11-06 14:52         ` Amir Goldstein

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.