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=1796386167; b=jxaCkSVrDln+FVSog+z3m/1Y/i3DIBuDT4JQjSJacNqXolmXl+nJQEJppNptSJi0VwwD G1L/qAZ1KF/F26LdF71XleqGITDyLqDXCnlY297JzxvFaBCO6AH+P9NaVQTZWaIbOHdme 1471QhMmhI0brGnZ9Za5mtwbmW2x3Ukjz/MeO7JcBIHNU1AxIpgz84DkzGpnx5vPSHWWZ j3ygwyJS9bF8nlHslflfVAWUufKu7AdsYStZ8amRHNKXKtqrmEOscFF+fJvTnZlELBKgt loQA/P2zFcecjtio/Ltt9fQKlKfatSNayQMStb2hXsJdord3xj5PMu1VSOEtu40mkVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386167; 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=AVi6/xrTqsUENetN5Hw19g+9dnhEcutOistqCTw+mtk=; b=OiVDWr0Iy6F0LbwHxVjvVp7TNdHki6u3qTZlxSq2eAQsyge6RNjZKY5oEbwBtfvLe+cD uss4ZhgIJHWrHxQQAtAtVe1TxC3fPPl23Jx/iZG/87X8EsvqPFCwSWQ2HPbs3W9MaX7q6 4jjBgeaJQZjTzU5QTnCd0K5KBQQiKPR/tpjvl+LoBqKJrr2HG0DmaQaVVoxSE5BnPbQ2V FXh0Is4otqSgJmbj+HMWkezfoYqZ3Vdhk58rSpNxhFLz6hvTq/Dpk/yZgC0RJnPC+aFZI 9QCXUv55coiqbd/epLIrTZj4SSIEdesbYdhIMot2H2gT7+Y1rS07uY1/b7KkVM+XydA== 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="pjy96/r0"; 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 C18E9606A32D; Fri, 4 Dec 2026 12:09:27 +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=pjy96/r0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B6CC1F000CE; Fri, 4 Dec 2026 12:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386167; bh=AVi6/xrTqsUENetN5Hw19g+9dnhEcutOistqCTw+mtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pjy96/r0Rpj6ifCxJTqi3sHjin+7Elg8CXB0QaLLORwuWoR8n0QW7RAqhh5ZtCAeE ml4X9EFJ9IEOWttsdqk2ApmxrPksLCeSUM6UzhP3msQpyTAaHl7+3ki27dTMl4Tzau i65JXkRJB+xOnQPIy5GGkCy1MlHym2NVjXCJTmDQ= 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.6 0814/1167] ovl: do not read the flags of a put upper dentry in lookup Date: Fri, 4 Dec 2026 19:04:01 +0900 Message-ID: <20261204100723.327057209@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 [ sashal: Moved ovl_dentry_init_reval() into the upperdentry/ctr block using this tree's inline locals (upperdentry, inode) instead of the later-refactored ctx struct fields. ] 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 b932b3b7bcea0..71e9816fdde6b 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -1323,9 +1323,17 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, if (metacopy_size > OVL_METACOPY_MIN_SIZE) ovl_set_flag(OVL_HAS_DIGEST, inode); - } - ovl_dentry_init_reval(dentry, upperdentry, OVL_I_E(inode)); + /* + * ovl_get_inode() puts 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); + } revert_creds(old_cred); if (origin_path) { -- 2.53.0