Skip to content

Commit 015cc7a

Browse files
ebiggersgregkh
authored andcommitted
crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS
commit 30d0f6a upstream. crypto_stats_get() is a no-op when the kernel is compiled without CONFIG_CRYPTO_STATS, so pairing it with crypto_alg_put() unconditionally (as crypto_rng_reset() does) is wrong. Fix this by moving the call to crypto_stats_get() to just before the actual algorithm operation which might need it. This makes it always paired with crypto_stats_rng_seed(). Fixes: eed74b3 ("crypto: rng - Fix a refcounting bug in crypto_rng_reset()") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0ba942c commit 015cc7a

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎crypto/rng.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,18 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
3434
u8 *buf = NULL;
3535
int err;
3636

37-
crypto_stats_get(alg);
3837
if (!seed && slen) {
3938
buf = kmalloc(slen, GFP_KERNEL);
40-
if (!buf) {
41-
crypto_alg_put(alg);
39+
if (!buf)
4240
return -ENOMEM;
43-
}
4441

4542
err = get_random_bytes_wait(buf, slen);
46-
if (err) {
47-
crypto_alg_put(alg);
43+
if (err)
4844
goto out;
49-
}
5045
seed = buf;
5146
}
5247

48+
crypto_stats_get(alg);
5349
err = crypto_rng_alg(tfm)->seed(tfm, seed, slen);
5450
crypto_stats_rng_seed(alg, err);
5551
out:

0 commit comments

Comments
 (0)