stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux@dominikbrodowski.net, iivanov@suse.de, stable@vger.kernel.org
Subject: Re: [PATCH stable 5.4.y] random: fix crash on multiple early calls to add_bootloader_randomness()
Date: Thu, 13 Jan 2022 19:53:06 +0100	[thread overview]
Message-ID: <YeB1EssPxuFBw7n7@kroah.com> (raw)
In-Reply-To: <20220113181329.69371-1-Jason@zx2c4.com>

On Thu, Jan 13, 2022 at 07:13:29PM +0100, Jason A. Donenfeld wrote:
> From: Dominik Brodowski <linux@dominikbrodowski.net>
> 
> commit f7e67b8e803185d0aabe7f29d25a35c8be724a78 upstream.
> 
> Currently, if CONFIG_RANDOM_TRUST_BOOTLOADER is enabled, multiple calls
> to add_bootloader_randomness() are broken and can cause a NULL pointer
> dereference, as noted by Ivan T. Ivanov. This is not only a hypothetical
> problem, as qemu on arm64 may provide bootloader entropy via EFI and via
> devicetree.
> 
> On the first call to add_hwgenerator_randomness(), crng_fast_load() is
> executed, and if the seed is long enough, crng_init will be set to 1.
> On subsequent calls to add_bootloader_randomness() and then to
> add_hwgenerator_randomness(), crng_fast_load() will be skipped. Instead,
> wait_event_interruptible() and then credit_entropy_bits() will be called.
> If the entropy count for that second seed is large enough, that proceeds
> to crng_reseed().
> 
> However, both wait_event_interruptible() and crng_reseed() depends
> (at least in numa_crng_init()) on workqueues. Therefore, test whether
> system_wq is already initialized, which is a sufficient indicator that
> workqueue_init_early() has progressed far enough.
> 
> If we wind up hitting the !system_wq case, we later want to do what
> would have been done there when wqs are up, so set a flag, and do that
> work later from the rand_initialize() call.
> 
> Reported-by: Ivan T. Ivanov <iivanov@suse.de>
> Fixes: 18b915ac6b0a ("efi/random: Treat EFI_RNG_PROTOCOL output as bootloader randomness")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
> [Jason: added crng_need_done state and related logic.]
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>  drivers/char/random.c | 59 ++++++++++++++++++++++++++++---------------
>  1 file changed, 38 insertions(+), 21 deletions(-)

Now queued up, thanks!

greg k-h

      reply	other threads:[~2022-01-13 18:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 18:02 FAILED: patch "[PATCH] random: fix crash on multiple early calls to" failed to apply to 5.4-stable tree gregkh
2022-01-13 18:13 ` [PATCH stable 5.4.y] random: fix crash on multiple early calls to add_bootloader_randomness() Jason A. Donenfeld
2022-01-13 18:53   ` Greg KH [this message]

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=YeB1EssPxuFBw7n7@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=Jason@zx2c4.com \
    --cc=iivanov@suse.de \
    --cc=linux@dominikbrodowski.net \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).