Some architectures (e.g. arm64) can have heterogeneous CPUs, and the boot CPU may be able to provide entropy while secondary CPUs cannot. On such systems, arch_get_random_long() and arch_get_random_seed_long() will fail unless support for RNG instructions has been detected on all CPUs. This prevents the boot CPU from being able to provide (potentially) trusted entropy when seeding the primary CRNG. To make it possible to seed the primary CRNG from the boot CPU without adversely affecting the runtime versions of arch_get_random_long() and arch_get_random_seed_long(), this patch adds new early versions of the functions used when initializing the primary CRNG. Default implementations are provided atop of the existing arch_get_random_long() and arch_get_random_seed_long() so that only architectures with such constraints need to provide the new helpers. There should be no functional change as a result of this patch.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -7,6 +7,8 @@ · 6 unmodified lines | |||
| 7 | #ifndef _LINUX_RANDOM_H | 7 | #ifndef _LINUX_RANDOM_H |
| 8 | #define _LINUX_RANDOM_H | 8 | #define _LINUX_RANDOM_H |
| 9 | 9 | ||
| 10 | #include <linux/bug.h> | ||
| 11 | #include <linux/kernel.h> | ||
| 10 | #include <linux/list.h> | 12 | #include <linux/list.h> |
| 11 | #include <linux/once.h> | 13 | #include <linux/once.h> |
| 12 | 14 | ||
| @@ -185,6 +187,26 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v) · 172 unmodified lines | |||
| 185 | } | 187 | } |
| 186 | #endif | 188 | #endif |
| 187 | 189 | ||
| 190 | /* | ||
| 191 | * Called from the boot CPU during startup; not valid to call once | ||
| 192 | * secondary CPUs are up and preemption is possible. | ||
| 193 | */ | ||
| 194 | #ifndef arch_get_random_seed_long_early | ||
| 195 | static inline bool __init arch_get_random_seed_long_early(unsigned long *v) | ||
| 196 | { | ||
| 197 | WARN_ON(system_state != SYSTEM_BOOTING); | ||
| 198 | return arch_get_random_seed_long(v); | ||
| 199 | } | ||
| 200 | #endif | ||
| 201 | |||
| 202 | #ifndef arch_get_random_long_early | ||
| 203 | static inline bool __init arch_get_random_long_early(unsigned long *v) | ||
| 204 | { | ||
| 205 | WARN_ON(system_state != SYSTEM_BOOTING); | ||
| 206 | return arch_get_random_long(v); | ||
| 207 | } | ||
| 208 | #endif | ||
| 209 | |||
| 188 | /* Pseudo random number generator from numerical recipes. */ | 210 | /* Pseudo random number generator from numerical recipes. */ |
| 189 | static inline u32 next_pseudo_random32(u32 seed) | 211 | static inline u32 next_pseudo_random32(u32 seed) |
| 190 | { | 212 | { |