From: Ma Ke <make24@iscas.ac.cn>
To: herbert@gondor.apana.org.au, davem@davemloft.net,
j-keerthy@ti.com, t-kristo@ti.com, akpm@linux-foundation.org
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Ma Ke <make24@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH RESEND] crypto: sa2ul - fix memory leak in sa_cra_init_aead()
Date: Mon, 19 Aug 2024 16:48:43 +0800 [thread overview]
Message-ID: <20240819084843.1012289-1-make24@iscas.ac.cn> (raw)
Currently the resource allocated by crypto_alloc_shash() is not freed in
case crypto_alloc_aead() fails, resulting in memory leak.
Add crypto_free_shash() to fix it.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: d2c8ac187fc9 ("crypto: sa2ul - Add AEAD algorithm support")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/crypto/sa2ul.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 461eca40e878..b5af621f7f17 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -1740,7 +1740,8 @@ static int sa_cra_init_aead(struct crypto_aead *tfm, const char *hash,
ctx->shash = crypto_alloc_shash(hash, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(ctx->shash)) {
dev_err(sa_k3_dev, "base driver %s couldn't be loaded\n", hash);
- return PTR_ERR(ctx->shash);
+ ret = PTR_ERR(ctx->shash);
+ goto err_free_shash;
}
ctx->fallback.aead = crypto_alloc_aead(fallback, 0,
@@ -1749,7 +1750,8 @@ static int sa_cra_init_aead(struct crypto_aead *tfm, const char *hash,
if (IS_ERR(ctx->fallback.aead)) {
dev_err(sa_k3_dev, "fallback driver %s couldn't be loaded\n",
fallback);
- return PTR_ERR(ctx->fallback.aead);
+ ret = PTR_ERR(ctx->fallback.aead);
+ goto err_free_shash;
}
crypto_aead_set_reqsize(tfm, sizeof(struct aead_request) +
@@ -1757,19 +1759,23 @@ static int sa_cra_init_aead(struct crypto_aead *tfm, const char *hash,
ret = sa_init_ctx_info(&ctx->enc, data);
if (ret)
- return ret;
+ goto err_free_shash;
ret = sa_init_ctx_info(&ctx->dec, data);
- if (ret) {
- sa_free_ctx_info(&ctx->enc, data);
- return ret;
- }
+ if (ret)
+ goto err_free_ctx_info;
dev_dbg(sa_k3_dev, "%s(0x%p) sc-ids(0x%x(0x%pad), 0x%x(0x%pad))\n",
__func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys,
ctx->dec.sc_id, &ctx->dec.sc_phys);
return ret;
+
+err_free_ctx_info:
+ sa_free_ctx_info(&ctx->enc, data);
+err_free_shash:
+ crypto_free_shash(ctx->shash);
+ return ret;
}
static int sa_cra_init_aead_sha1(struct crypto_aead *tfm)
--
2.25.1
next reply other threads:[~2024-08-19 8:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-19 8:48 Ma Ke [this message]
2024-08-30 9:53 ` Herbert Xu
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=20240819084843.1012289-1-make24@iscas.ac.cn \
--to=make24@iscas.ac.cn \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=j-keerthy@ti.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=t-kristo@ti.com \
/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
all inboxes | Powered by JetHome®