crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS
authorEric Biggers <ebiggers@google.com>
Mon, 22 Mar 2021 05:07:48 +0000 (22:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 May 2021 12:47:35 +0000 (14:47 +0200)
commit015cc7ad58d08131f46a786ecb0e84cc29ec0c4c
tree2c884333fa80f8f498dc4c00f1c8c3fdfac7eddd
parent0ba942cbf52b7df88e6a2607a457a0040fa90b07
crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS

commit 30d0f6a956fc74bb2e948398daf3278c6b08c7e9 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: eed74b3eba9e ("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>
crypto/rng.c