From: Sagi Grimberg <sagi@grimberg.me>
To: linux-nvme@lists.infradead.org
Cc: Christoph Hellwig <hch@lst.de>, Keith Busch <kbusch@kernel.org>,
Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>,
Hannes Reinecke <hare@suse.de>
Subject: [PATCH 6/6] nvme-auth: don't override ctrl keys before validation
Date: Tue, 25 Oct 2022 16:43:30 +0300 [thread overview]
Message-ID: <20221025134330.1028352-7-sagi@grimberg.me> (raw)
In-Reply-To: <20221025134330.1028352-1-sagi@grimberg.me>
Replace ctrl ctrl_key/host_key only after nvme_auth_generate_key is successful.
Also, this fixes a bug where the keys are leaked.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/host/core.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9b0b11191ed9..ae1bc79cd712 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3756,13 +3756,17 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
memcpy(dhchap_secret, buf, count);
nvme_auth_stop(ctrl);
if (strcmp(dhchap_secret, opts->dhchap_secret)) {
+ struct nvme_dhchap_key *key, *host_key;
int ret;
- ret = nvme_auth_generate_key(dhchap_secret, &ctrl->host_key);
+ ret = nvme_auth_generate_key(dhchap_secret, &key);
if (ret)
return ret;
kfree(opts->dhchap_secret);
opts->dhchap_secret = dhchap_secret;
+ host_key = ctrl->host_key;
+ ctrl->host_key = key;
+ nvme_auth_free_key(host_key);
/* Key has changed; re-authentication with new key */
nvme_auth_reset(ctrl);
}
@@ -3806,13 +3810,17 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
memcpy(dhchap_secret, buf, count);
nvme_auth_stop(ctrl);
if (strcmp(dhchap_secret, opts->dhchap_ctrl_secret)) {
+ struct nvme_dhchap_key *key, *ctrl_key;
int ret;
- ret = nvme_auth_generate_key(dhchap_secret, &ctrl->ctrl_key);
+ ret = nvme_auth_generate_key(dhchap_secret, &key);
if (ret)
return ret;
kfree(opts->dhchap_ctrl_secret);
opts->dhchap_ctrl_secret = dhchap_secret;
+ ctrl_key = ctrl->ctrl_key;
+ ctrl->ctrl_key = key;
+ nvme_auth_free_key(ctrl_key);
/* Key has changed; re-authentication with new key */
nvme_auth_reset(ctrl);
}
--
2.34.1
next prev parent reply other threads:[~2022-10-25 13:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-25 13:43 [PATCH 0/6] nvme: a few nvme-auth fixes found during code browsing Sagi Grimberg
2022-10-25 13:43 ` [PATCH 1/6] nvme-auth: rename __nvme_auth_[reset|free] to nvme_auth[reset|free]_dhchap Sagi Grimberg
2022-10-25 17:18 ` Hannes Reinecke
2022-10-25 17:34 ` Chaitanya Kulkarni
2022-10-25 13:43 ` [PATCH 2/6] nvme-auth: remove symbol export from nvme_auth_reset Sagi Grimberg
2022-10-25 17:18 ` Hannes Reinecke
2022-10-25 17:34 ` Chaitanya Kulkarni
2022-10-25 13:43 ` [PATCH 3/6] nvme-auth: don't re-authenticate if the controller is not LIVE Sagi Grimberg
2022-10-25 17:22 ` Hannes Reinecke
2022-10-25 20:22 ` Sagi Grimberg
2022-10-25 13:43 ` [PATCH 4/6] nvme-auth: remove redundant buffer deallocations Sagi Grimberg
2022-10-25 17:23 ` Hannes Reinecke
2022-10-25 17:36 ` Chaitanya Kulkarni
2022-10-25 13:43 ` [PATCH 5/6] nvme-auth: don't ignore key generation failures when initializing ctrl keys Sagi Grimberg
2022-10-25 17:24 ` Hannes Reinecke
2022-10-25 13:43 ` Sagi Grimberg [this message]
2022-10-25 17:25 ` [PATCH 6/6] nvme-auth: don't override ctrl keys before validation Hannes Reinecke
2022-10-25 15:32 ` [PATCH 0/6] nvme: a few nvme-auth fixes found during code browsing Christoph Hellwig
2022-10-25 15:46 ` Sagi Grimberg
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=20221025134330.1028352-7-sagi@grimberg.me \
--to=sagi@grimberg.me \
--cc=Chaitanya.Kulkarni@wdc.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).