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=1795043991; b=LWSR/qWHT5CUweTwMLOyx2XbIk1eiFujqnIvADD5LG9zShVmr2AdPbUApQjIMwusQr/D U3UmPlc4h27n+EWma/E+3agQgKHVz0GnCdrEq0/bNM4aD5VA9Gpq/ciM1v3zivUm30nyZ G5rkpfRcAGo2+l4l63IV0kOqTqNKfe7DuJm85ZP5XYNYpRSmgXvO94wO1OnHipgil34t8 OKnKHoia6OVW4G0bEXVT3bEgmQ1l5/0XG15Tlr+xUqtja2uW1X9gEFD+SkxXInB9In/8E 66oAToadJSPUKe9ctG68R3/UF3zYZRngKpqfpo36nfYmBDz8xh26t8ZslmXm60ijmfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795043991; 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=JyCvWoRymBXUBTigvn91MtCiR9eINH15iBUHqdNsBsI=; b=us9aH+FpF5BS2exSkS8dK/+CktN8tcu/CaWNrhojfAwgr7TgC8vW05LDqKUlSZMYswiC HR28SEcjwI/7DG00CjR6W0fiM+ZhlGg1j9+dcjLvQeQ/jT13TLvOyf6tzdHRluQeq+rgA 3tzpBLkNk5d6iGmf6EyvT2ktqS9cmbSFVgoTWjmt1F9bj7gcoH3ghQV2BumsV1CYdnJma Ebnm2HCKoptn2scjGy4TosCGmEx/pWHF9uJRcTL7ZdukNGGKw3XMY9AFSF1dyOK40lZQ/ TLoYkc2Rm8713j901ChZDUZQ68+VS3U4rMi+Crlzn6I8NWFh0qDrNTM7dELr61giLLA== 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=T0+4OCLQ; 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 D4192606A32A; Wed, 18 Nov 2026 23:19:51 +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=T0+4OCLQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3323B1F000C5; Wed, 18 Nov 2026 23:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795043991; bh=JyCvWoRymBXUBTigvn91MtCiR9eINH15iBUHqdNsBsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T0+4OCLQ9bUSMUMpcf8gQTzhiO89BwJvsS9l8FS9/fmfCRUwoM/Z+5tML8CeUuXKu y589oO9z8rsP84HAxKC1tLBeIE/mI/YlD7+gMNIhF0Hom3YT6AbFCm/IEdLaS+0Z3c ZH0V4CKokl70W1jTDDWQSHmMYxQ6DdETf5vPzmLM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vasileios Almpanis , Breno Leitao , Sasha Levin Subject: [PATCH 6.1 0406/2857] configfs: pin the symlink targets dirent instead of chasing ->ci_dentry Date: Wed, 18 Nov 2026 15:24:00 +0100 Message-ID: <20261118150216.007909555@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@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: Vasileios Almpanis [ Upstream commit a7c1290eef60711c10289c056ad32ed1f2b47b12 ] create_link() reads the target's configfs_dirent from item->ci_dentry->d_fsdata, relying on the item reference taken by get_target(). That reference pins the item, not its dentry: the dentry is pinned by DCACHE_PERSISTENT, which configfs_remove_dir() releases via simple_rmdir() while the item is still alive. A symlink racing with rmdir of its target can therefore find ->ci_dentry freed and its dirent released, triggering WARN_ON(!atomic_read(&sd->s_count)) in configfs_get(). Take the dirent in get_target() as well, under ->d_lock and atomically with the item reference, and pass it down to create_link(). A hashed dentry has not been killed yet, so its ->d_fsdata reference keeps the dirent alive there. Cc: stable@vger.kernel.org Fixes: 7063fbf22611 ("[PATCH] configfs: User-driven configuration filesystem") Signed-off-by: Vasileios Almpanis Tested-by: Breno Leitao Reviewed-by: Breno Leitao Link: https://patch.msgid.link/20260730093435.195441-2-vasilisalmpanis@gmail.com Signed-off-by: Breno Leitao Signed-off-by: Sasha Levin --- fs/configfs/symlink.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c index 31b3a4ad5ea66..feaccac55d8cd 100644 --- a/fs/configfs/symlink.c +++ b/fs/configfs/symlink.c @@ -76,9 +76,9 @@ static int configfs_get_target_path(struct config_item *item, static int create_link(struct config_item *parent_item, struct config_item *item, + struct configfs_dirent *target_sd, struct dentry *dentry) { - struct configfs_dirent *target_sd = item->ci_dentry->d_fsdata; char *body; int ret; @@ -115,6 +115,7 @@ static int create_link(struct config_item *parent_item, static int get_target(const char *symname, struct config_item **target, + struct configfs_dirent **target_sd, struct super_block *sb) { struct path path __free(path_put) = {}; @@ -125,7 +126,20 @@ static int get_target(const char *symname, struct config_item **target, return ret; if (path.dentry->d_sb != sb) return -EPERM; - *target = configfs_get_config_item(path.dentry); + /* + * A hashed dentry guarantees that neither the item nor the dirent + * have been released yet, as removals unhash before dropping. + * Grab both references here. An item reference alone would not keep + * ->ci_dentry alive. + */ + spin_lock(&path.dentry->d_lock); + if (!d_unhashed(path.dentry)) { + struct configfs_dirent *sd = path.dentry->d_fsdata; + + *target = config_item_get(sd->s_element); + *target_sd = configfs_get(sd); + } + spin_unlock(&path.dentry->d_lock); if (!*target) return -ENOENT; return 0; @@ -139,6 +153,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, struct configfs_dirent *sd; struct config_item *parent_item; struct config_item *target_item = NULL; + struct configfs_dirent *target_sd = NULL; const struct config_item_type *type; sd = dentry->d_parent->d_fsdata; @@ -182,7 +197,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, * AV, a thoroughly annoyed bastard. */ inode_unlock(dir); - ret = get_target(symname, &target_item, dentry->d_sb); + ret = get_target(symname, &target_item, &target_sd, dentry->d_sb); inode_lock(dir); if (ret) goto out_put; @@ -196,13 +211,14 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, ret = type->ct_item_ops->allow_link(parent_item, target_item); if (!ret) { mutex_lock(&configfs_symlink_mutex); - ret = create_link(parent_item, target_item, dentry); + ret = create_link(parent_item, target_item, target_sd, dentry); mutex_unlock(&configfs_symlink_mutex); if (ret && type->ct_item_ops->drop_link) type->ct_item_ops->drop_link(parent_item, target_item); } + configfs_put(target_sd); config_item_put(target_item); out_put: -- 2.53.0