Skip to contentSkip to conversation

nvmet: reject namespace enable without device path

PATCH Applied Seokgyu Choi 4 participants 4 messages Aug 27 – Sep 2

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

PATCH 1/1 nvmet: reject namespace enable without device path

A newly allocated namespace has a NULL device_path until userspace configures the device_path attribute.

If buffered_io is enabled before device_path is configured, nvmet_bdev_ns_enable() returns -ENOTBLK and nvmet_ns_enable() falls back to nvmet_file_ns_enable(). The latter passes the NULL device_path to filp_open(), causing a NULL pointer dereference in getname_kernel().

Reject namespace enable when device_path has not been configured.

---
 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.53.0
maintainer Applied
#3 lore raw
In reply to Seokgyu Choi
Quoted 10 lines · Seokgyu Choi

A newly allocated namespace has a NULL device_path until userspace configures the device_path attribute.

If buffered_io is enabled before device_path is configured, nvmet_bdev_ns_enable() returns -ENOTBLK and nvmet_ns_enable() falls back to nvmet_file_ns_enable(). The latter passes the NULL device_path to filp_open(), causing a NULL pointer dereference in getname_kernel().

Reject namespace enable when device_path has not been configured.

Thanks, applied to nvme-7.3.