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=1796388791; b=f+Z0m3SZn48CrCWbuNLQjE7OmAca58BzMNQfllE+6As6pqxUqQohNQ18EAg4l4TIu4ui fDZreTKGZVH6H7h3xeOP5Npg6E6pZihFh7pfmVF3WAY5XAcoGtoHu1lOUKx6rJ/s81nah jw1kJJrGGHeRzq/EcT9pVUPhu2TBYVjxXflEWTF/X7UNRGo/4bH7jRUrxEkjQztP1ns/u c9MlppS/GumT+JTdbPNVOpNDgbSSOz7l7hR8xzLZ5JPI5HSH2RvkVTFT/RTucPD/WBzlI j9IWKfSPWLlg9CwhZlMR8wgPw5NEbziOqQEIN7y/UZiRwNcZH5/eo1oWzYnwi3Ng0Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388791; 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=eF1/LFcNJBp0P6QfnogJMj/TskCN1laBHfT3IBYV2Ww=; b=a4B+6kyx/sqzRZhUBuQpbV1M3F7htfGnWk1vHotQ9DVTkLz3uurXuo0/vU0oX9UWbhmH a7CZthDDwY7FrPnCrVzk1Rt0Fy/Wjr8BGtMAV1JJZ1QB3pXncDlQ6jA6PtmH9varbsuFQ FqEbw/mxMwEbn7NnSckI2GlxAweaW4/f1Svd6aJwn3Lq+FXGrzWGPPa85pZjXqx/G6/Ai pD3sbxGyrYFXD9HDTf95YCASUDgwS+cn+pyNB/3/sHBGG53ucuIQI+S8R5zvTnkCpD/GE j2wlWt0srl0C26B9aO5XypUflaQOEnKtCm6S8NDYWsHGFUx2uoTGpToks3xKcXpSJKw== 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=Oa4kAQc7; 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 7AEFF606A32C; Fri, 4 Dec 2026 12:53:11 +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=Oa4kAQc7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 486FA1F000C2; Fri, 4 Dec 2026 12:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388790; bh=eF1/LFcNJBp0P6QfnogJMj/TskCN1laBHfT3IBYV2Ww=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Oa4kAQc7b2qCvnuLGWmMURlA7VO2fpAYdnoZcMQ0N888eb8pcnY/jIoLeU3Bpm6Ym I276Wh2x6XXgZV51zidTma7jcOuwww3WbY/vrDgTc9EcDuUbKzck1A+lKl7f/OCW8C b1L+z1FaREKe8Ak+l7Nhlp3mIpuZ1Nh2Em2eHTtw= 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.1 0752/1059] ovl: do not read the flags of a put upper dentry in lookup Date: Fri, 4 Dec 2026 19:04:43 +0900 Message-ID: <20261204100703.481716067@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 the ovl_dentry_init_reval() call inside the if (upperdentry || ctr) block, taking flags from ovl_i_dentry_upper(inode) with an else branch for negative dentries, and dropped upstream's third argument since this tree's helper takes two. ] Signed-off-by: Sasha Levin --- fs/overlayfs/namei.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 124c437e65e6a..a255102adc624 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -1123,9 +1123,16 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, goto out_free_oe; if (upperdentry && !uppermetacopy) ovl_set_flag(OVL_UPPERDATA, inode); - } - ovl_dentry_init_reval(dentry, upperdentry); + /* + * 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)); + } else { + ovl_dentry_init_reval(dentry, NULL); + } revert_creds(old_cred); if (origin_path) { -- 2.53.0