public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] nvme: fix memleak in nvme_ctrl_dhchap_secret_store()
@ 2022-11-21  6:21 Zhang Qilong
  2022-11-21  9:51 ` Sagi Grimberg
  0 siblings, 1 reply; 7+ messages in thread
From: Zhang Qilong @ 2022-11-21  6:21 UTC (permalink / raw)
  To: hare, kbusch, axboe, hch, sagi; +Cc: linux-nvme

If dhchap_secret is not consistent with options or
nvme_auth_generate_key() fails, we should free the
memory of dhchap_secret to avoid memleak.

Fixes: f50fff73d620 ("nvme: implement In-Band authentication")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/nvme/host/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index da55ce45ac70..e06d1b3961fe 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3748,13 +3748,16 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
 		int ret;
 
 		ret = nvme_auth_generate_key(dhchap_secret, &ctrl->host_key);
-		if (ret)
+		if (ret) {
+			kfree(dhchap_secret);
 			return ret;
+		}
 		kfree(opts->dhchap_secret);
 		opts->dhchap_secret = dhchap_secret;
 		/* Key has changed; re-authentication with new key */
 		nvme_auth_reset(ctrl);
-	}
+	} else
+		kfree(dhchap_secret);
 	/* Start re-authentication */
 	dev_info(ctrl->device, "re-authenticating controller\n");
 	queue_work(nvme_wq, &ctrl->dhchap_auth_work);
-- 
2.25.1



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

end of thread, other threads:[~2022-11-21 15:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-21  6:21 [PATCH] nvme: fix memleak in nvme_ctrl_dhchap_secret_store() Zhang Qilong
2022-11-21  9:51 ` Sagi Grimberg
2022-11-21 11:33   ` 答复: " zhangqilong
2022-11-21 11:39     ` Sagi Grimberg
2022-11-21 11:54       ` 答复: " zhangqilong
2022-11-21 14:23         ` Sagi Grimberg
2022-11-21 15:09           ` 答复: " zhangqilong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox