OSDN Git Service

hwrng: core - Always drop the RNG in hwrng_unregister()
authorMichael Büsch <m@bues.ch>
Thu, 14 Jun 2018 18:08:11 +0000 (20:08 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 15 Jun 2018 15:06:49 +0000 (23:06 +0800)
commit837bf7cc3b7504385ae0e829c72e470dfc27cf6c
treea81c740ca1b82b148c7ce6e29880d6c948eaa9f0
parenta81ae8095712d1513fe8d58527c92c439b43233e
hwrng: core - Always drop the RNG in hwrng_unregister()

enable_best_rng() is used in hwrng_unregister() to switch away from the
currently active RNG, if that is the one currently being removed.
However enable_best_rng() might fail, if the next RNG's init routine
fails. In that case enable_best_rng() will return an error code and
the currently active RNG will remain active.
After unregistering this might lead to crashes due to use-after-free.

Fix this by dropping the currently active RNG, if enable_best_rng()
failed. This will result in no RNG to be active, if the next-best
one failed to initialize.

This problem was introduced by 142a27f0a731ddcf467546960a5585970ca98e21

Fixes: 142a27f0a731 ("hwrng: core - Reset user selected rng by...")
Reported-by: Wirz <spam@lukas-wirz.de>
Tested-by: Wirz <spam@lukas-wirz.de>
Signed-off-by: Michael Büsch <m@bues.ch>
Cc: stable@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/core.c