Skip to contentSkip to conversation

FAILED: patch "[PATCH] ovl: fix leak of lowerdata redirect on ovl_get_inode()" failed to apply to 6.6-stable tree

PATCH New [email protected] 2 participants 2 messages Nov 25 – Nov 26

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x f1b7e5534854043077bb72afc8d87ad1e0b283e0
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112540-ipod-frantic-30d3@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From f1b7e5534854043077bb72afc8d87ad1e0b283e0 Mon Sep 17 00:00:00 2001
From: Amir Goldstein <[email protected]>
Date: Sat, 7 Nov 2026 15:48:36 +0100
Subject: [PATCH] ovl: fix leak of lowerdata redirect on ovl_get_inode()
failure

ovl_lookup_layers() moves d->redirect into oip.lowerdata_redirect and clears d->redirect before calling ovl_get_inode(). When ovl_get_inode() fails, it does not free oip.lowerdata_redirect, and ovl_lookup() frees the already cleared d->redirect, so the lowerdata redirect string is leaked.

Clear d->redirect only after ovl_get_inode() has succeeded, like d->upperredirect, so that ovl_lookup() frees it on failure.

Fixes 2b21da920866 ("ovl: prepare to store lowerdata redirect for lazy lowerdata lookup")
fs/overlayfs/namei.c +4 -3
index a27479a10027..e25858c8dbcd 100644
@@ -1366,15 +1366,16 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data
 		};
 
 		/* Store lowerdata redirect for lazy lookup */
-		if (ctx->ctr > 1 && !d->is_dir && !ctx->stack[ctx->ctr - 1].dentry) {
+		if (ctx->ctr > 1 && !d->is_dir && !ctx->stack[ctx->ctr - 1].dentry)
 			oip.lowerdata_redirect = d->redirect;
-			d->redirect = NULL;
-		}
 
 		inode = ovl_get_inode(dentry->d_sb, &oip);
 		if (IS_ERR(inode))
 			return PTR_ERR(inode);
 
+		if (oip.lowerdata_redirect)
+			d->redirect = NULL;
+
 		ctx->inode = inode;
 		if (ctx->upperdentry && !uppermetacopy)
 			ovl_set_flag(OVL_UPPERDATA, ctx->inode);
maintainer
#1 lore raw

PATCH 1/1 ovl: fix leak of lowerdata redirect on ovl_get_inode() failure

From: Amir Goldstein <[email protected]>

[ Upstream commit f1b7e5534854043077bb72afc8d87ad1e0b283e0 ]

ovl_lookup_layers() moves d->redirect into oip.lowerdata_redirect and clears d->redirect before calling ovl_get_inode(). When ovl_get_inode() fails, it does not free oip.lowerdata_redirect, and ovl_lookup() frees the already cleared d->redirect, so the lowerdata redirect string is leaked.

Clear d->redirect only after ovl_get_inode() has succeeded, like d->upperredirect, so that ovl_lookup() frees it on failure.

Fixes 2b21da920866 ("ovl: prepare to store lowerdata redirect for lazy lowerdata lookup")
[ sashal: adapted the fix to inline ovl_lookup() code using local variables (d.redirect, ctr, stack) because the ovl_lookup_layers() helper and ovl_lookup_ctx struct don't exist here ]
---
 fs/overlayfs/namei.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/overlayfs/namei.c +6 -3
index b932b3b7bcea0..15613f8ef5b59 100644
@@ -1310,14 +1310,17 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
 		};
 
 		/* Store lowerdata redirect for lazy lookup */
-		if (ctr > 1 && !d.is_dir && !stack[ctr - 1].dentry) {
+		if (ctr > 1 && !d.is_dir && !stack[ctr - 1].dentry)
 			oip.lowerdata_redirect = d.redirect;
-			d.redirect = NULL;
-		}
+
 		inode = ovl_get_inode(dentry->d_sb, &oip);
 		err = PTR_ERR(inode);
 		if (IS_ERR(inode))
 			goto out_free_oe;
+
+		if (oip.lowerdata_redirect)
+			d.redirect = NULL;
+
 		if (upperdentry && !uppermetacopy)
 			ovl_set_flag(OVL_UPPERDATA, inode);
 
Signature · 1 line
2.53.0