From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383176; b=1y7WE3iyptB8vcsl51D8bZ2vSOvlsMIVyXDMEA2E1ookz27ACts2SyH0DxMhHWFRDXf4 kFl8DyFN7UgS7FsA4OzsKCTaRw4WJS2pBsG+PKJqtmWhIMGFOLcht9KDwtOvhXrfUtzw8 Y2zDil8RTnmAGLmwV/SEa5J9IGA7X1YhIE9tOTANr1wmJiDBqunmVK1+hP6IjnSdfx1n5 cQLPeCp/0pq14rTp1vD5qgH5sVbNhlhYs9BA0ZxcPlp4Yx+IqdqPIpg8DhXTkndxm+8UI /+AVwNUa7k4SQ2fn8p1Rq2H/x+v8Q2E/yAUoyIrX/RAL/Sqy71bVPYu0LsoPGYZOC1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383176; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=oziqnjb98Og5baabj6H438WSJu3PuJAmhA57yXvza+o=; b=FEDSRUK5vuqeF0BQwctlkQTx+RWa7kTZKWmSzL0Xbx7V1bghZPiJZluG8lmfRC4zNxpx M1yZFn40MBLsyYPgH3mA6vCDObuoXoQHt1MDTfWnd1oLGxZGOPLY4vL9T0ug217CLZMO6 HXNBuPC8dK8wGbMo+dL485+X40D5egbi2tsya8NQdLLApegfnA9Q6IOqOefuPaunO9dSm KfNfZgGt+V5FWXRdo0at1usClCVOzpxnrQq6gKPKL5m6vxIBFgenJsZ43JUuJK2s8zvbp H4bbCsDA1Btetv9Ee2GlFpMrEPGPzleTJtTVCADo9Z/qH6mtNbzybbMu1FS3CloYbQA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=j3BuAyXp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D3DF606A322; Fri, 4 Dec 2026 11:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=j3BuAyXp Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF1381F000CE; Fri, 4 Dec 2026 11:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383176; bh=oziqnjb98Og5baabj6H438WSJu3PuJAmhA57yXvza+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j3BuAyXpbydTcSj55VYf/5mGGTrCFykggo2dUKPM8Dlk/GLUcue4bjlaQlblf612g Tgft6bbRo0h2LXJSGPakZEJJFpqBxccHFURSOOefIu/OlE5v0t69iYzEXMOdnXYwYV XcaTar8yO5y1RL7Ep8iNzbG6W6PxGyD1RDxqIQWc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Amir Goldstein , Sasha Levin Subject: [PATCH 6.12 114/555] ovl: do not read the flags of a put upper dentry in lookup Date: Fri, 4 Dec 2026 19:02:37 +0900 Message-ID: <20261204100612.281860793@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amir Goldstein [ Upstream commit 7031366be218f291592a7ad38bc34a7cd1459737 ] ovl_lookup_layers() passes ctx->upperdentry to ovl_get_inode(), which takes over the reference. If an overlay inode for the upper inode is already cached, as for a second hard link, ovl_get_inode() puts the dentry and returns the cached inode. ovl_lookup_layers() then passes the put dentry to ovl_dentry_init_reval(), which reads its d_flags. With a local upper fs the put dentry usually stays in the dcache, but with a FUSE upper whose entry has timed out, dput() kills it, so this is a use-after-free. Fix this by taking the revalidate flags from the upper dentry of the overlay inode, which is the one that ovl_dentry_revalidate_common() revalidates. Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-986db859-840c-479d-944c-b9c43b93377e Fixes: bccece1ead36 ("ovl: allow remote upper") Cc: stable@vger.kernel.org Signed-off-by: Amir Goldstein Signed-off-by: Sasha Levin --- fs/overlayfs/namei.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 2eddcaab781ba..7053a24f42d99 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -1363,9 +1363,17 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data if (metacopy_size > OVL_METACOPY_MIN_SIZE) ovl_set_flag(OVL_HAS_DIGEST, ctx->inode); - } - ovl_dentry_init_reval(dentry, ctx->upperdentry, OVL_I_E(ctx->inode)); + /* + * ovl_get_inode() puts ctx->upperdentry if it finds a cached + * inode, e.g. for another hard link, so use the upper dentry + * of the inode. + */ + ovl_dentry_init_reval(dentry, ovl_i_dentry_upper(inode), + OVL_I_E(inode)); + } else { + ovl_dentry_init_reval(dentry, NULL, NULL); + } return 0; } -- 2.53.0