Commit 7db6d22f authored by Dor Deri's avatar Dor Deri Committed by Tomasz Zawadzki
Browse files

nvmf: validate NSID for Identify CNS 03h command



According to NVMe specification r1.4, section 5.15.2.4, the controller
shall return the descriptor list only if the NSID field specifies an
active namespace. If the NSID is inactive, the controller shall abort
the command with the status Invalid Field in Command. If the NSID is
invalid, the controller shall abort the command with the status Invalid
Namespace or Format.

Change-Id: I88212b1a3f133855afeb59243fa4c0f5f2de0767
Signed-off-by: default avatarDor Deri <dor.deri@dell.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26583


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent 9312b259
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -3345,14 +3345,23 @@ nvmf_ctrlr_identify_ns_id_descriptor_list(
	struct spdk_nvmf_ns *ns;
	size_t buf_remain = id_desc_list_size;
	void *buf_ptr = id_desc_list;
	uint32_t nsid = cmd->nsid;

	ns = nvmf_ctrlr_get_ns(ctrlr, cmd->nsid);
	if (ns == NULL || ns->bdev == NULL) {
	if (nsid == 0 || nsid > ctrlr->subsys->max_nsid) {
		SPDK_ERRLOG("Identify Namespace Identification Descriptor list with invalid NSID %u\n", nsid);
		rsp->status.sct = SPDK_NVME_SCT_GENERIC;
		rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}

	ns = nvmf_ctrlr_get_ns(ctrlr, nsid);
	if (ns == NULL || ns->bdev == NULL) {
		SPDK_ERRLOG("Identify Namespace Identification Descriptor list with inactive NSID %u\n", nsid);
		rsp->status.sct = SPDK_NVME_SCT_GENERIC;
		rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}

#define ADD_ID_DESC(type, data, size) \
	do { \
		if (!spdk_mem_all_zero(data, size)) { \
+1 −1
Original line number Diff line number Diff line
@@ -1062,7 +1062,7 @@ test_get_ns_id_desc_list(void)
	memset(&rsp, 0, sizeof(rsp));
	CU_ASSERT(nvmf_ctrlr_process_admin_cmd(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
	CU_ASSERT(rsp.nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
	CU_ASSERT(rsp.nvme_cpl.status.sc == SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT);
	CU_ASSERT(rsp.nvme_cpl.status.sc == SPDK_NVME_SC_INVALID_FIELD);

	/* Valid NSID, but ns has no IDs defined */
	spdk_bit_array_set(ctrlr.visible_ns, 0);