[PATCH 1/1] nvmet: do not allow model_number exceed 40 bytes

ngottlieb at nvidia.com ngottlieb at nvidia.com
Mon Mar 15 14:56:11 GMT 2021


From: Noam Gottlieb <ngottlieb at nvidia.com>

According to the NVM specifications, the model number size should be
40 bytes (bytes 63:24 of the Identify Controller data structure).
Therefore, any attempt to store a value into model_number which
exceeds 40 bytes should return an error.

Reviewed-by: Max Gurtovoy <mgurtovoy at nvidia.com>
Signed-off-by: Noam Gottlieb <ngottlieb at nvidia.com>
---
 drivers/nvme/target/configfs.c | 6 ++++++
 drivers/nvme/target/nvmet.h    | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 635a7cb45d0b..40c8980387a6 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -1150,6 +1150,12 @@ static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
 	if (!len)
 		return -EINVAL;
 
+	if (len > NVMET_MN_MAX_SIZE) {
+		pr_err("Model nubmer size can not exceed %d Bytes\n",
+		       NVMET_MN_MAX_SIZE);
+		return -EINVAL;
+	}
+
 	for (pos = 0; pos < len; pos++) {
 		if (!nvmet_is_ascii(page[pos]))
 			return -EINVAL;
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index cdfa537b1c0a..6871dd2884f9 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -27,6 +27,7 @@
 #define NVMET_ERROR_LOG_SLOTS		128
 #define NVMET_NO_ERROR_LOC		((u16)-1)
 #define NVMET_DEFAULT_CTRL_MODEL	"Linux"
+#define NVMET_MN_MAX_SIZE		40
 
 /*
  * Supported optional AENs:
-- 
2.18.2




More information about the Linux-nvme mailing list