From: Greg Kroah-Hartman Date: Mon, 13 Jun 2022 09:01:30 +0000 (+0200) Subject: 5.15-stable patches X-Git-Tag: v4.9.318~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49f5aeb7d274d2839628a824575e37000e297705;p=thirdparty%2Fkernel%2Fstable-queue.git 5.15-stable patches added patches: random-account-for-arch-randomness-in-bits.patch random-avoid-checking-crng_ready-twice-in-random_init.patch random-mark-bootloader-randomness-code-as-__init.patch --- diff --git a/queue-5.15/random-account-for-arch-randomness-in-bits.patch b/queue-5.15/random-account-for-arch-randomness-in-bits.patch new file mode 100644 index 00000000000..6b7b69e4755 --- /dev/null +++ b/queue-5.15/random-account-for-arch-randomness-in-bits.patch @@ -0,0 +1,59 @@ +From foo@baz Mon Jun 13 11:00:57 AM CEST 2022 +From: "Jason A. Donenfeld" +Date: Mon, 13 Jun 2022 10:07:49 +0200 +Subject: random: account for arch randomness in bits +To: stable@vger.kernel.org, gregkh@linuxfoundation.org +Message-ID: <20220613080749.153222-4-Jason@zx2c4.com> + +From: "Jason A. Donenfeld" + +commit 77fc95f8c0dc9e1f8e620ec14d2fb65028fb7adc upstream. + +Rather than accounting in bytes and multiplying (shifting), we can just +account in bits and avoid the shift. The main motivation for this is +there are other patches in flux that expand this code a bit, and +avoiding the duplication of "* 8" everywhere makes things a bit clearer. + +Cc: stable@vger.kernel.org +Fixes: 12e45a2a6308 ("random: credit architectural init the exact amount") +Signed-off-by: Jason A. Donenfeld +Signed-off-by: Greg Kroah-Hartman +--- + drivers/char/random.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +--- a/drivers/char/random.c ++++ b/drivers/char/random.c +@@ -813,7 +813,7 @@ early_param("random.trust_bootloader", p + int __init random_init(const char *command_line) + { + ktime_t now = ktime_get_real(); +- unsigned int i, arch_bytes; ++ unsigned int i, arch_bits; + unsigned long entropy; + + #if defined(LATENT_ENTROPY_PLUGIN) +@@ -821,12 +821,12 @@ int __init random_init(const char *comma + _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); + #endif + +- for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE; ++ for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8; + i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) { + if (!arch_get_random_seed_long_early(&entropy) && + !arch_get_random_long_early(&entropy)) { + entropy = random_get_entropy(); +- arch_bytes -= sizeof(entropy); ++ arch_bits -= sizeof(entropy) * 8; + } + _mix_pool_bytes(&entropy, sizeof(entropy)); + } +@@ -838,7 +838,7 @@ int __init random_init(const char *comma + if (crng_ready()) + crng_reseed(); + else if (trust_cpu) +- _credit_init_bits(arch_bytes * 8); ++ _credit_init_bits(arch_bits); + + return 0; + } diff --git a/queue-5.15/random-avoid-checking-crng_ready-twice-in-random_init.patch b/queue-5.15/random-avoid-checking-crng_ready-twice-in-random_init.patch new file mode 100644 index 00000000000..00e706bd931 --- /dev/null +++ b/queue-5.15/random-avoid-checking-crng_ready-twice-in-random_init.patch @@ -0,0 +1,49 @@ +From foo@baz Mon Jun 13 11:00:57 AM CEST 2022 +From: "Jason A. Donenfeld" +Date: Mon, 13 Jun 2022 10:07:47 +0200 +Subject: random: avoid checking crng_ready() twice in random_init() +To: stable@vger.kernel.org, gregkh@linuxfoundation.org +Message-ID: <20220613080749.153222-2-Jason@zx2c4.com> + +From: "Jason A. Donenfeld" + +commit 9b29b6b20376ab64e1b043df6301d8a92378e631 upstream. + +The current flow expands to: + + if (crng_ready()) + ... + else if (...) + if (!crng_ready()) + ... + +The second crng_ready() call is redundant, but can't so easily be +optimized out by the compiler. + +This commit simplifies that to: + + if (crng_ready() + ... + else if (...) + ... + +Fixes: 560181c27b58 ("random: move initialization functions out of hot pages") +Cc: stable@vger.kernel.org +Cc: Dominik Brodowski +Signed-off-by: Jason A. Donenfeld +Signed-off-by: Greg Kroah-Hartman +--- + drivers/char/random.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/char/random.c ++++ b/drivers/char/random.c +@@ -838,7 +838,7 @@ int __init random_init(const char *comma + if (crng_ready()) + crng_reseed(); + else if (trust_cpu) +- credit_init_bits(arch_bytes * 8); ++ _credit_init_bits(arch_bytes * 8); + + return 0; + } diff --git a/queue-5.15/random-mark-bootloader-randomness-code-as-__init.patch b/queue-5.15/random-mark-bootloader-randomness-code-as-__init.patch new file mode 100644 index 00000000000..9d2563f07ea --- /dev/null +++ b/queue-5.15/random-mark-bootloader-randomness-code-as-__init.patch @@ -0,0 +1,64 @@ +From foo@baz Mon Jun 13 11:00:57 AM CEST 2022 +From: "Jason A. Donenfeld" +Date: Mon, 13 Jun 2022 10:07:48 +0200 +Subject: random: mark bootloader randomness code as __init +To: stable@vger.kernel.org, gregkh@linuxfoundation.org +Message-ID: <20220613080749.153222-3-Jason@zx2c4.com> + +From: "Jason A. Donenfeld" + +commit 39e0f991a62ed5efabd20711a7b6e7da92603170 upstream. + +add_bootloader_randomness() and the variables it touches are only used +during __init and not after, so mark these as __init. At the same time, +unexport this, since it's only called by other __init code that's +built-in. + +Cc: stable@vger.kernel.org +Fixes: 428826f5358c ("fdt: add support for rng-seed") +Signed-off-by: Jason A. Donenfeld +Signed-off-by: Greg Kroah-Hartman +--- + drivers/char/random.c | 7 +++---- + include/linux/random.h | 2 +- + 2 files changed, 4 insertions(+), 5 deletions(-) + +--- a/drivers/char/random.c ++++ b/drivers/char/random.c +@@ -789,8 +789,8 @@ static void __cold _credit_init_bits(siz + * + **********************************************************************/ + +-static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU); +-static bool trust_bootloader __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER); ++static bool trust_cpu __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU); ++static bool trust_bootloader __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER); + static int __init parse_trust_cpu(char *arg) + { + return kstrtobool(arg, &trust_cpu); +@@ -886,13 +886,12 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_random + * Handle random seed passed by bootloader, and credit it if + * CONFIG_RANDOM_TRUST_BOOTLOADER is set. + */ +-void __cold add_bootloader_randomness(const void *buf, size_t len) ++void __init add_bootloader_randomness(const void *buf, size_t len) + { + mix_pool_bytes(buf, len); + if (trust_bootloader) + credit_init_bits(len * 8); + } +-EXPORT_SYMBOL_GPL(add_bootloader_randomness); + + struct fast_pool { + struct work_struct mix; +--- a/include/linux/random.h ++++ b/include/linux/random.h +@@ -13,7 +13,7 @@ + struct notifier_block; + + void add_device_randomness(const void *buf, size_t len); +-void add_bootloader_randomness(const void *buf, size_t len); ++void __init add_bootloader_randomness(const void *buf, size_t len); + void add_input_randomness(unsigned int type, unsigned int code, + unsigned int value) __latent_entropy; + void add_interrupt_randomness(int irq) __latent_entropy; diff --git a/queue-5.15/series b/queue-5.15/series index 1495d0230db..a85811a70cb 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -239,3 +239,6 @@ drm-amdgpu-update-vcn-codec-support-for-yellow-carp.patch powerpc-32-fix-overread-overwrite-of-thread_struct-via-ptrace.patch powerpc-mm-switch-obsolete-dssall-to-.long.patch drm-ast-create-threshold-values-for-ast2600.patch +random-avoid-checking-crng_ready-twice-in-random_init.patch +random-mark-bootloader-randomness-code-as-__init.patch +random-account-for-arch-randomness-in-bits.patch