Skip to content

random: fix crash on multiple early calls to add_bootloader_randomness() - #4829

Merged
pelwell merged 1 commit into
raspberrypi:rpi-5.10.yfrom
pelwell:is4828
Jan 22, 2022
Merged

pelwell merged 1 commit into
raspberrypi:rpi-5.10.yfrom
pelwell:is4828

Conversation

@pelwell

@pelwell pelwell commented Jan 14, 2022

Copy link
Copy Markdown
Contributor

This is a possible fix for #4828. Hat tip to @P33M for finding the upstream patch.

commit f7e67b8 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: 18b915a ("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

commit f7e67b8 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: 18b915a ("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>
@colemickens

Copy link
Copy Markdown

Again confirming that this patch does resolve #4828.

@pelwell
pelwell merged commit ec5ae69 into raspberrypi:rpi-5.10.y Jan 22, 2022
@pelwell
pelwell deleted the is4828 branch January 22, 2022 06:51
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jan 27, 2022
See: raspberrypi/linux#4845

kernel: drm/vc4_hdmi: Add Broadcast RGB property to allow override of RGB range
See: raspberrypi/linux#4850

kernel: Update rpi-display overlay
See: raspberrypi/linux#4841

kernel: ARM: dts: BCM2711 AON_INTR2 generates IRQ edges
See: raspberrypi/linux#4838

kernel: drivers: bcm2835_unicam: Disable trigger mode operation
See: raspberrypi/linux#4834

kernel: random: fix crash on multiple early calls to add_bootloader_randomness
See: raspberrypi/linux#4829
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Jan 27, 2022
See: raspberrypi/linux#4845

kernel: drm/vc4_hdmi: Add Broadcast RGB property to allow override of RGB range
See: raspberrypi/linux#4850

kernel: Update rpi-display overlay
See: raspberrypi/linux#4841

kernel: ARM: dts: BCM2711 AON_INTR2 generates IRQ edges
See: raspberrypi/linux#4838

kernel: drivers: bcm2835_unicam: Disable trigger mode operation
See: raspberrypi/linux#4834

kernel: random: fix crash on multiple early calls to add_bootloader_randomness
See: raspberrypi/linux#4829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants