From: Harald Freudenberger <freude@linux.ibm.com>
To: "Michael Büsch" <m@bues.ch>, "Matt Mackall" <mpm@selenic.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>
Cc: Wirz <spam@lukas-wirz.de>,
linux-crypto@vger.kernel.org, b43-dev@lists.infradead.org,
linux-wireless <linux-wireless@vger.kernel.org>,
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>,
Harald Freudenberger <freude@linux.vnet.ibm.com>
Subject: Re: [PATCH] hw_random: Always drop the RNG in hwrng_unregister()
Date: Fri, 15 Jun 2018 10:08:12 +0200 [thread overview]
Message-ID: <8f1f5be1-979c-7601-1419-907b1980d974@linux.ibm.com> (raw)
In-Reply-To: <20180614200811.76401d95@wiggum>
On 14.06.2018 20:08, Michael Büsch wrote:
> 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
>
>
> 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
>
> ---
>
> See this discussion for a crash in b43's hwrng caused by this problem:
> https://www.spinics.net/lists/linux-wireless/msg173089.html
>
>
>
> 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);
>
> void hwrng_unregister(struct hwrng *rng)
> {
> + int err;
> +
> mutex_lock(&rng_mutex);
>
> list_del(&rng->list);
> - if (current_rng == rng)
> - enable_best_rng();
> + if (current_rng == rng) {
> + err = enable_best_rng();
> + if (err) {
> + drop_current_rng();
> + cur_rng_set_by_user = 0;
> + }
> + }
>
> if (list_empty(&rng_list)) {
> mutex_unlock(&rng_mutex);
>
>
>
Yes, if the hw_init() of the newly chosen rng fails, enable_best_rng() comes
back with an error and did not drop the current rng. The patch handles
this case. I did not test it, but the code looks fine.
reviewed-by Harald Freudenberger <freude@linux.ibm.com>
next prev parent reply other threads:[~2018-06-15 8:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-14 18:08 [PATCH] hw_random: Always drop the RNG in hwrng_unregister() Michael Büsch
2018-06-15 8:08 ` Harald Freudenberger [this message]
2018-06-15 15:15 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8f1f5be1-979c-7601-1419-907b1980d974@linux.ibm.com \
--to=freude@linux.ibm.com \
--cc=b43-dev@lists.infradead.org \
--cc=freude@linux.vnet.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=m@bues.ch \
--cc=mpm@selenic.com \
--cc=prasannatsmkumar@gmail.com \
--cc=spam@lukas-wirz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox