linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: <ngottlieb@nvidia.com>
To: <mgurtovoy@nvidia.com>, <sagi@grimberg.me>, <hch@lst.de>,
	<kbusch@kernel.org>, <chaitanya.kulkarni@wdc.com>,
	<linux-nvme@lists.infradead.org>
Cc: Noam Gottlieb <ngottlieb@nvidia.com>
Subject: [PATCH 1/1] nvmet: do not allow model_number exceed 40 bytes
Date: Mon, 15 Mar 2021 14:56:11 +0000	[thread overview]
Message-ID: <20210315145611.155972-1-ngottlieb@nvidia.com> (raw)

From: Noam Gottlieb <ngottlieb@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@nvidia.com>
Signed-off-by: Noam Gottlieb <ngottlieb@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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

             reply	other threads:[~2021-03-15 14:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 14:56 ngottlieb [this message]
2021-03-15 21:10 ` [PATCH 1/1] nvmet: do not allow model_number exceed 40 bytes Chaitanya Kulkarni
2021-03-15 21:50   ` Sagi Grimberg
2021-03-16  3:40     ` Chaitanya Kulkarni
2021-03-16  8:35       ` Max Gurtovoy
2021-03-16 18:30         ` Sagi Grimberg
2021-03-16 18:32         ` Chaitanya Kulkarni
2021-03-18  5:18 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210315145611.155972-1-ngottlieb@nvidia.com \
    --to=ngottlieb@nvidia.com \
    --cc=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mgurtovoy@nvidia.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).