linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: rng - Fix a refcounting bug in crypto_rng_reset()
@ 2020-01-20 14:38 Dan Carpenter
  2020-01-20 15:56 ` Neil Horman
  2020-02-13  9:17 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-01-20 14:38 UTC (permalink / raw)
  To: Neil Horman, Corentin Labbe
  Cc: Herbert Xu, David S. Miller, linux-crypto, kernel-janitors

We need to decrement this refcounter on these error paths.

Fixes: f7d76e05d058 ("crypto: user - fix use_after_free of struct xxx_request")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 crypto/rng.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/crypto/rng.c b/crypto/rng.c
index 1e21231f71c9..1490d210f1a1 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -37,12 +37,16 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
 	crypto_stats_get(alg);
 	if (!seed && slen) {
 		buf = kmalloc(slen, GFP_KERNEL);
-		if (!buf)
+		if (!buf) {
+			crypto_alg_put(alg);
 			return -ENOMEM;
+		}
 
 		err = get_random_bytes_wait(buf, slen);
-		if (err)
+		if (err) {
+			crypto_alg_put(alg);
 			goto out;
+		}
 		seed = buf;
 	}
 
-- 
2.11.0


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

* Re: [PATCH] crypto: rng - Fix a refcounting bug in crypto_rng_reset()
  2020-01-20 14:38 [PATCH] crypto: rng - Fix a refcounting bug in crypto_rng_reset() Dan Carpenter
@ 2020-01-20 15:56 ` Neil Horman
  2020-02-13  9:17 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Neil Horman @ 2020-01-20 15:56 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Corentin Labbe, Herbert Xu, David S. Miller, linux-crypto,
	kernel-janitors

On Mon, Jan 20, 2020 at 05:38:04PM +0300, Dan Carpenter wrote:
> We need to decrement this refcounter on these error paths.
> 
> Fixes: f7d76e05d058 ("crypto: user - fix use_after_free of struct xxx_request")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  crypto/rng.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/crypto/rng.c b/crypto/rng.c
> index 1e21231f71c9..1490d210f1a1 100644
> --- a/crypto/rng.c
> +++ b/crypto/rng.c
> @@ -37,12 +37,16 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
>  	crypto_stats_get(alg);
>  	if (!seed && slen) {
>  		buf = kmalloc(slen, GFP_KERNEL);
> -		if (!buf)
> +		if (!buf) {
> +			crypto_alg_put(alg);
>  			return -ENOMEM;
> +		}
>  
>  		err = get_random_bytes_wait(buf, slen);
> -		if (err)
> +		if (err) {
> +			crypto_alg_put(alg);
>  			goto out;
> +		}
>  		seed = buf;
>  	}
>  
> -- 
> 2.11.0
> 
> 
LGTM
Acked-by: Neil Horman <nhorman@tuxdriver.com>

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

* Re: [PATCH] crypto: rng - Fix a refcounting bug in crypto_rng_reset()
  2020-01-20 14:38 [PATCH] crypto: rng - Fix a refcounting bug in crypto_rng_reset() Dan Carpenter
  2020-01-20 15:56 ` Neil Horman
@ 2020-02-13  9:17 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2020-02-13  9:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Neil Horman, Corentin Labbe, David S. Miller, linux-crypto,
	kernel-janitors

On Mon, Jan 20, 2020 at 05:38:04PM +0300, Dan Carpenter wrote:
> We need to decrement this refcounter on these error paths.
> 
> Fixes: f7d76e05d058 ("crypto: user - fix use_after_free of struct xxx_request")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  crypto/rng.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 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, other threads:[~2020-02-13  9:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 14:38 [PATCH] crypto: rng - Fix a refcounting bug in crypto_rng_reset() Dan Carpenter
2020-01-20 15:56 ` Neil Horman
2020-02-13  9:17 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).