From: Greg Kroah-Hartman Date: Mon, 10 Aug 2020 14:56:21 +0000 (+0200) Subject: 5.8-stable patches X-Git-Tag: v4.19.139~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c3addc27cc5906c55c10f72a9fdfb68a9c7edf3;p=thirdparty%2Fkernel%2Fstable-queue.git 5.8-stable patches added patches: random-random.h-should-include-archrandom.h-not-the-other-way-around.patch random32-move-the-pseudo-random-32-bit-definitions-to-prandom.h.patch --- diff --git a/queue-5.8/random-random.h-should-include-archrandom.h-not-the-other-way-around.patch b/queue-5.8/random-random.h-should-include-archrandom.h-not-the-other-way-around.patch new file mode 100644 index 00000000000..e40f21b8501 --- /dev/null +++ b/queue-5.8/random-random.h-should-include-archrandom.h-not-the-other-way-around.patch @@ -0,0 +1,49 @@ +From 585524081ecdcde1c719e63916c514866d898217 Mon Sep 17 00:00:00 2001 +From: Linus Torvalds +Date: Wed, 5 Aug 2020 12:39:48 -0700 +Subject: random: random.h should include archrandom.h, not the other way around +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Linus Torvalds + +commit 585524081ecdcde1c719e63916c514866d898217 upstream. + +This is hopefully the final piece of the crazy puzzle with random.h +dependencies. + +And by "hopefully" I obviously mean "Linus is a hopeless optimist". + +Reported-and-tested-by: Daniel Díaz +Acked-by: Guenter Roeck +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + arch/arm64/include/asm/archrandom.h | 1 - + arch/arm64/kernel/kaslr.c | 2 +- + 2 files changed, 1 insertion(+), 2 deletions(-) + +--- a/arch/arm64/include/asm/archrandom.h ++++ b/arch/arm64/include/asm/archrandom.h +@@ -6,7 +6,6 @@ + + #include + #include +-#include + #include + + static inline bool __arm64_rndr(unsigned long *v) +--- a/arch/arm64/kernel/kaslr.c ++++ b/arch/arm64/kernel/kaslr.c +@@ -11,8 +11,8 @@ + #include + #include + #include ++#include + +-#include + #include + #include + #include diff --git a/queue-5.8/random32-move-the-pseudo-random-32-bit-definitions-to-prandom.h.patch b/queue-5.8/random32-move-the-pseudo-random-32-bit-definitions-to-prandom.h.patch new file mode 100644 index 00000000000..358e8031b53 --- /dev/null +++ b/queue-5.8/random32-move-the-pseudo-random-32-bit-definitions-to-prandom.h.patch @@ -0,0 +1,213 @@ +From c0842fbc1b18c7a044e6ff3e8fa78bfa822c7d1a Mon Sep 17 00:00:00 2001 +From: Linus Torvalds +Date: Fri, 31 Jul 2020 07:51:14 +0200 +Subject: random32: move the pseudo-random 32-bit definitions to prandom.h + +From: Linus Torvalds + +commit c0842fbc1b18c7a044e6ff3e8fa78bfa822c7d1a upstream. + +The addition of percpu.h to the list of includes in random.h revealed +some circular dependencies on arm64 and possibly other platforms. This +include was added solely for the pseudo-random definitions, which have +nothing to do with the rest of the definitions in this file but are +still there for legacy reasons. + +This patch moves the pseudo-random parts to linux/prandom.h and the +percpu.h include with it, which is now guarded by _LINUX_PRANDOM_H and +protected against recursive inclusion. + +A further cleanup step would be to remove this from +entirely, and make people who use the prandom infrastructure include +just the new header file. That's a bit of a churn patch, but grepping +for "prandom_" and "next_pseudo_random32" "struct rnd_state" should +catch most users. + +But it turns out that that nice cleanup step is fairly painful, because +a _lot_ of code currently seems to depend on the implicit include of +, which can currently come in a lot of ways, including +such fairly core headfers as . + +So the "nice cleanup" part may or may never happen. + +Fixes: 1c9df907da83 ("random: fix circular include dependency on arm64 after addition of percpu.h") +Tested-by: Guenter Roeck +Acked-by: Willy Tarreau +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + include/linux/prandom.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ + include/linux/random.h | 66 ++-------------------------------------- + 2 files changed, 82 insertions(+), 62 deletions(-) + +--- /dev/null ++++ b/include/linux/prandom.h +@@ -0,0 +1,78 @@ ++/* SPDX-License-Identifier: GPL-2.0 */ ++/* ++ * include/linux/prandom.h ++ * ++ * Include file for the fast pseudo-random 32-bit ++ * generation. ++ */ ++#ifndef _LINUX_PRANDOM_H ++#define _LINUX_PRANDOM_H ++ ++#include ++#include ++ ++u32 prandom_u32(void); ++void prandom_bytes(void *buf, size_t nbytes); ++void prandom_seed(u32 seed); ++void prandom_reseed_late(void); ++ ++struct rnd_state { ++ __u32 s1, s2, s3, s4; ++}; ++ ++DECLARE_PER_CPU(struct rnd_state, net_rand_state); ++ ++u32 prandom_u32_state(struct rnd_state *state); ++void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); ++void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state); ++ ++#define prandom_init_once(pcpu_state) \ ++ DO_ONCE(prandom_seed_full_state, (pcpu_state)) ++ ++/** ++ * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) ++ * @ep_ro: right open interval endpoint ++ * ++ * Returns a pseudo-random number that is in interval [0, ep_ro). Note ++ * that the result depends on PRNG being well distributed in [0, ~0U] ++ * u32 space. Here we use maximally equidistributed combined Tausworthe ++ * generator, that is, prandom_u32(). This is useful when requesting a ++ * random index of an array containing ep_ro elements, for example. ++ * ++ * Returns: pseudo-random number in interval [0, ep_ro) ++ */ ++static inline u32 prandom_u32_max(u32 ep_ro) ++{ ++ return (u32)(((u64) prandom_u32() * ep_ro) >> 32); ++} ++ ++/* ++ * Handle minimum values for seeds ++ */ ++static inline u32 __seed(u32 x, u32 m) ++{ ++ return (x < m) ? x + m : x; ++} ++ ++/** ++ * prandom_seed_state - set seed for prandom_u32_state(). ++ * @state: pointer to state structure to receive the seed. ++ * @seed: arbitrary 64-bit value to use as a seed. ++ */ ++static inline void prandom_seed_state(struct rnd_state *state, u64 seed) ++{ ++ u32 i = (seed >> 32) ^ (seed << 10) ^ seed; ++ ++ state->s1 = __seed(i, 2U); ++ state->s2 = __seed(i, 8U); ++ state->s3 = __seed(i, 16U); ++ state->s4 = __seed(i, 128U); ++} ++ ++/* Pseudo random number generator from numerical recipes. */ ++static inline u32 next_pseudo_random32(u32 seed) ++{ ++ return seed * 1664525 + 1013904223; ++} ++ ++#endif +--- a/include/linux/random.h ++++ b/include/linux/random.h +@@ -11,7 +11,6 @@ + #include + #include + #include +-#include + + #include + +@@ -111,63 +110,12 @@ declare_get_random_var_wait(long) + + unsigned long randomize_page(unsigned long start, unsigned long range); + +-u32 prandom_u32(void); +-void prandom_bytes(void *buf, size_t nbytes); +-void prandom_seed(u32 seed); +-void prandom_reseed_late(void); +- +-struct rnd_state { +- __u32 s1, s2, s3, s4; +-}; +- +-DECLARE_PER_CPU(struct rnd_state, net_rand_state); +- +-u32 prandom_u32_state(struct rnd_state *state); +-void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); +-void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state); +- +-#define prandom_init_once(pcpu_state) \ +- DO_ONCE(prandom_seed_full_state, (pcpu_state)) +- +-/** +- * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) +- * @ep_ro: right open interval endpoint +- * +- * Returns a pseudo-random number that is in interval [0, ep_ro). Note +- * that the result depends on PRNG being well distributed in [0, ~0U] +- * u32 space. Here we use maximally equidistributed combined Tausworthe +- * generator, that is, prandom_u32(). This is useful when requesting a +- * random index of an array containing ep_ro elements, for example. +- * +- * Returns: pseudo-random number in interval [0, ep_ro) +- */ +-static inline u32 prandom_u32_max(u32 ep_ro) +-{ +- return (u32)(((u64) prandom_u32() * ep_ro) >> 32); +-} +- + /* +- * Handle minimum values for seeds +- */ +-static inline u32 __seed(u32 x, u32 m) +-{ +- return (x < m) ? x + m : x; +-} +- +-/** +- * prandom_seed_state - set seed for prandom_u32_state(). +- * @state: pointer to state structure to receive the seed. +- * @seed: arbitrary 64-bit value to use as a seed. ++ * This is designed to be standalone for just prandom ++ * users, but for now we include it from ++ * for legacy reasons. + */ +-static inline void prandom_seed_state(struct rnd_state *state, u64 seed) +-{ +- u32 i = (seed >> 32) ^ (seed << 10) ^ seed; +- +- state->s1 = __seed(i, 2U); +- state->s2 = __seed(i, 8U); +- state->s3 = __seed(i, 16U); +- state->s4 = __seed(i, 128U); +-} ++#include + + #ifdef CONFIG_ARCH_RANDOM + # include +@@ -210,10 +158,4 @@ static inline bool __init arch_get_rando + } + #endif + +-/* Pseudo random number generator from numerical recipes. */ +-static inline u32 next_pseudo_random32(u32 seed) +-{ +- return seed * 1664525 + 1013904223; +-} +- + #endif /* _LINUX_RANDOM_H */ diff --git a/queue-5.8/series b/queue-5.8/series index 68a1e0036e3..845fe77c963 100644 --- a/queue-5.8/series +++ b/queue-5.8/series @@ -33,3 +33,5 @@ revert-powerpc-kasan-fix-shadow-pages-allocation-failure.patch powerpc-kasan-fix-shadow-pages-allocation-failure.patch pci-tegra-revert-tegra124-raw_violation_fixup.patch ima-move-appraise_bootparam-dependency-on-arch_policy-to-runtime.patch +random32-move-the-pseudo-random-32-bit-definitions-to-prandom.h.patch +random-random.h-should-include-archrandom.h-not-the-other-way-around.patch