Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: hare@suse.de (Hannes Reinecke)
Subject: [PATCH 2/2] nvme: validate cntlid during controller initialisation
Date: Thu,  4 Apr 2019 00:41:58 +0200	[thread overview]
Message-ID: <20190403224158.58106-3-hare@suse.de> (raw)
In-Reply-To: <20190403224158.58106-1-hare@suse.de>

From: Hannes Reinecke <hare@suse.com>

The CNTLID value is required to be unique, and we do rely on this
for correct operation. So reject any controller for which a non-unique
CNTLID has been detected.

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 drivers/nvme/host/core.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index b5939112b9b6..23000a368e1f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2485,6 +2485,7 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl)
 int nvme_init_identify(struct nvme_ctrl *ctrl)
 {
 	struct nvme_id_ctrl *id;
+	struct nvme_ctrl *tmp;
 	u64 cap;
 	int ret, page_shift;
 	u32 max_hw_sectors;
@@ -2624,7 +2625,20 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
 	}
 
-	ret = nvme_mpath_init(ctrl, id);
+	ret = 0;
+	mutex_lock(&ctrl->subsys->lock);
+	list_for_each_entry(tmp, &ctrl->subsys->ctrls, subsys_entry) {
+		if (tmp->cntlid == ctrl->cntlid) {
+			dev_err(ctrl->device, "Duplicate cntlid %u, rejecting\n",
+				ctrl->cntlid);
+			ret = -EINVAL;
+			break;
+		}
+	}
+	mutex_unlock(&ctrl->subsys->lock);
+
+	if (ret == 0)
+		ret = nvme_mpath_init(ctrl, id);
 	kfree(id);
 
 	if (ret < 0)
-- 
2.16.4

  parent reply	other threads:[~2019-04-03 22:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 22:41 [PATCH 0/2] nvme: validate CNTLID Hannes Reinecke
2019-04-03 22:41 ` [PATCH 1/2] nvme-multipath: avoid crash on invalid subsystem cntlid enumeration Hannes Reinecke
2019-05-03 11:04   ` Hannes Reinecke
2019-05-03 11:31     ` Christoph Hellwig
2019-04-03 22:41 ` Hannes Reinecke [this message]
2019-04-04  5:26   ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2019-05-13  6:25 detect duplicate cntlids v2 Christoph Hellwig
2019-05-13  6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
2019-05-13  6:36   ` Hannes Reinecke
2019-05-13 15:16   ` Chaitanya Kulkarni
2019-05-13 18:25   ` Heitke, Kenneth
2019-08-30 18:24   ` James Smart
2019-08-30 18:30     ` Sagi Grimberg

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=20190403224158.58106-3-hare@suse.de \
    --to=hare@suse.de \
    /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