Skip to contentSkip to conversation

nvme: host: core: fix NULL pointer dereference in nvme_pr_command

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Nov 13, 2017 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: host: core: fix NULL pointer dereference in nvme_pr_command

_head_ pointer is being dereferenced when it is NULL.

Fix this by moving the code that dereferences such pointer after it has been properly initialized in function nvme_get_ns_from_disk.

Addresses-Coverity-ID: 1461344

Fixes 32acab3181c7 ("nvme: implement multipath access to nvme subsystems")
Signed-off-by Gustavo A. R. Silva <garsilva at embeddedor.com>
---
 drivers/nvme/host/core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/nvme/host/core.c +7 -7
index 25da74d..9b9c324 100644
@@ -1452,16 +1452,16 @@ static int nvme_pr_command(struct block_device *bdev, u32 cdw10,
 	put_unaligned_le64(key, &data[0]);
 	put_unaligned_le64(sa_key, &data[8]);
 
-	memset(&c, 0, sizeof(c));
-	c.common.opcode = op;
-	c.common.nsid = cpu_to_le32(head->ns_id);
-	c.common.cdw10[0] = cpu_to_le32(cdw10);
-
 	ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
-	if (unlikely(!ns))
+	if (unlikely(!ns)) {
 		ret = -EWOULDBLOCK;
-	else
+	} else {
+		memset(&c, 0, sizeof(c));
+		c.common.opcode = op;
+		c.common.nsid = cpu_to_le32(head->ns_id);
+		c.common.cdw10[0] = cpu_to_le32(cdw10);
 		ret = nvme_submit_sync_cmd(ns->queue, &c, data, 16);
+	}
 	nvme_put_ns_from_disk(head, srcu_idx);
 	return ret;
 }
Signature · 1 line
2.7.4
maintainer Reviewed-by on v1 1/1
#1 lore raw

Looks good,

Reviewed-by Sagi Grimberg <sagi at grimberg.me>