Skip to contentSkip to conversation

nvmet: validate device_path before enabling namespace

PATCH In review [email protected] 2 participants 3 messages Sep 8 – Sep 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet: validate device_path before enabling namespace

From: Yalagada Pavan Kumar <[email protected]>

When buffered_io is enabled, nvmet_bdev_ns_enable() returns -ENOTBLK without checking whether device_path is configured. nvmet_ns_enable() then falls back to nvmet_file_ns_enable(), which passes the NULL device_path to filp_open() and causes a NULL pointer dereference.

Validate device_path before attempting to enable to namespace and return -EINVAL when it has not been configured.

Fixes 6f6d604b4ef8 ("nvmet: allow bdev in buffered_io mode")
Reported-by [email protected]
---
 drivers/nvme/target/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/target/core.c +5 -0
index d74c01c98f19..336013139ef6 100644
@@ -591,6 +591,11 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
 	if (ns->enabled)
 		goto out_unlock;
 
+	if (!ns->device_path) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
 	ret = nvmet_bdev_ns_enable(ns);
 	if (ret == -ENOTBLK)
 		ret = nvmet_file_ns_enable(ns);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · On Wed, Sep 09, 2026 at 01:04:52AM +0530, [email protected] wrote:

From: Yalagada Pavan Kumar <[email protected]>

When buffered_io is enabled, nvmet_bdev_ns_enable() returns -ENOTBLK without checking whether device_path is configured. nvmet_ns_enable() then falls back to nvmet_file_ns_enable(), which passes the NULL device_path to filp_open() and causes a NULL pointer dereference.

Validate device_path before attempting to enable to namespace and return -EINVAL when it has not been configured.

This was alraedy closed:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=09d0c07bd9ce3b2f2d993f672698d32a17543c32

#2 lore raw
Quoted 8 lines · Keith Busch
Quoted 7 lines · On Wed, Sep 09, 2026 at 01:04:52AM +0530, [email protected] wrote:

From: Yalagada Pavan Kumar <[email protected]>

When buffered_io is enabled, nvmet_bdev_ns_enable() returns -ENOTBLK without checking whether device_path is configured. nvmet_ns_enable() then falls back to nvmet_file_ns_enable(), which passes the NULL device_path to filp_open() and causes a NULL pointer dereference.

Quoted 6 lines
Quoted 2 lines

Validate device_path before attempting to enable to namespace and return -EINVAL when it has not been configured.

This was alraedy closed:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=09d0c07bd9ce3b2f2d993f672698d32a17543c32

Good to hear this has already been fixed. I'll drop the patch.

Thanks
Pavan