From nobody Thu Sep 24 20:04:08 2026 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 233E732E121; Mon, 21 Sep 2026 09:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981617; cv=none; b=iQrTbmxzXzUC7m6y4GI//3H5IUan+CymYYsLGRK6q/i/59ueeFd3k3pstcAlEasi/8g1o9Gt9K+uC8CN8JaccE5KbhavP23YtLWP+Pun/2t/9CB8mvL44k+rCmoeK8u0do8DUK/QkfUwHw8P0JvQotkx4VrpoQOqs+/rS87MSek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981617; c=relaxed/simple; bh=STo49Godg6DLVIS4A3fquG3iQwdFcMAQTL+yZDX8aAM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GG/HtFQ5RALPqELGqc1QWdhoFcvsnH+fNcg33AlVOo1UtMzS0LzaXGdLwh8dd8t1RFtJQ7PEOfqoHyGPhG+atuCLYuNx1qtPUIaYfvSOUNp8bvRSL+WiA9EPFhwgWBYioEhBVwBFZY1dkPOTtUZWJKoSWILp3fQLWBzuxFqASgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=ibOsf5Hw; arc=none smtp.client-ip=101.71.155.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="ibOsf5Hw" Received: from PC-202605011814.localdomain (unknown [222.191.246.242]) by smtp.qiye.163.com (Hmail) with ESMTP id 4e8e7465e; Mon, 21 Sep 2026 17:06:43 +0800 (GMT+08:00) From: Runyu Xiao To: Christoph Hellwig Cc: Sagi Grimberg , Chaitanya Kulkarni , Andreas Hindborg , Breno Leitao , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Runyu Xiao , Jianhao Xu Subject: [PATCH v4 1/3] fs: configfs: add helpers for opening non-configfs paths Date: Mon, 21 Sep 2026 17:05:57 +0800 Message-Id: <20260921090559.41364-2-runyu.xiao@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921090559.41364-1-runyu.xiao@seu.edu.cn> References: <20260921090559.41364-1-runyu.xiao@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0aa0c337b5c503a1kunm2bb71b5a41172 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlCGk9JVh5JSh5LSUkYSEhDSlYeHw 5VEwETFhoSFyQUDg9ZV1kYEgtZQVlJSUlVSkJKVUlPTVVJT0lZV1kWGg8SFR0UWUFZT0tIVUpLSE pPSExVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=ibOsf5HwXz/CY07TG0jgmH5PQqIvHGw4W50Q2zgE9wHBO5rZQ4/iMcnilDDCpnZhXL8guqo9PoDEkQ6v6pxo4/8bdlhh2CNuoix7QQxTvOuKo7HOMlJVgzthd7ZvN4NgRO45MCbm0sxlhzmcvnlUjJW6rrZmyvfNBtb7dlkWdm0=; c=relaxed/relaxed; s=default; d=seu.edu.cn; v=1; bh=FrHsZaSHjKajBX0rdMRb30xqwkz5sNsC48iENtcmYd8=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" Configfs store callbacks may open user-configured paths while holding an item frag_sem. Opening a configfs path from such a callback can re-enter configfs and try to acquire the same semaphore. Add helpers that reject configfs paths by comparing the actual filesystem type and open the resolved path with file_open_root(), preserving normal open-time permission and security checks. Provide a root-relative form for callers that retain a resolved root and may create a file below it. Assisted-by: LLM Codex Signed-off-by: Runyu Xiao --- fs/configfs/mount.c | 33 +++++++++++++++++++++++++++++++++ include/linux/configfs.h | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c index d8cac1cbf3bd5..77e1788ce2372 100644 --- a/fs/configfs/mount.c +++ b/fs/configfs/mount.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -118,6 +119,38 @@ static struct file_system_type configfs_fs_type =3D { }; MODULE_ALIAS_FS("configfs"); =20 +bool configfs_path_is_configfs(const struct path *path) +{ + return path->dentry->d_sb->s_type =3D=3D &configfs_fs_type; +} +EXPORT_SYMBOL_GPL(configfs_path_is_configfs); + +struct file *configfs_open_root(const struct path *root, const char *name, + int flags, umode_t mode) +{ + if (configfs_path_is_configfs(root)) + return ERR_PTR(-EINVAL); + + return file_open_root(root, name, flags, mode); +} +EXPORT_SYMBOL_GPL(configfs_open_root); + +struct file *configfs_file_open(const char *filename, int flags, umode_t m= ode) +{ + struct file *file; + struct path path; + int ret; + + ret =3D kern_path(filename, LOOKUP_FOLLOW, &path); + if (ret) + return ERR_PTR(ret); + + file =3D configfs_open_root(&path, "", flags, mode); + path_put(&path); + return file; +} +EXPORT_SYMBOL_GPL(configfs_file_open); + struct dentry *configfs_pin_fs(void) { int err =3D simple_pin_fs(&configfs_fs_type, &configfs_mount, diff --git a/include/linux/configfs.h b/include/linux/configfs.h index ef65c75beeaad..768132b2be1ae 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -34,6 +34,8 @@ struct configfs_group_operations; struct configfs_attribute; struct configfs_bin_attribute; struct configfs_subsystem; +struct file; +struct path; =20 struct config_item { char *ci_name; @@ -243,6 +245,10 @@ void configfs_unregister_subsystem(struct configfs_sub= system *subsys); int configfs_register_group(struct config_group *parent_group, struct config_group *group); void configfs_unregister_group(struct config_group *group); +bool configfs_path_is_configfs(const struct path *path); +struct file *configfs_open_root(const struct path *root, const char *name, + int flags, umode_t mode); +struct file *configfs_file_open(const char *filename, int flags, umode_t m= ode); =20 void configfs_remove_default_groups(struct config_group *group); =20 --=20 2.34.1 From nobody Thu Sep 24 20:04:08 2026 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D818A45041C; Mon, 21 Sep 2026 09:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981612; cv=none; b=rT4/RCw3ZTV5Ea/kDf14hr+Fn1I/8/sdYd3ykeAX8tsMqDJp3jvQ7EIQ+uYDmbJ2kJ/pL2R9q3yvWp9xr7ukymyhG+vfa+mZmBE5CXm/nvJ56COrMiASEB/A0SiO7aVg1Zk8/hfPkDKDuQI395//91HodfgvZZ9oNjqPHaYZZs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981612; c=relaxed/simple; bh=itRd7GtKOrHPOaG8Qi01tj/V/+p1/41tRd8I0FxtH40=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HcObIcuE9grvjZ3GhI8omUdX9TOj9Joe7LmiYzxESRviEseun0dNxj+3vHxywOKIHBBxphsrupdZJDsQ2168c1YS0IywcKIU5JwyZgTl1ECgXmPyHEmvbTvzDYbm84Kp1ufyp+rqWF9+HBirXqZXo+2iUZp4slKxxvXKVBspFhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=PliqQQXE; arc=none smtp.client-ip=101.71.155.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="PliqQQXE" Received: from PC-202605011814.localdomain (unknown [222.191.246.242]) by smtp.qiye.163.com (Hmail) with ESMTP id 4e8e74662; Mon, 21 Sep 2026 17:06:44 +0800 (GMT+08:00) From: Runyu Xiao To: Christoph Hellwig Cc: Sagi Grimberg , Chaitanya Kulkarni , Andreas Hindborg , Breno Leitao , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Runyu Xiao , Jianhao Xu Subject: [PATCH v4 2/3] nvmet: avoid recursive configfs open for file-backed namespaces Date: Mon, 21 Sep 2026 17:05:58 +0800 Message-Id: <20260921090559.41364-3-runyu.xiao@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921090559.41364-1-runyu.xiao@seu.edu.cn> References: <20260921090559.41364-1-runyu.xiao@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0aa0c337bb2603a1kunm2bb71b5a4117b X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlDGR0eVhoaHUkYHh9CGB5KSVYeHw 5VEwETFhoSFyQUDg9ZV1kYEgtZQVlJSUlVSkJKVUlPTVVJT0lZV1kWGg8SFR0UWUFZT0tIVUpLSE pPSExVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=PliqQQXEERXIZvW4UdVd0d8SiaE4qlJYWjTnJBp3/NlHEJKZRF5SZJsUJKh5WeVOS5VCa8RqDw1xPmlDcTQcfOjJq6dvrLzP168av1cGW90lfWu2tF39lGbnl8rZIEtrPl7bXSTBR+tlaqYkzxhh+5dyqgUT1hML6u5grdezJ1o=; c=relaxed/relaxed; s=default; d=seu.edu.cn; v=1; bh=YtRF6Vta+5vZ+xMHLfaKypEUxsauMMO8lTqR07dKzD8=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" nvmet_ns_enable_store() runs as a configfs store callback while configfs holds the item frag_sem. File-backed namespace enable used filp_open() on the configured device_path, so a path into configfs could re-enter __configfs_open_file() and try to acquire the same semaphore again. Use configfs_file_open() so the path is resolved before opening, configfs-backed paths are rejected, and the resolved path is opened with file_open_root() while retaining the normal open-time permission and security checks. Fixes: d5eff33ee6f8 ("nvmet: add simple file backed ns support") Cc: stable@vger.kernel.org Assisted-by: LLM Codex Signed-off-by: Runyu Xiao Reviewed-by: Christoph Hellwig --- drivers/nvme/target/io-cmd-file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd= -file.c index 0b22d183f9279..2a4f25de94ba1 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "nvmet.h" =20 @@ -38,7 +39,7 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) if (!ns->buffered_io) flags |=3D O_DIRECT; =20 - ns->file =3D filp_open(ns->device_path, flags, 0); + ns->file =3D configfs_file_open(ns->device_path, flags, 0); if (IS_ERR(ns->file)) { ret =3D PTR_ERR(ns->file); pr_err("failed to open file %s: (%d)\n", --=20 2.34.1 From nobody Thu Sep 24 20:04:08 2026 Received: from mail-m49197.qiye.163.com (mail-m49197.qiye.163.com [45.254.49.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0765245D5D0; Mon, 21 Sep 2026 09:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981617; cv=none; b=bx2+Wqwc9CE/JRQR3pfXDn9W1/FqIA6xhGOVwXVWv2q1YcB0v0ID1VQheqCZJ48k2rq2tXkP1Q37p+UsbHgBthv26dAuJusUV6As1+QrBps2mB0T9wy7RsuWzcxpJyFEe6cO1RTvzv5GI5h1r/CV3SrZ8B5kRmL/sbDajdC9FKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981617; c=relaxed/simple; bh=OodoNLFg2xb6tTS7hEsElmY4bLlXqZ+aPssM8ZCmQDI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UjunhBPVp56d7fBvRhFfFWIY57btXu4s8YbsORFNgQP2X8vM32u65ylObMFt2BEwGbES+XUIi6IJrLseQFSt+jyleOjvBQV06y7onAf7XSYJ/NNWFTJRMoS7E9LiiIyiJueCJoENHLtFwaIu0Mq6mdoYT8l2gPjCF2h8WQ+APh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=cqt1IbQE; arc=none smtp.client-ip=45.254.49.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="cqt1IbQE" Received: from PC-202605011814.localdomain (unknown [222.191.246.242]) by smtp.qiye.163.com (Hmail) with ESMTP id 4e8e74667; Mon, 21 Sep 2026 17:06:47 +0800 (GMT+08:00) From: Runyu Xiao To: Christoph Hellwig Cc: Sagi Grimberg , Chaitanya Kulkarni , Andreas Hindborg , Breno Leitao , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Runyu Xiao , Jianhao Xu Subject: [PATCH v4 3/3] nvmet: avoid recursive configfs open for passthru Date: Mon, 21 Sep 2026 17:05:59 +0800 Message-Id: <20260921090559.41364-4-runyu.xiao@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921090559.41364-1-runyu.xiao@seu.edu.cn> References: <20260921090559.41364-1-runyu.xiao@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0aa0c337c68503a1kunm2bb71b5a4118c X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlCTktIVk1ITUNDHkwaGUwdSVYeHw 5VEwETFhoSFyQUDg9ZV1kYEgtZQVlJSUlVSkJKVUlPTVVJT0lZV1kWGg8SFR0UWUFZT0tIVUpLSE pPSExVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=cqt1IbQEYPOqcbALyJChXnIjSiaYdgh3M/ImKPVJj1KzjMfUD2eVrZrd0eAyY8fs//gMv6nhry/1cZYemB1L+5VvhxJ1jMe9BCTw+OW+10H+lhfynLfTlg0fQ9ZEj0oNE5iRDWSu60/SDpUhgaIVVFp+ZwPjkJGQ6+A/POfvJg8=; c=relaxed/relaxed; s=default; d=seu.edu.cn; v=1; bh=PCqoKYBxp3/57YeeKIDVPJH+6QZu8Y/TZGIX+utFJO0=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" nvmet_passthru_enable_store() runs as a configfs store callback while configfs holds the item frag_sem. Passthru enable used filp_open() on the configured controller path, so a path into configfs could re-enter __configfs_open_file() and try to acquire the same semaphore again. Use configfs_file_open() so the path is resolved before opening, configfs-backed paths are rejected, and the resolved path is opened with file_open_root() while retaining the normal open-time permission and security checks. Fixes: cae5b01a2afc ("nvmet: introduce the passthru configfs interface") Cc: stable@vger.kernel.org Assisted-by: LLM Codex Signed-off-by: Runyu Xiao Reviewed-by: Christoph Hellwig --- drivers/nvme/target/passthru.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index fa6527c537e26..d60256004e6cf 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -9,6 +9,7 @@ */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include =20 #include "../host/nvme.h" #include "nvmet.h" @@ -602,7 +603,7 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *sub= sys) goto out_unlock; } =20 - file =3D filp_open(subsys->passthru_ctrl_path, O_RDWR, 0); + file =3D configfs_file_open(subsys->passthru_ctrl_path, O_RDWR, 0); if (IS_ERR(file)) { ret =3D PTR_ERR(file); goto out_unlock; --=20 2.34.1