Skip to content

Commit 1c22e02

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
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: a07b497 "nvmet: add a generic NVMe target") Reported-by: Alon Zahavi <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent c7ca975 commit 1c22e02

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/nvme/target/fabrics-cmd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
244244
goto out;
245245
}
246246

247+
d->subsysnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
248+
d->hostnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
247249
status = nvmet_alloc_ctrl(d->subsysnqn, d->hostnqn, req,
248250
le32_to_cpu(c->kato), &ctrl);
249251
if (status)
@@ -313,6 +315,8 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
313315
goto out;
314316
}
315317

318+
d->subsysnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
319+
d->hostnqn[NVMF_NQN_FIELD_LEN - 1] = '\0';
316320
ctrl = nvmet_ctrl_find_get(d->subsysnqn, d->hostnqn,
317321
le16_to_cpu(d->cntlid), req);
318322
if (!ctrl) {

0 commit comments

Comments
 (0)