* [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash
@ 2024-07-06 6:46 Gaosheng Cui
2024-07-06 7:21 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gaosheng Cui @ 2024-07-06 6:46 UTC (permalink / raw)
To: hare, hch, sagi, kch, axboe, cuigaosheng1; +Cc: linux-nvme
If we fail to call nvme_auth_augmented_challenge, or fail to kmalloc
for shash, we should free the memory allocation for challenge, so add
err path out_free_challenge to fix the memory leak.
Fixes: 7a277c37d352 ("nvmet-auth: Diffie-Hellman key exchange support")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
drivers/nvme/target/auth.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
index 7d2633940f9b..8bc3f431c77f 100644
--- a/drivers/nvme/target/auth.c
+++ b/drivers/nvme/target/auth.c
@@ -314,7 +314,7 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
req->sq->dhchap_c1,
challenge, shash_len);
if (ret)
- goto out_free_response;
+ goto out_free_challenge;
}
pr_debug("ctrl %d qid %d host response seq %u transaction %d\n",
@@ -325,7 +325,7 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
GFP_KERNEL);
if (!shash) {
ret = -ENOMEM;
- goto out_free_response;
+ goto out_free_challenge;
}
shash->tfm = shash_tfm;
ret = crypto_shash_init(shash);
@@ -361,9 +361,10 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
goto out;
ret = crypto_shash_final(shash, response);
out:
+ kfree(shash);
+out_free_challenge:
if (challenge != req->sq->dhchap_c1)
kfree(challenge);
- kfree(shash);
out_free_response:
nvme_auth_free_key(transformed_key);
out_free_tfm:
@@ -427,14 +428,14 @@ int nvmet_auth_ctrl_hash(struct nvmet_req *req, u8 *response,
req->sq->dhchap_c2,
challenge, shash_len);
if (ret)
- goto out_free_response;
+ goto out_free_challenge;
}
shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(shash_tfm),
GFP_KERNEL);
if (!shash) {
ret = -ENOMEM;
- goto out_free_response;
+ goto out_free_challenge;
}
shash->tfm = shash_tfm;
@@ -471,9 +472,10 @@ int nvmet_auth_ctrl_hash(struct nvmet_req *req, u8 *response,
goto out;
ret = crypto_shash_final(shash, response);
out:
+ kfree(shash);
+out_free_challenge:
if (challenge != req->sq->dhchap_c2)
kfree(challenge);
- kfree(shash);
out_free_response:
nvme_auth_free_key(transformed_key);
out_free_tfm:
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash
2024-07-06 6:46 [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash Gaosheng Cui
@ 2024-07-06 7:21 ` Christoph Hellwig
2024-07-06 13:15 ` Hannes Reinecke
2024-07-08 17:49 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2024-07-06 7:21 UTC (permalink / raw)
To: Gaosheng Cui; +Cc: hare, hch, sagi, kch, axboe, linux-nvme
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash
2024-07-06 6:46 [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash Gaosheng Cui
2024-07-06 7:21 ` Christoph Hellwig
@ 2024-07-06 13:15 ` Hannes Reinecke
2024-07-08 17:49 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2024-07-06 13:15 UTC (permalink / raw)
To: Gaosheng Cui, hch, sagi, kch, axboe; +Cc: linux-nvme
On 7/6/24 08:46, Gaosheng Cui wrote:
> If we fail to call nvme_auth_augmented_challenge, or fail to kmalloc
> for shash, we should free the memory allocation for challenge, so add
> err path out_free_challenge to fix the memory leak.
>
> Fixes: 7a277c37d352 ("nvmet-auth: Diffie-Hellman key exchange support")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
> drivers/nvme/target/auth.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash
2024-07-06 6:46 [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash Gaosheng Cui
2024-07-06 7:21 ` Christoph Hellwig
2024-07-06 13:15 ` Hannes Reinecke
@ 2024-07-08 17:49 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2024-07-08 17:49 UTC (permalink / raw)
To: Gaosheng Cui; +Cc: hare, hch, sagi, kch, axboe, linux-nvme
On Sat, Jul 06, 2024 at 02:46:25PM +0800, Gaosheng Cui wrote:
> If we fail to call nvme_auth_augmented_challenge, or fail to kmalloc
> for shash, we should free the memory allocation for challenge, so add
> err path out_free_challenge to fix the memory leak.
Thanks, applied to nvme-6.11 with a slightly condenced patch subject.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-08 17:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-06 6:46 [PATCH -next] nvmet-auth: Fix the error handling path in nvmet_auth_host_hash and nvmet_auth_ctrl_hash Gaosheng Cui
2024-07-06 7:21 ` Christoph Hellwig
2024-07-06 13:15 ` Hannes Reinecke
2024-07-08 17:49 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox