Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: emilne@redhat.com (Ewan D. Milne)
Subject: [PATCH 1/1] nvme-fc: avoid memory corruption caused by calling nvmf_free_options() twice
Date: Mon, 24 Apr 2017 13:24:16 -0400	[thread overview]
Message-ID: <1493054656-18296-2-git-send-email-emilne@redhat.com> (raw)
In-Reply-To: <1493054656-18296-1-git-send-email-emilne@redhat.com>

From: "Ewan D. Milne" <emilne@redhat.com>

Do not call nvmf_free_options() from the nvme_fc_ctlr destructor if
nvme_fc_create_ctrl() returns an error, because nvmf_create_ctrl()
frees the options when an error is returned.

Signed-off-by: Ewan D. Milne <emilne at redhat.com>
---
 drivers/nvme/host/fc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 890e096..9da98ec 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -1716,7 +1716,8 @@ enum {
 	nvme_fc_rport_put(ctrl->rport);
 
 	ida_simple_remove(&nvme_fc_ctrl_cnt, ctrl->cnum);
-	nvmf_free_options(ctrl->ctrl.opts);
+	if (ctrl->ctrl.opts)
+		nvmf_free_options(ctrl->ctrl.opts);
 	kfree(ctrl);
 }
 
@@ -2821,6 +2822,7 @@ enum blk_eh_timer_return
 
 	ret = nvme_fc_create_association(ctrl);
 	if (ret) {
+		ctrl->ctrl.opts = NULL;
 		/* initiate nvme ctrl ref counting teardown */
 		nvme_uninit_ctrl(&ctrl->ctrl);
 		nvme_put_ctrl(&ctrl->ctrl);
-- 
1.8.3.1

  reply	other threads:[~2017-04-24 17:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 17:24 [PATCH 0/1] Fix crash when failing to connect to FC NVMe target Ewan D. Milne
2017-04-24 17:24 ` Ewan D. Milne [this message]
2017-04-25 17:54   ` [PATCH 1/1] nvme-fc: avoid memory corruption caused by calling nvmf_free_options() twice Christoph Hellwig
2017-04-25 17:57     ` Christoph Hellwig
2017-04-25 18:00       ` 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=1493054656-18296-2-git-send-email-emilne@redhat.com \
    --to=emilne@redhat.com \
    /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