Skip to contentSkip to conversation

crypto: safexcel - Unwind SHA3 initialization if HMAC setup fails

PATCH In review Wentao Liang 2 participants 2 messages Nov 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: safexcel - Unwind SHA3 initialization if HMAC setup fails

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")
Assisted-by DeepSeek-V4.1-Flash and OpenAI Codex
---
 drivers/crypto/inside-secure/safexcel_hash.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/crypto/inside-secure/safexcel_hash.c +10 -3
index 8f107da66685..308a1992a738 100644
@@ -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)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Wentao Liang

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")
Assisted-by DeepSeek-V4.1-Flash and OpenAI Codex

Not even bothering to run checkpatch.

Quoted 1 line

Another fake identity of "vulab" doing exactly the same as other cases, repeating same mistake of running unsupervised crappy bot even though was asked multiple times to fix that.

Best regards,
Krzysztof