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=1796381582; b=odFBiiXMyKTiStjsQIePQHSlQF+fwcx1dr5DqNS+OQJBTqr2HrY7LjpvgcdtGdyduBo2 /tOsPh9mVTJ882iN7P+GSHzzlO3YMAVJIhf0R9YjNKxSkHJQyGSZSN8teIo+FWSKT5U0j +nBXSU95TYKodvhz/OlLHLha22r0j7H7Hd/Gp/qo/8+NRwhVoRdogwc3tgj/uXhrQsRLv C5B+pFJINQWQzMQ7/LwSvZwfA/xiKAF/Db6Nx1HL1LJayscBWwe8O4SB9/ugKPmiUJAhL kGWi0r4upG3ftOkY+hpXVI1rmlYtcEvH/OJsItRV0APqcpBqwTFJ0WaOogw0ROoC3oA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381582; 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=CT013TePqQCo2IEMDNbfKnXAua2qYi+ThqHQAq1sTeQ=; b=ZcDt8uMXgXj7+xpszxb4GyJsYdycvjbtb+5rfQ4EklYh33yqwHSI/qp/jVt84GxHaLOI LlN3g1aQbn+th6R7g6VEz+TV9GQBVZ7qQAD0bWw+SoGS/hdvJAJdsEE0hyr6SMYSQdAzR WVBQ9Idjr/2jYRDfLu5viisdpCDSBu6hqdw6juFLlERH+caIoT3RGFX74pAthU3rdjLRJ IAy8He3wi68inqhy/9RoljU/0Xkm5wFxQkK9UIQRf0diSBW3SRjE3DJmayPXlwZ4FKR4U ppD0Glkx+ZDuQHoigABIRvbcHVx+Tt5+pF8kJG9qoh4Xma6YCPiZL9lyR4/D6eobwVQ== 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=1pPP5Tqu; 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 2A729606A322; Fri, 4 Dec 2026 10:53:02 +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=1pPP5Tqu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9733A1F000C2; Fri, 4 Dec 2026 10:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381582; bh=CT013TePqQCo2IEMDNbfKnXAua2qYi+ThqHQAq1sTeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1pPP5TquEum2BpK5CQJlXkp6Hpqy+RqKj7mDjljwYuFnutiPQEEKGSmlpQR4lJC06 uC8x1KTnHYQmDQSUK5Yt29kVF0a3tCQ9heQ7lvRf8FHvnVuPlbW4VMhfTWB3vXdI9n b8/zrVLT54n8eXSbc/nInMo/Vu5JfW2UmucfYL3Y= 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.18 086/703] ovl: do not read the flags of a put upper dentry in lookup Date: Fri, 4 Dec 2026 18:59:45 +0900 Message-ID: <20261204100630.022709816@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 0ec6b9b3c4baa..2c962a53cc59e 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -1390,9 +1390,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