Skip to content

Commit 2e8e1ea

Browse files
brooniewilldeacon
authored andcommitted
arm64: Use v8.5-RNG entropy for KASLR seed
When seeding KALSR on a system where we have architecture level random number generation make use of that entropy, mixing it in with the seed passed by the bootloader. Since this is run very early in init before feature detection is complete we open code rather than use archrandom.h. Signed-off-by: Mark Brown <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 1a50ec0 commit 2e8e1ea

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

arch/arm64/include/asm/archrandom.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,17 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
5959
return ok;
6060
}
6161

62+
static inline bool __init __early_cpu_has_rndr(void)
63+
{
64+
/* Open code as we run prior to the first call to cpufeature. */
65+
unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1);
66+
return (ftr >> ID_AA64ISAR0_RNDR_SHIFT) & 0xf;
67+
}
68+
6269
#else
6370

6471
static inline bool __arm64_rndr(unsigned long *v) { return false; }
72+
static inline bool __init __early_cpu_has_rndr(void) { return false; }
6573

6674
#endif /* CONFIG_ARCH_RANDOM */
6775
#endif /* _ASM_ARCHRANDOM_H */

arch/arm64/kernel/kaslr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ u64 __init kaslr_early_init(u64 dt_phys)
120120
return 0;
121121
}
122122

123+
/*
124+
* Mix in any entropy obtainable architecturally, open coded
125+
* since this runs extremely early.
126+
*/
127+
if (__early_cpu_has_rndr()) {
128+
unsigned long raw;
129+
130+
if (__arm64_rndr(&raw))
131+
seed ^= raw;
132+
}
133+
123134
if (!seed) {
124135
kaslr_status = KASLR_DISABLED_NO_SEED;
125136
return 0;

0 commit comments

Comments
 (0)