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=1796387520; b=LwhK1nbxPbDt312jvRL2jrjnjQoXR1qeF7Q1hQb+kI2rL8WhxtxBBWFp+RePzbqVSsU1 xW3UzLaL6pUy4Tps7OKMK6N2zixZmLkXMiM5SgDjq50OY55eDquNdu0A/tRHBVYeb5NbD 0NCxufJsE5Fp3bB4xQS5jnHQ8R34Jnxih7APhhRjT4dsocvTamEtJHzXwx+xlFpcNa/T+ D7ie2+F8tOEePkfqId62ofEjLvRUjfq8oHXoe7T7TIyBx5aJV7pSKR+RZ5DvbNLazxrCO incswifUQaEWPtZ2mfsuxifGQU3hxi1LvsYiOPrRQKE62+7KW4tnDPqgSSfCnehFAqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387520; 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=Xd7JGqm1zxJJtPzYcKmRQcN/B/3dIjAdz4qEbOmGG0o=; b=0PYyg3JIZj/JQXlKwOpXw8Mv+YJo8Zu/qWw1Bw2jMLFXkAL5GYXitCitO9bCjIe8p+2V QrTa/g6gBYqt3Xqt65Y98qGNi9lgfRVE9gYY9WzyAZcyfsxrwAa/dJ21Q7fLJHWz17WDj bPUvHtQngd26tTh4UCHjfydW3OFepjJg0+TE+gXKQqquzAbOmakmHTh8PK2YclNgXdTJC c7BflcWJKyf4/DDoBzwPhrY9xnKOGJ7npUo45ePhK6KMJJDiHQaiudN0Xrg2F251RJ0zu GKN//g8rutPzWmvz+41Ho8vLJQYe2x2fU8XJG2qlMSZUvbqNkI9Uvj0b1afUKQxjS0g== 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=vitJSENC; 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 6E50B606A322; Fri, 4 Dec 2026 12:32:00 +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=vitJSENC Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9E0D1F000CE; Fri, 4 Dec 2026 12:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387520; bh=Xd7JGqm1zxJJtPzYcKmRQcN/B/3dIjAdz4qEbOmGG0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vitJSENC1GuSCvA23BYTWke7dOk9BT4BCC+4ymy3sUlZvgv1frQs7tpgjNL0A8+1n oCz8s67ENrLBb/BYFDwmfAPFr/RzSRogSN9SmB+i70N0IktKM7ggkDbHK/7nCVdR1n rKvU2/77sqLmalWIHOErodzrYCcGDiFJtVtA3WBU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Daehyeon Ko <4ncienth@gmail.com>, Amir Goldstein , Jan Kara , "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 6.1 0238/1059] fs: dont fail __d_obtain_alias() for unlinked inodes Date: Fri, 4 Dec 2026 18:56:09 +0900 Message-ID: <20261204100650.436865875@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: 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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amir Goldstein [ Upstream commit a522dd871024a0f065bfa7638afdb929607f58fc ] Commit 669bb5af15d4 ("fs: make sure to call fsnotify_inoderemove() only once when inode is dead") did two things. It made dentry_unlink_inode() call fsnotify_inoderemove() only once the inode has neither links nor aliases left. And it made __d_obtain_alias() fail with -ESTALE for an inode in that state so that open_by_handle_at() can't create a new alias after FS_DELETE_SELF has been reported and the inode marks are gone. The second part is wrong for network filesystems. __d_obtain_alias() backs d_obtain_alias() and d_obtain_root(). Those are what the ->fh_to_dentry() and ->get_parent() methods use to turn the inode they looked up into a dentry for exportfs_decode_fh_raw(), i.e., for open_by_handle_at() and for nfsd file handle decoding. For a local filesystem an in-core inode without links and aliases is an orphan that goes away on the final iput(). For a network filesystem that's not true. i_nlink is just the link count the server last reported and whether the object is still reachable through its file handle is up to the server. If a file is unlinked while it is still open elsewhere, e.g., by another NFSv4 client or by a process on the server, the server keeps the object alive and its file handle stays valid. nfs_fh_to_dentry() fetches the attributes for such a handle, nfs_fhget() sets i_nlink to 0 from them, the new inode has no aliases yet and so __d_obtain_alias() now fails with -ESTALE. The same applies to fuse_get_dentry() which takes i_nlink from the fuse server. Filesystems that care about unlinked inodes already make that decision themselves in ->fh_to_dentry(), e.g., ceph's __fh_to_dentry() fetches the link count with CEPH_CAP_LINK_SHARED and only refuses an unlinked inode if it isn't open. Note that on a network filesystem i_nlink drops to zero through attribute updates when another client unlinks the file. So the inode might never have gone through dentry_unlink_inode() with i_nlink == 0, i.e., fsnotify_inoderemove() might never have been called for it and there's nothing for the -ESTALE to protect. So drop the two checks from __d_obtain_alias() again and go back to the unconditional alias lookup. While at it, update the comment above inode_notify_dead() since it no longer blocks new aliases. Amir sent this as v3 to replace 669bb5af15d4 but that commit was already in mainline by then. So do it as a fix on top. The resulting code is identical to v3. This means open_by_handle_at() can again create a new alias for an unlinked inode after FS_DELETE_SELF has been reported. Closing that file reports a second FS_DELETE_SELF and the file has none of the inode marks that were torn down. That's what Daehyeon's open_by_handle_at() LTP test checks so it is expected to fail again. This needs to be handled separately. A mark that is added through such a file while fsnotify_destroy_marks() is still running is rejected with -ENOENT since 36ebddca56b9 ("fsnotify: prevent mark additions during connector teardown") so it can't end up on a detached connector. Christian Brauner says: Amir's v3 replaced 669bb5af15d4 as a whole. I turned it into an incremental fix on top of mainline and wrote a new commit message. Jan's Reviewed-by was given on v3 and the resulting code is identical. Fixes: 669bb5af15d4 ("fs: make sure to call fsnotify_inoderemove() only once when inode is dead") Cc: stable@vger.kernel.org Reported-by: Daehyeon Ko <4ncienth@gmail.com> Signed-off-by: Amir Goldstein Link: https://patch.msgid.link/CAOQ4uxg7Qt436SiKhKEJKOjtCjeB_XyTjazYF7HMyQAGGcgx2A@mail.gmail.com Reviewed-by: Jan Kara Link: https://patch.msgid.link/20261030-work-dcache-obtain_alias-v1-1-a1f7e44536d2@kernel.org Signed-off-by: Christian Brauner (Amutable) [ sashal: Adapted the hunks to this tree's split helper: the recheck under i_lock went into __d_instantiate_anon(), and the initial lookup became d_find_any_alias() inside the existing out_iput flow. ] Signed-off-by: Sasha Levin --- fs/dcache.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 5065c16af16d4..111ada96c33b0 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -382,10 +382,9 @@ static void dentry_free(struct dentry *dentry) } /* - * If inode is unlinked and doesn't have any aliases (i.e., all fds pointing to - * it are closed), it is pretty much dead. Except that file handle lookup could - * still revive it which causes issues to fsnotify. So once inode reaches this - * state we make sure to block creating any new aliases. + * When inode is unlinked and doesn't have any aliases (i.e., all fds pointing + * to it are closed) we report FS_DELETE_SELF to fsnotify and cleanup all inode + * marks. */ static bool inode_notify_dead(struct inode *inode) { @@ -2109,10 +2108,7 @@ static struct dentry *__d_instantiate_anon(struct dentry *dentry, security_d_instantiate(dentry, inode); spin_lock(&inode->i_lock); - if (!inode_notify_dead(inode)) - res = __d_find_any_alias(inode); - else - res = ERR_PTR(-ESTALE); + res = __d_find_any_alias(inode); if (res) { spin_unlock(&inode->i_lock); dput(dentry); @@ -2159,12 +2155,7 @@ static struct dentry *__d_obtain_alias(struct inode *inode, bool disconnected) if (IS_ERR(inode)) return ERR_CAST(inode); - spin_lock(&inode->i_lock); - if (!inode_notify_dead(inode)) - res = __d_find_any_alias(inode); /* existing alias? */ - else - res = ERR_PTR(-ESTALE); - spin_unlock(&inode->i_lock); + res = d_find_any_alias(inode); /* existing alias? */ if (res) goto out_iput; -- 2.53.0