[PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz

Guixin Liu kanie at linux.alibaba.com
Mon Dec 4 23:37:40 PST 2023


Make sure that ioccsz and iorcsz returned by target
are correct before use it.

Per 2.0a base NVMe spec:
I/O Queue Command Capsule Supported Size (IOCCSZ): This field defines
the maximum I/O command capsule size in 16 byte units. The minimum value
that shall be indicated is 4 corresponding to 64 bytes.
I/O Queue Response Capsule Supported Size (IORCSZ): This field defines
the maximum I/O response capsule size in 16 byte units. The minimum
value that shall be indicated is 1 corresponding to 16 bytes.

Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
---
 drivers/nvme/host/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4da6ee6..87db4a9 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3043,6 +3043,20 @@ static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ct
 		return -EINVAL;
 	}
 
+	if (ctrl->ioccsz < 4) {
+		dev_err(ctrl->device,
+			"I/O queue command capsule supported size %d < 4\n",
+			ctrl->ioccsz);
+		return -EINVAL;
+	}
+
+	if (ctrl->iorcsz < 1) {
+		dev_err(ctrl->device,
+			"I/O queue response capsule supported size %d < 1\n",
+			ctrl->iorcsz);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
1.8.3.1




More information about the Linux-nvme mailing list