Skip to contentSkip to conversation

nvmet: nul-terminate the NQNs passed in the connect command

PATCH In review Christoph Hellwig 3 participants 4 messages Nov 17, 2023

Subsystems (2)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH v2 1/1 nvmet: nul-terminate the NQNs passed in the connect command

The host and subsystem NQNs are passed in the connect command payload and interpreted as nul-terminated strings. Ensure they actually are nul-terminated before using them.

Fixes a07b4970f464 "nvmet: add a generic NVMe target")
---
 drivers/nvme/target/fabrics-cmd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/nvme/target/fabrics-cmd.c +4 -0
index 43b5bd8bb6a52d..d8da840a1c0ed1 100644
@@ -244,6 +244,8 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
 		goto out;
 	}
 
+	d->subsysnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
+	d->hostnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
 	status = nvmet_alloc_ctrl(d->subsysnqn, d->hostnqn, req,
 				  le32_to_cpu(c->kato), &ctrl);
 	if (status)
@@ -313,6 +315,8 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
 		goto out;
 	}
 
+	d->subsysnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
+	d->hostnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
 	ctrl = nvmet_ctrl_find_get(d->subsysnqn, d->hostnqn,
 				   le16_to_cpu(d->cntlid), req);
 	if (!ctrl) {
Signature · 1 line
2.39.2
#2 lore raw
Quoted 11 lines · Keith Busch
Quoted 7 lines · Christoph Hellwig

The host and subsystem NQNs are passed in the connect command payload and interpreted as nul-terminated strings. Ensure they actually are nul-terminated before using them.

Fixes a07b4970f464 "nvmet: add a generic NVMe target")

Applied for nvme-6.7, thanks!

if this is on the top of the tree can you please add my reviewed-by tag posted earlier ?

-ck

Reviewed-by on v2 1/1
#3 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

The host and subsystem NQNs are passed in the connect command payload and interpreted as nul-terminated strings. Ensure they actually are nul-terminated before using them.

Fixes a07b4970f464 "nvmet: add a generic NVMe target")

---

-ck