linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme: host: core: fix NULL pointer dereference in nvme_pr_command
@ 2017-11-13 19:36 Gustavo A. R. Silva
  2017-11-13 19:38 ` Sagi Grimberg
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2017-11-13 19:36 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, linux-kernel, Gustavo A. R. Silva

_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@embeddedor.com>
---
 drivers/nvme/host/core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 25da74d..9b9c324 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvme: host: core: fix NULL pointer dereference in nvme_pr_command
  2017-11-13 19:36 [PATCH] nvme: host: core: fix NULL pointer dereference in nvme_pr_command Gustavo A. R. Silva
@ 2017-11-13 19:38 ` Sagi Grimberg
  0 siblings, 0 replies; 2+ messages in thread
From: Sagi Grimberg @ 2017-11-13 19:38 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Keith Busch, Jens Axboe, Christoph Hellwig
  Cc: linux-nvme, linux-kernel

Looks good,

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-13 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 19:36 [PATCH] nvme: host: core: fix NULL pointer dereference in nvme_pr_command Gustavo A. R. Silva
2017-11-13 19:38 ` Sagi Grimberg

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).