Skip to content

Commit

Permalink
crypto: rng - Fix a refcounting bug in crypto_rng_reset()
Browse files Browse the repository at this point in the history
We need to decrement this refcounter on these error paths.

Fixes: f7d76e0 ("crypto: user - fix use_after_free of struct xxx_request")
Cc: <stable@vger.kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Dan Carpenter authored and Herbert Xu committed Feb 13, 2020
1 parent 00e62e8 commit eed74b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crypto/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit eed74b3

Please sign in to comment.