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=1796336182; b=GfFGExa8/tNE66WVyBYi0t9M7F+5lk1FqyzC+UH836S4Pv2UXGXiXMbRKtu2OmOsW0N/ ZXk1yJAYZU+vdaS2vp+n9T2QE17uayMfOdHQt4U0XxhlTOy0xIMu6pnNu5rs9cw5VdX9o BCebrG27F7McR1cTH7rI8BItRL0dLXzXbkcV0oAVfCpNAbi1E0bchDtFmfqY9iP98Ljn7 BVuCB9+tkju6pQCvlI4crGguQ1MO0rOrlUaxZPPYS/GVanAEFJhhFzNhN0ASeHjV9T4DY 4TXiBzZhX4KhNJCsXQr7xuoYpklIBTsJ7QZ/DPDYoTz4d23pXsdYmhVjznL+m2AHn9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336182; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=k1KHECoEjN2dGvAUK59m4EhBvZOLgEqTfqT/IElRNTU=; b=sRj/W+2iAo1xxZBws/0sFFAv+MLbrfGL+OSZ+O281VSS+1f1B+8QB9ItKDixSexIBIH4 nsJh/RhBDpGChy0yWtDRX2oqLH+MN1wS+RxP1os4t7qPG5rSlk3Y1OJPpQWF9CsJZQmgn cl3lULwFYB7Upzedn3683P5A05L0AUo0LrfXiVULZTbgzr/naiHrpMRFNGszd655rUkm0 /rXoFyKIFbcihB0sOmS3TRdCs60idyNnNmC3iwZuTT/1i6UTnenSPNMx6NfK1GZD4F0E4 P7wI6+9CRa8uwEblAu0ykU96vA/8l3arR12sd+ck0B2f/CUUyPw0JFiVML0kluTcpmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BvjLShWn; 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 01609606A322 for ; Thu, 3 Dec 2026 22:16:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BvjLShWn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 071FD1F000C2; Thu, 3 Dec 2026 22:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796336181; bh=k1KHECoEjN2dGvAUK59m4EhBvZOLgEqTfqT/IElRNTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BvjLShWnwLvn7bTPNgevfKizfqGiwrzsEIKL/VgJ3TDC3ZIQ0Rc9DGfB3BOeQ0KOs /gumPsG/iQKqcqyGWLAuHg4gxa9QADCBBdmUxfhPqNI3d6nDoXY7oefNVvIW3TIubp Ps7HSzAGZJcAkbhlWDkbjj7fY82nMG1c38T1vMPGsXknEvQTZkjqnFaZHAW9z9CfZ/ c4Yb+GWunSXcGIF5DTyFIOksyQ6RrHkFli9yBaESSY9RfBg58PL5oI2RIiDJ+Q26Gv ELkLQ5ufH8Wp4gfwNknbs8dH4qSMqEQan57N6uqetgn9HXk7xvgFLrc7/bSZt6kOHJ dFgOBNkGa22cg== From: Sasha Levin To: stable@vger.kernel.org Cc: Leon Ming , Miklos Szeredi , Sasha Levin Subject: [PATCH 6.18.y] fuse: set dentry epoch before making the dentry visible Date: Thu, 3 Dec 2026 17:16:19 -0500 Message-ID: <20261203221604.802461-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120239-hypnotic-spectacle-6177@gregkh> References: <2026120239-hypnotic-spectacle-6177@gregkh> 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 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 --- fs/fuse/dir.c | 12 ++++++++---- fs/fuse/readdir.c | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 9e20bc9dbdac4..757848eea6784 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -449,13 +449,17 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, 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_idmap *idmap, struct inode *dir, 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(struct mnt_idmap *idmap, struct fuse_moun 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(struct mnt_idmap *idmap, struct fuse_moun 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); diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c index 8833352965a41..8981bbcf2500a 100644 --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -235,6 +235,7 @@ static int fuse_direntplus_link(struct file *file, 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 @@ static int fuse_direntplus_link(struct file *file, 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 @@ static int fuse_direntplus_link(struct file *file, 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); -- 2.53.0