Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] crypto: amlogic - fix two resources leak
@ 2019-11-08  9:45 Corentin Labbe
  2019-11-08 21:00 ` Kees Cook
  2019-11-15  6:07 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Corentin Labbe @ 2019-11-08  9:45 UTC (permalink / raw)
  To: davem, herbert, keescook+coverity-bot, narmstrong
  Cc: linux-crypto, linux-kernel, Corentin Labbe

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

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
Addresses-Coverity-ID: 1487401 ("Resource leaks")
Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
index e9283ffdbd23..58b717aab6e8 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
@@ -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;
 }
-- 
2.23.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: amlogic - fix two resources leak
  2019-11-08  9:45 [PATCH] crypto: amlogic - fix two resources leak Corentin Labbe
@ 2019-11-08 21:00 ` Kees Cook
  2019-11-15  6:07 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2019-11-08 21:00 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: davem, herbert, keescook+coverity-bot, narmstrong, linux-crypto,
	linux-kernel

On Fri, Nov 08, 2019 at 09:45:17AM +0000, Corentin Labbe wrote:
> This patch fixes two resources leak that occur on error path.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
> Addresses-Coverity-ID: 1487401 ("Resource leaks")
> Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>

Thanks!

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> index e9283ffdbd23..58b717aab6e8 100644
> --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> @@ -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;
>  }
> -- 
> 2.23.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: amlogic - fix two resources leak
  2019-11-08  9:45 [PATCH] crypto: amlogic - fix two resources leak Corentin Labbe
  2019-11-08 21:00 ` Kees Cook
@ 2019-11-15  6:07 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2019-11-15  6:07 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: davem, keescook+coverity-bot, narmstrong, linux-crypto, linux-kernel

On Fri, Nov 08, 2019 at 09:45:17AM +0000, Corentin Labbe wrote:
> This patch fixes two resources leak that occur on error path.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
> Addresses-Coverity-ID: 1487401 ("Resource leaks")
> Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
>  drivers/crypto/amlogic/amlogic-gxl-cipher.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08  9:45 [PATCH] crypto: amlogic - fix two resources leak Corentin Labbe
2019-11-08 21:00 ` Kees Cook
2019-11-15  6:07 ` Herbert Xu

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git