From: Wentao Liang <vulab@iscas.ac.cn>
To: atenart@kernel.org, herbert@gondor.apana.org.au
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] crypto: safexcel - Unwind SHA3 initialization if HMAC setup fails
Date: Tue, 3 Nov 2026 06:40:30 +0000 [thread overview]
Message-ID: <20261103064030.1034291-1-vulab@iscas.ac.cn> (raw)
safexcel_hmac_sha3_cra_init() first initializes the SHA3 context, which
allocates an ahash fallback. If allocating the shash transform or its
descriptor fails afterwards, that fallback is not released. The crypto
core does not invoke cra_exit after cra_init returns an error.
Call safexcel_sha3_cra_exit() on these failure paths to release the
resources acquired by safexcel_sha3_cra_init().
Fixes: 6c1c09b3dd0c ("crypto: inside-secure - Add HMAC-SHA3 family of authentication algorithms")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/crypto/inside-secure/safexcel_hash.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c
index 8f107da66685..308a1992a738 100644
--- a/drivers/crypto/inside-secure/safexcel_hash.c
+++ b/drivers/crypto/inside-secure/safexcel_hash.c
@@ -2649,17 +2649,24 @@ static int safexcel_hmac_sha3_cra_init(struct crypto_tfm *tfm, const char *alg)
/* Allocate precalc basic digest implementation */
ctx->shpre = crypto_alloc_shash(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
- if (IS_ERR(ctx->shpre))
- return PTR_ERR(ctx->shpre);
+ if (IS_ERR(ctx->shpre)) {
+ ret = PTR_ERR(ctx->shpre);
+ goto err_sha3;
+ }
ctx->shdesc = kmalloc(sizeof(*ctx->shdesc) +
crypto_shash_descsize(ctx->shpre), GFP_KERNEL);
if (!ctx->shdesc) {
crypto_free_shash(ctx->shpre);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_sha3;
}
ctx->shdesc->tfm = ctx->shpre;
return 0;
+
+err_sha3:
+ safexcel_sha3_cra_exit(tfm);
+ return ret;
}
static void safexcel_hmac_sha3_cra_exit(struct crypto_tfm *tfm)
--
2.34.1
next reply other threads:[~2026-11-03 6:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 6:40 Wentao Liang [this message]
2026-11-03 7:10 ` Krzysztof Kozlowski
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=20261103064030.1034291-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=atenart@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.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
all inboxes | Powered by JetHome®