crypto: rng - Fix a refcounting bug in crypto_rng_reset()
diff mbox series

Message ID 20200120143804.pbmnrh72v2gogx43@kili.mountain
State Accepted
Delegated to: Herbert Xu
Headers show
Series
  • crypto: rng - Fix a refcounting bug in crypto_rng_reset()
Related show

Commit Message

Dan Carpenter Jan. 20, 2020, 2:38 p.m. UTC
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(-)

Comments

Neil Horman Jan. 20, 2020, 3:56 p.m. UTC | #1
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>
Herbert Xu Feb. 13, 2020, 9:17 a.m. UTC | #2
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.

Patch
diff mbox series

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;
 	}