diff options
author | Michael Büsch <m@bues.ch> | 2018-06-14 14:08:11 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-06-15 11:06:49 -0400 |
commit | 837bf7cc3b7504385ae0e829c72e470dfc27cf6c (patch) | |
tree | a81c740ca1b82b148c7ce6e29880d6c948eaa9f0 /drivers | |
parent | a81ae8095712d1513fe8d58527c92c439b43233e (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/hw_random/core.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 91bb98c42a1c..aaf9e5afaad4 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c | |||
@@ -516,11 +516,18 @@ EXPORT_SYMBOL_GPL(hwrng_register); | |||
516 | 516 | ||
517 | void hwrng_unregister(struct hwrng *rng) | 517 | void hwrng_unregister(struct hwrng *rng) |
518 | { | 518 | { |
519 | int err; | ||
520 | |||
519 | mutex_lock(&rng_mutex); | 521 | mutex_lock(&rng_mutex); |
520 | 522 | ||
521 | list_del(&rng->list); | 523 | list_del(&rng->list); |
522 | if (current_rng == rng) | 524 | if (current_rng == rng) { |
523 | enable_best_rng(); | 525 | err = enable_best_rng(); |
526 | if (err) { | ||
527 | drop_current_rng(); | ||
528 | cur_rng_set_by_user = 0; | ||
529 | } | ||
530 | } | ||
524 | 531 | ||
525 | if (list_empty(&rng_list)) { | 532 | if (list_empty(&rng_list)) { |
526 | mutex_unlock(&rng_mutex); | 533 | mutex_unlock(&rng_mutex); |