Skip to contentSkip to conversation

nvmet: Identify-Active Namespace ID List command should reject invalid nsid

PATCH Superseded Maurizio Lombardi 2 participants 2 messages Aug 28, 2024 – Aug 29, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet: Identify-Active Namespace ID List command should reject invalid nsid

nsid values of 0xFFFFFFFE and 0XFFFFFFFF should be rejected with a status code of "Invalid Namespace or Format".
See NVMe Base Specification, Active Namespace ID list (CNS 02h).

Fixes a07b4970f464 ("nvmet: add a generic NVMe target")
---
 drivers/nvme/target/admin-cmd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/nvme/target/admin-cmd.c +6 -0
index f7e1156ac7ec..d37bb1cb94fa 100644
@@ -587,6 +587,12 @@ static void nvmet_execute_identify_nslist(struct nvmet_req *req)
 	u16 status = 0;
 	int i = 0;
 
+	if (min_nsid >= NVME_NSID_ALL - 1) {
+		req->error_loc = offsetof(struct nvme_identify, nsid);
+		status = NVME_SC_INVALID_NS | NVME_STATUS_DNR;
+		goto out;
+	}
+
 	list = kzalloc(buf_size, GFP_KERNEL);
 	if (!list) {
 		status = NVME_SC_INTERNAL;
Signature · 1 line
2.43.5
#1 lore raw

drivers/nvme/target/admin-cmd.c static void nvmet_execute_identify_nslist(struct nvmet_req *req) · line 590

Quoted 1 line · Maurizio Lombardi
drivers/nvme/target/admin-cmd.c +1 -0
+	if (min_nsid >= NVME_NSID_ALL - 1) {

It would almost seem cleaner to check for the two magic constant. Either way please put a comment in with the spec reference as the code is rather non-obvious with out.