Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0768ae32 authored by Eric Biggers's avatar Eric Biggers
Browse files

ANDROID: allow add_hwgenerator_randomness() from non-kthread



A recent LTS change causes add_hwgenerator_randomness() to crash when
called from a non-kthread task.  This shouldn't be a problem, since this
function should only be called by the HWRNG framework.  However, on this
branch it is part of the KMI since a vendor module is using it
inappropriately by calling it during early init.  (Note that
add_bootloader_randomness() would be a better fit for the use case.)

To prevent a crash in this case, restore support for
add_hwgenerator_randomness() being called from a non-kthread task.

This change isn't currently needed in 5.4 or newer kernels, as
add_hwgenerator_randomness() isn't part of the KMI there.

Bug: 238701371
Fixes: 8bc7018f ("random: do not use batches when !crng_ready()")
Change-Id: I0b86743deb30f54b8f838a36eea740b370a30a8b
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
parent 79651a7a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -873,7 +873,8 @@ void add_hwgenerator_randomness(const char *buf, size_t len, size_t entropy)
	 * Throttle writing to once every CRNG_RESEED_INTERVAL, unless
	 * we're not yet initialized.
	 */
	if (!kthread_should_stop() && crng_ready())
	if ((current->flags & PF_KTHREAD) &&
	    !kthread_should_stop() && crng_ready())
		schedule_timeout_interruptible(CRNG_RESEED_INTERVAL);
}
EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);