linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] nvme: fix dhchap secret memleaks in auth code
@ 2023-05-22 21:53 Chris Leech
  2023-05-23  0:16 ` Chaitanya Kulkarni
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Leech @ 2023-05-22 21:53 UTC (permalink / raw)
  To: linux-nvme; +Cc: Hannes Reinecke

Re-authentication through the sysfs interface without changing the PSK
will result in a memory leak. This was tested with blktests nvme/045.

Fixes: f50fff73d620 ("nvme: implement In-Band authentication")
Signed-off-by: Chris Leech <cleech@redhat.com>
---
 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 1f0cbb77b249..9aff76ced4f8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3828,8 +3828,10 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
 		int ret;
 
 		ret = nvme_auth_generate_key(dhchap_secret, &key);
-		if (ret)
+		if (ret) {
+			kfree(dhchap_secret);
 			return ret;
+		}
 		kfree(opts->dhchap_secret);
 		opts->dhchap_secret = dhchap_secret;
 		host_key = ctrl->host_key;
@@ -3837,6 +3839,8 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
 		ctrl->host_key = key;
 		mutex_unlock(&ctrl->dhchap_auth_mutex);
 		nvme_auth_free_key(host_key);
+	} else {
+		kfree(dhchap_secret);
 	}
 	/* Start re-authentication */
 	dev_info(ctrl->device, "re-authenticating controller\n");
@@ -3882,8 +3886,10 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
 		int ret;
 
 		ret = nvme_auth_generate_key(dhchap_secret, &key);
-		if (ret)
+		if (ret) {
+			kfree(dhchap_secret);
 			return ret;
+		}
 		kfree(opts->dhchap_ctrl_secret);
 		opts->dhchap_ctrl_secret = dhchap_secret;
 		ctrl_key = ctrl->ctrl_key;
@@ -3891,6 +3897,8 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
 		ctrl->ctrl_key = key;
 		mutex_unlock(&ctrl->dhchap_auth_mutex);
 		nvme_auth_free_key(ctrl_key);
+	} else {
+		kfree(dhchap_secret);
 	}
 	/* Start re-authentication */
 	dev_info(ctrl->device, "re-authenticating controller\n");
-- 
2.40.1



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

* Re: [PATCH 1/1] nvme: fix dhchap secret memleaks in auth code
  2023-05-22 21:53 [PATCH 1/1] nvme: fix dhchap secret memleaks in auth code Chris Leech
@ 2023-05-23  0:16 ` Chaitanya Kulkarni
  2023-05-23  1:21   ` Chris Leech
  0 siblings, 1 reply; 3+ messages in thread
From: Chaitanya Kulkarni @ 2023-05-23  0:16 UTC (permalink / raw)
  To: Chris Leech; +Cc: Hannes Reinecke, linux-nvme

On 5/22/23 14:53, Chris Leech wrote:
> Re-authentication through the sysfs interface without changing the PSK
> will result in a memory leak. This was tested with blktests nvme/045.
>
> Fixes: f50fff73d620 ("nvme: implement In-Band authentication")
> Signed-off-by: Chris Leech <cleech@redhat.com>
> ---
>

I think it is already fixed in nvme-6.5, if not please let me know ..

-ck



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

* Re: [PATCH 1/1] nvme: fix dhchap secret memleaks in auth code
  2023-05-23  0:16 ` Chaitanya Kulkarni
@ 2023-05-23  1:21   ` Chris Leech
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Leech @ 2023-05-23  1:21 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: Hannes Reinecke, linux-nvme

On Mon, May 22, 2023 at 5:16 PM Chaitanya Kulkarni
<chaitanyak@nvidia.com> wrote:
> On 5/22/23 14:53, Chris Leech wrote:
> > Re-authentication through the sysfs interface without changing the PSK
> > will result in a memory leak. This was tested with blktests nvme/045.
>
> I think it is already fixed in nvme-6.5, if not please let me know ..

You're right, sorry about that.  Looks good in nvme-6.5

- Chris



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

end of thread, other threads:[~2023-05-23  1:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-22 21:53 [PATCH 1/1] nvme: fix dhchap secret memleaks in auth code Chris Leech
2023-05-23  0:16 ` Chaitanya Kulkarni
2023-05-23  1:21   ` Chris Leech

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