This is a note to let you know that I've just added the patch titled random: avoid arch_get_random_seed_long() when collecting IRQ randomness to the 4.14-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: random-avoid-arch_get_random_seed_long-when-collecting-irq-randomness.patch and it can be found in the queue-4.14 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Thu Jun 16 07:08:33 PM CEST 2022 From: Ard Biesheuvel <ardb@xxxxxxxxxx> Date: Thu, 5 Nov 2020 16:29:44 +0100 Subject: random: avoid arch_get_random_seed_long() when collecting IRQ randomness From: Ard Biesheuvel <ardb@xxxxxxxxxx> commit 390596c9959c2a4f5b456df339f0604df3d55fe0 upstream. When reseeding the CRNG periodically, arch_get_random_seed_long() is called to obtain entropy from an architecture specific source if one is implemented. In most cases, these are special instructions, but in some cases, such as on ARM, we may want to back this using firmware calls, which are considerably more expensive. Another call to arch_get_random_seed_long() exists in the CRNG driver, in add_interrupt_randomness(), which collects entropy by capturing inter-interrupt timing and relying on interrupt jitter to provide random bits. This is done by keeping a per-CPU state, and mixing in the IRQ number, the cycle counter and the return address every time an interrupt is taken, and mixing this per-CPU state into the entropy pool every 64 invocations, or at least once per second. The entropy that is gathered this way is credited as 1 bit of entropy. Every time this happens, arch_get_random_seed_long() is invoked, and the result is mixed in as well, and also credited with 1 bit of entropy. This means that arch_get_random_seed_long() is called at least once per second on every CPU, which seems excessive, and doesn't really scale, especially in a virtualization scenario where CPUs may be oversubscribed: in cases where arch_get_random_seed_long() is backed by an instruction that actually goes back to a shared hardware entropy source (such as RNDRRS on ARM), we will end up hitting it hundreds of times per second. So let's drop the call to arch_get_random_seed_long() from add_interrupt_randomness(), and instead, rely on crng_reseed() to call the arch hook to get random seed material from the platform. Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx> Reviewed-by: Andre Przywara <andre.przywara@xxxxxxx> Tested-by: Andre Przywara <andre.przywara@xxxxxxx> Reviewed-by: Eric Biggers <ebiggers@xxxxxxxxxx> Acked-by: Marc Zyngier <maz@xxxxxxxxxx> Reviewed-by: Jason A. Donenfeld <Jason@xxxxxxxxx> Link: https://lore.kernel.org/r/20201105152944.16953-1-ardb@xxxxxxxxxx Signed-off-by: Will Deacon <will@xxxxxxxxxx> Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/char/random.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1279,8 +1279,6 @@ void add_interrupt_randomness(int irq, i cycles_t cycles = random_get_entropy(); __u32 c_high, j_high; __u64 ip; - unsigned long seed; - int credit = 0; if (cycles == 0) cycles = get_reg(fast_pool, regs); @@ -1316,23 +1314,12 @@ void add_interrupt_randomness(int irq, i fast_pool->last = now; __mix_pool_bytes(r, &fast_pool->pool, sizeof(fast_pool->pool)); - - /* - * If we have architectural seed generator, produce a seed and - * add it to the pool. For the sake of paranoia don't let the - * architectural seed generator dominate the input from the - * interrupt noise. - */ - if (arch_get_random_seed_long(&seed)) { - __mix_pool_bytes(r, &seed, sizeof(seed)); - credit = 1; - } spin_unlock(&r->lock); fast_pool->count = 0; /* award one bit for the contents of the fast pool */ - credit_entropy_bits(r, credit + 1); + credit_entropy_bits(r, 1); } EXPORT_SYMBOL_GPL(add_interrupt_randomness); Patches currently in stable-queue which might be from ardb@xxxxxxxxxx are queue-4.14/random-initialize-chacha20-constants-with-correct-endianness.patch queue-4.14/lib-crypto-sha1-re-roll-loops-to-reduce-code-size.patch queue-4.14/powerpc-use-bool-in-archrandom.h.patch queue-4.14/crypto-blake2s-generic-c-library-implementation-and-selftest.patch queue-4.14/random-remove-dead-code-left-over-from-blocking-pool.patch queue-4.14/linux-random.h-mark-config_arch_random-functions-__must_check.patch queue-4.14/random-treat-bootloader-trust-toggle-the-same-way-as-cpu-trust-toggle.patch queue-4.14/lib-crypto-blake2s-move-hmac-construction-into-wireguard.patch queue-4.14/crypto-blake2s-include-linux-bug.h-instead-of-asm-bug.h.patch queue-4.14/linux-random.h-use-false-with-bool.patch queue-4.14/random-avoid-arch_get_random_seed_long-when-collecting-irq-randomness.patch queue-4.14/random-avoid-superfluous-call-to-rdrand-in-crng-extraction.patch queue-4.14/crypto-blake2s-adjust-include-guard-naming.patch