nvme: verify MNAN value if ANA is enabled
authorDaniel Wagner <dwagner@suse.de>
Mon, 7 Jun 2021 08:56:56 +0000 (10:56 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 16 Jun 2021 03:36:15 +0000 (05:36 +0200)
The controller is required to have a non-zero MNAN value if it supports
ANA:

   If the controller supports Asymmetric Namespace Access Reporting, then
   this field shall be set to a non-zero value that is less than or equal
   to the NN value.

Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/multipath.c

index 127a17b..9842623 100644 (file)
@@ -818,6 +818,13 @@ int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
            !(ctrl->subsys->cmic & NVME_CTRL_CMIC_ANA))
                return 0;
 
+       if (!ctrl->max_namespaces ||
+           ctrl->max_namespaces > le32_to_cpu(id->nn)) {
+               dev_err(ctrl->device,
+                       "Invalid MNAN value %u\n", ctrl->max_namespaces);
+               return -EINVAL;
+       }
+
        ctrl->anacap = id->anacap;
        ctrl->anatt = id->anatt;
        ctrl->nanagrpid = le32_to_cpu(id->nanagrpid);