Skip to contentSkip to conversation

crypto: amlogic - fix two resources leak

PATCH In review Corentin Labbe 3 participants 3 messages Nov 8, 2019 – Nov 15, 2019

Subsystems (2)
lore
Share & tools
lore

Corentin Labbe

author maintainer
#0 lore raw

PATCH 1/1 crypto: amlogic - fix two resources leak

This patch fixes two resources leak that occur on error path.

Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
Addresses-Coverity-ID: 1487401 ("Resource leaks")

Fixes 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/crypto/amlogic/amlogic-gxl-cipher.c +6 -4
index e9283ffdbd23..58b717aab6e8 100644
@@ -131,7 +131,8 @@ static int meson_cipher(struct skcipher_request *areq)
 	if (areq->iv && ivsize > 0) {
 		if (ivsize > areq->cryptlen) {
 			dev_err(mc->dev, "invalid ivsize=%d vs len=%d\n", ivsize, areq->cryptlen);
-			return -EINVAL;
+			err = -EINVAL;
+			goto theend;
 		}
 		memcpy(bkeyiv + 32, areq->iv, ivsize);
 		keyivlen = 48;
@@ -151,9 +152,10 @@ static int meson_cipher(struct skcipher_request *areq)
 
 	phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen,
 				  DMA_TO_DEVICE);
-	if (dma_mapping_error(mc->dev, phykeyiv)) {
+	err = dma_mapping_error(mc->dev, phykeyiv);
+	if (err) {
 		dev_err(mc->dev, "Cannot DMA MAP KEY IV\n");
-		return -EFAULT;
+		goto theend;
 	}
 
 	tloffset = 0;
@@ -245,7 +247,6 @@ static int meson_cipher(struct skcipher_request *areq)
 	if (areq->iv && ivsize > 0) {
 		if (rctx->op_dir == MESON_DECRYPT) {
 			memcpy(areq->iv, backup_iv, ivsize);
-			kzfree(backup_iv);
 		} else {
 			scatterwalk_map_and_copy(areq->iv, areq->dst,
 						 areq->cryptlen - ivsize,
@@ -254,6 +255,7 @@ static int meson_cipher(struct skcipher_request *areq)
 	}
 theend:
 	kzfree(bkeyiv);
+	kzfree(backup_iv);
 
 	return err;
 }
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Corentin Labbe

This patch fixes two resources leak that occur on error path.

Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
Addresses-Coverity-ID: 1487401 ("Resource leaks")

Fixes 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")

Thanks!

-Kees

Quoted 50 lines
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/crypto/amlogic/amlogic-gxl-cipher.c +6 -4
index e9283ffdbd23..58b717aab6e8 100644
@@ -131,7 +131,8 @@ static int meson_cipher(struct skcipher_request *areq)
 	if (areq->iv && ivsize > 0) {
 		if (ivsize > areq->cryptlen) {
 			dev_err(mc->dev, "invalid ivsize=%d vs len=%d\n", ivsize, areq->cryptlen);
-			return -EINVAL;
+			err = -EINVAL;
+			goto theend;
 		}
 		memcpy(bkeyiv + 32, areq->iv, ivsize);
 		keyivlen = 48;
@@ -151,9 +152,10 @@ static int meson_cipher(struct skcipher_request *areq)
 
 	phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen,
 				  DMA_TO_DEVICE);
-	if (dma_mapping_error(mc->dev, phykeyiv)) {
+	err = dma_mapping_error(mc->dev, phykeyiv);
+	if (err) {
 		dev_err(mc->dev, "Cannot DMA MAP KEY IV\n");
-		return -EFAULT;
+		goto theend;
 	}
 
 	tloffset = 0;
@@ -245,7 +247,6 @@ static int meson_cipher(struct skcipher_request *areq)
 	if (areq->iv && ivsize > 0) {
 		if (rctx->op_dir == MESON_DECRYPT) {
 			memcpy(areq->iv, backup_iv, ivsize);
-			kzfree(backup_iv);
 		} else {
 			scatterwalk_map_and_copy(areq->iv, areq->dst,
 						 areq->cryptlen - ivsize,
@@ -254,6 +255,7 @@ static int meson_cipher(struct skcipher_request *areq)
 	}
 theend:
 	kzfree(bkeyiv);
+	kzfree(backup_iv);
 
 	return err;
 }
Signature · 1 line
2.23.0
Signature · 1 line
Kees Cook
maintainer
#2 lore raw
In reply to Corentin Labbe
Quoted 10 lines · Corentin Labbe

This patch fixes two resources leak that occur on error path.

Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
Addresses-Coverity-ID: 1487401 ("Resource leaks")

Fixes 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 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