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=1796380916; b=kUMIg39LAuNFNpCD6vfBeTt6XNjHwjEQG+ueq2isIT6qTJuWbJ1OUjytfRAQ3u6remTQ nyP/aeK0Ai2s1r0Nu6v0BDa8awHuu9gTZdmt0YX5QL4RkxinSQgaDVNmCiLVMW5IbRag7 uFr6VMyk+jj8psmvGOw/enm6xZUgf7R9SMd6/ShWoVboolIAvgdJAWgMvIiBBAP4+rsHg CubNjzQpqomN9Dsvh//co4vhype33h4T6UEnQxEreOCRWSoS6RBTTKyIJgEBZ1qj2w0D6 hyYXy/JstiXm2w13PX1A8R8AbCtbRc89NAMCSyimtCJDBMIkzeKXGEKYQXT7kAQbgFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380916; 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=hfcReaIwkuqWwz0znSYG6PZaoYLbVBTM+k1eiL+g54E=; b=n3JLIaEtnFyVG+A/aPnnApNGZBvQLTxDaIZI7j8jTF5VIpxRnZy3ESkNd8D/iYv0Jo5M U2XWAlqy9rHAZrEfzz5GhEIoxueBYIDz45ca/oQylb4+uTVV06KenbkYr/R4FGjN1xfmm pKug5kA6ZqPV9WvFU73e/xrvz8VN26sLCEkEsQ75pI2441c5S3wMF3y1fms0iFK+sfGQi +FeulvJrqKfGQvzKyGsci5NM8gzUqPOiWFg5lbbLmiJygNcn/afDjV22dQ2KTHYdcjwr7 ua/3z1Gebb3xrd5UBEnnuH9NjcLv+7sBb6aOEE04F8xzG+xUTDybncqe3AVI4Ts5Ryg== 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=lg8Rwp2s; 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 2178E606A322; Fri, 4 Dec 2026 10:41:56 +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=lg8Rwp2s Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F2851F000C2; Fri, 4 Dec 2026 10:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380916; bh=hfcReaIwkuqWwz0znSYG6PZaoYLbVBTM+k1eiL+g54E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lg8Rwp2slQJFSl2jbBUqCbNafVFFFQILFDvjWFayxA2agvG0o5lY99By54sG2G+51 p+SkT191cKodzxU6RKq4p+yM6jrf6/OSb13qip+0QpfbZ/8OT5GPU0pO715FodNKES jY3YXGkuM5P8B2R4nH4v5+e/u6LNkq1C3mOFDDPI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Leon Ming , Miklos Szeredi Subject: [PATCH 7.3 478/742] fuse: set dentry epoch before making the dentry visible Date: Fri, 4 Dec 2026 19:05:42 +0900 Message-ID: <20261204100647.845128870@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leon Ming commit fea42fae07822cd717ba4b3082834bb5908bf911 upstream. 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 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 @@ -644,13 +644,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 */ + fuse_dentry_set_epoch(entry, epoch); newent = d_splice_alias(inode, entry); err = PTR_ERR(newent); if (IS_ERR(newent)) goto out_err; - entry = newent ? newent : entry; - fuse_dentry_set_epoch(entry, epoch); + if (newent) { + entry = newent; + fuse_dentry_set_epoch(entry, epoch); + } if (outarg_valid) fuse_change_entry_timeout(entry, &outarg); else @@ -906,8 +910,8 @@ static int fuse_create_open(struct mnt_i goto out_err; } kfree(forget); - d_instantiate(entry, inode); fuse_dentry_set_epoch(entry, epoch); + d_instantiate(entry, inode); fuse_change_entry_timeout(entry, &outentry); fuse_dir_changed(dir); err = generic_file_open(inode, file); @@ -1029,6 +1033,7 @@ static struct dentry *create_new_entry(s fuse_chan_queue_forget(fm->fc->chan, forget, outarg.nodeid, 1); return ERR_PTR(-ENOMEM); } + fuse_dentry_set_epoch(entry, epoch); kfree(forget); d_drop(entry); @@ -1040,7 +1045,6 @@ static struct dentry *create_new_entry(s fuse_dentry_set_epoch(d, epoch); fuse_change_entry_timeout(d, &outarg); } else { - fuse_dentry_set_epoch(entry, epoch); fuse_change_entry_timeout(entry, &outarg); } fuse_dir_changed(dir); --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -230,6 +230,7 @@ retry: fuse_change_attributes(inode, &o->attr, NULL, ATTR_TIMEOUT(o), attr_version); + fuse_dentry_set_epoch(dentry, epoch); /* * The other branch comes via fuse_iget() * which bumps nlookup inside @@ -244,6 +245,7 @@ retry: return -ENOMEM; } + fuse_dentry_set_epoch(dentry, epoch); ihold(inode); /* d_splice_alias() eats a reference */ alias = d_splice_alias(inode, dentry); d_lookup_done(dentry); @@ -260,11 +262,12 @@ retry: iput(inode); return PTR_ERR(dentry); } + if (alias) + fuse_dentry_set_epoch(dentry, epoch); iput(inode); } if (fc->readdirplus_auto) set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state); - fuse_dentry_set_epoch(dentry, epoch); fuse_change_entry_timeout(dentry, o); dput(dentry);