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=1796383021; b=lpDOFWg1uFq5FBjKZktxHcKsRv7MjvIE/Uu5XLOtI+RrcloqeJcQXRnmS2392YKzJ7go jr0yFEo9QwCqAuFH/dQG9SXkBD9edBZT3WrV0dX9eA/zrBt0cMkqbHlzradq4Ds3vuIbp u0sovOWtLktW3S0tz0k6q8NGxuH/4RYit0qQAj5WHy1qYLDcWOqFUNhtC9TyMPWF5gqaD DJa5LowxtDX6qHLt7f+cwxKE8kOz1sD00X0zGx2X5DZXtvin03cJCaL9bFqwKFNBJZ9l6 lOABE+KGbZZlAGMXAjeOqJuOtSw6fBd4aF+OxlFjY+uJ6cKfczjRQRDDGoF+piPr6mw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383021; 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=czL99vviJQFTlYXpT5lQ+8gXVJwQSxVPF9sn8RuGuTk=; b=pj0fUYOzDPzp4lmQmEN1bPrriXOX36BXvKpSS1/2S17w/3X25Ebjza85ZfphManWmB46 bR9Hud5vdzY7XORN6CJKz7VQudnSN+lAD0PA0Ko+lwr8qt9IVsnkVucKDF2lh8Ycx639p 5zxfhVozR4Xcyl48vZJMpC+dV8NNI0DOlkmnhhRdxPpyq22QFIV3uxg7FgI18dmzwuK8U v7/2jmXSGOrNcLa37ZeDRDvOpeFpuxIblliZ+Pmm2oBedBw4Jq3tKHdfhBOsTiTnAuaM2 0Serf0vE6kXkEMkT0SV10AmrID87kWHZ9yAz5u67LQaIF/wjGGAHZ4HQ0D6IWdM0K2w== 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=awVY4gLF; 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 29BC3606A330; Fri, 4 Dec 2026 11:17:01 +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=awVY4gLF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25CD01F000CE; Fri, 4 Dec 2026 11:17:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383020; bh=czL99vviJQFTlYXpT5lQ+8gXVJwQSxVPF9sn8RuGuTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=awVY4gLFKPx6xVna4QtkiA9xaJUORpQZDgxhl7FHjkwxCO2N1exZVup6dBE4pD6l2 jqRlT1O2OPv8KXwfutmEO/yp8RXfPfIKDDypnjbffuPckKF6SsX50Oqon8NLi1cvMx RfK17+Tsq1Vx1vld9M7aY6tCZz9c0MEhT0aY2ikQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Leon Ming , Miklos Szeredi , Sasha Levin Subject: [PATCH 6.18 693/703] fuse: set dentry epoch before making the dentry visible Date: Fri, 4 Dec 2026 19:09:52 +0900 Message-ID: <20261204100646.276253538@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: stable@vger.kernel.org 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: Leon Ming [ Upstream commit fea42fae07822cd717ba4b3082834bb5908bf911 ] fuse_lookup(), create_new_entry(), fuse_create_open() and fuse_direntplus_link() set the dentry epoch only after d_splice_alias() or d_instantiate() has made the dentry visible. A new dentry starts at epoch 0 and the connection at epoch 1, so in that window a concurrent lookup can find the dentry, fail fuse_dentry_revalidate() and d_invalidate() it. The original lookup then returns an unhashed dentry, and readlink() of /proc/self/fd/N on an O_PATH fd for it says " (deleted)" for a file that exists. Anything that resolves real paths with open(O_PATH) + readlink() can pick up the bogus path; TypeScript's native compiler (tsgo) intermittently fails to find installed packages this way. It got much more common after commit 5a6baf204610 ("fuse: fix uninit-value in fuse_dentry_revalidate()") zeroed the initial epoch; before that, slab garbage usually passed the check. Set the epoch before the dentry is published, and keep setting it on any alias that d_splice_alias() returns; the dentry that loses to an alias is dropped without ever being visible, so setting it too is harmless. With 32 processes making concurrent first lookups of 6000 files on a fresh squashfuse_ll mount (UML, 16 CPUs), 1652 of 10.75M lookups came back "(deleted)" before this patch and none after. Fixes: 2396356a945b ("fuse: add more control over cache invalidation behaviour") Cc: stable@vger.kernel.org Signed-off-by: Leon Ming Signed-off-by: Miklos Szeredi [ sashal: Replaced the missing fuse_dentry_set_epoch() helper with direct d_time = epoch assignments in each hunk, and kept the surrounding older-API context lines. ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dir.c | 12 ++++++++---- fs/fuse/readdir.c | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -449,13 +449,17 @@ static struct dentry *fuse_lookup(struct if (inode && get_node_id(inode) == FUSE_ROOT_ID) goto out_iput; + /* Set before the dentry is visible, or a racing lookup invalidates it */ + entry->d_time = epoch; newent = d_splice_alias(inode, entry); err = PTR_ERR(newent); if (IS_ERR(newent)) goto out_err; - entry = newent ? newent : entry; - entry->d_time = epoch; + if (newent) { + entry = newent; + entry->d_time = epoch; + } if (outarg_valid) fuse_change_entry_timeout(entry, &outarg); else @@ -712,8 +716,8 @@ static int fuse_create_open(struct mnt_i goto out_err; } kfree(forget); - d_instantiate(entry, inode); entry->d_time = epoch; + d_instantiate(entry, inode); fuse_change_entry_timeout(entry, &outentry); fuse_dir_changed(dir); err = generic_file_open(inode, file); @@ -835,6 +839,7 @@ static struct dentry *create_new_entry(s fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1); return ERR_PTR(-ENOMEM); } + entry->d_time = epoch; kfree(forget); d_drop(entry); @@ -846,7 +851,6 @@ static struct dentry *create_new_entry(s d->d_time = epoch; fuse_change_entry_timeout(d, &outarg); } else { - entry->d_time = epoch; fuse_change_entry_timeout(entry, &outarg); } fuse_dir_changed(dir); --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -235,6 +235,7 @@ retry: fuse_change_attributes(inode, &o->attr, NULL, ATTR_TIMEOUT(o), attr_version); + dentry->d_time = epoch; /* * The other branch comes via fuse_iget() * which bumps nlookup inside @@ -249,6 +250,7 @@ retry: return -ENOMEM; } + dentry->d_time = epoch; ihold(inode); /* d_splice_alias() eats a reference */ alias = d_splice_alias(inode, dentry); d_lookup_done(dentry); @@ -265,11 +267,12 @@ retry: iput(inode); return PTR_ERR(dentry); } + if (alias) + dentry->d_time = epoch; iput(inode); } if (fc->readdirplus_auto) set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state); - dentry->d_time = epoch; fuse_change_entry_timeout(dentry, o); dput(dentry);