Skip to contentSkip to conversation

crypto: sun8i-ss: Fix memory leak of pad

PATCH In review Colin King 3 participants 3 messages Apr 1, 2021 – Apr 9, 2021

Subsystems (4)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 crypto: sun8i-ss: Fix memory leak of pad

From: Colin Ian King <[email protected]>

It appears there are several failure return paths that don't seem to be free'ing pad. Fix these.

Addresses-Coverity: ("Resource leak")

Fixes d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")
---
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +4 -3
index 7d1fc9aba665..3c073eb3db03 100644
@@ -348,8 +348,10 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
 	bf = (__le32 *)pad;
 
 	result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
-	if (!result)
+	if (!result) {
+		kfree(pad);
 		return -ENOMEM;
+	}
 
 	for (i = 0; i < MAX_SG; i++) {
 		rctx->t_dst[i].addr = 0;
@@ -436,10 +438,9 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
 		     DMA_TO_DEVICE);
 	dma_unmap_single(ss->dev, addr_res, digestsize, DMA_FROM_DEVICE);
 
-	kfree(pad);
-
 	memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
 theend:
+	kfree(pad);
 	kfree(result);
 	crypto_finalize_hash_request(engine, breq, err);
 	return 0;
Signature · 7 lines
2.30.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

It appears there are several failure return paths that don't seem to be free'ing pad. Fix these.

Addresses-Coverity: ("Resource leak")

Fixes d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")

---

Hello

Tested-on: sun8i-a83t-bananapi-m3

Thanks

maintainer
#2 lore raw
In reply to Colin King
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

It appears there are several failure return paths that don't seem to be free'ing pad. Fix these.

Addresses-Coverity: ("Resource leak")

Fixes d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")
---
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt