Skip to content

Commit 89f58f9

Browse files
gscuikeithbusch
authored andcommitted
nvmet-auth: fix nvmet_auth hash error handling
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: 7a277c3 ("nvmet-auth: Diffie-Hellman key exchange support") Signed-off-by: Gaosheng Cui <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 18f03a0 commit 89f58f9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/nvme/target/auth.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
314314
req->sq->dhchap_c1,
315315
challenge, shash_len);
316316
if (ret)
317-
goto out_free_response;
317+
goto out_free_challenge;
318318
}
319319

320320
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,
325325
GFP_KERNEL);
326326
if (!shash) {
327327
ret = -ENOMEM;
328-
goto out_free_response;
328+
goto out_free_challenge;
329329
}
330330
shash->tfm = shash_tfm;
331331
ret = crypto_shash_init(shash);
@@ -361,9 +361,10 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
361361
goto out;
362362
ret = crypto_shash_final(shash, response);
363363
out:
364+
kfree(shash);
365+
out_free_challenge:
364366
if (challenge != req->sq->dhchap_c1)
365367
kfree(challenge);
366-
kfree(shash);
367368
out_free_response:
368369
nvme_auth_free_key(transformed_key);
369370
out_free_tfm:
@@ -427,14 +428,14 @@ int nvmet_auth_ctrl_hash(struct nvmet_req *req, u8 *response,
427428
req->sq->dhchap_c2,
428429
challenge, shash_len);
429430
if (ret)
430-
goto out_free_response;
431+
goto out_free_challenge;
431432
}
432433

433434
shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(shash_tfm),
434435
GFP_KERNEL);
435436
if (!shash) {
436437
ret = -ENOMEM;
437-
goto out_free_response;
438+
goto out_free_challenge;
438439
}
439440
shash->tfm = shash_tfm;
440441

@@ -471,9 +472,10 @@ int nvmet_auth_ctrl_hash(struct nvmet_req *req, u8 *response,
471472
goto out;
472473
ret = crypto_shash_final(shash, response);
473474
out:
475+
kfree(shash);
476+
out_free_challenge:
474477
if (challenge != req->sq->dhchap_c2)
475478
kfree(challenge);
476-
kfree(shash);
477479
out_free_response:
478480
nvme_auth_free_key(transformed_key);
479481
out_free_tfm:

0 commit comments

Comments
 (0)