Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/boot: Allow a "silent" kaslr random byte fetch

Under earlyprintk, each RNG call produces a debug report line. To support
the future FGKASLR feature, which will fetch random bytes during function
shuffling, this is not useful information (each line is identical and
tells us nothing new), needlessly spamming the console. Instead, allow
for a NULL "purpose" to suppress the debug reporting.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20211013175742.1197608-3-keescook@chromium.org

authored by

Kees Cook and committed by
Peter Zijlstra
0d054d4e a54c401a

+12 -6
+12 -6
arch/x86/lib/kaslr.c
··· 56 56 unsigned long raw, random = get_boot_seed(); 57 57 bool use_i8254 = true; 58 58 59 - debug_putstr(purpose); 60 - debug_putstr(" KASLR using"); 59 + if (purpose) { 60 + debug_putstr(purpose); 61 + debug_putstr(" KASLR using"); 62 + } 61 63 62 64 if (has_cpuflag(X86_FEATURE_RDRAND)) { 63 - debug_putstr(" RDRAND"); 65 + if (purpose) 66 + debug_putstr(" RDRAND"); 64 67 if (rdrand_long(&raw)) { 65 68 random ^= raw; 66 69 use_i8254 = false; ··· 71 68 } 72 69 73 70 if (has_cpuflag(X86_FEATURE_TSC)) { 74 - debug_putstr(" RDTSC"); 71 + if (purpose) 72 + debug_putstr(" RDTSC"); 75 73 raw = rdtsc(); 76 74 77 75 random ^= raw; ··· 80 76 } 81 77 82 78 if (use_i8254) { 83 - debug_putstr(" i8254"); 79 + if (purpose) 80 + debug_putstr(" i8254"); 84 81 random ^= i8254(); 85 82 } 86 83 ··· 91 86 : "a" (random), "rm" (mix_const)); 92 87 random += raw; 93 88 94 - debug_putstr("...\n"); 89 + if (purpose) 90 + debug_putstr("...\n"); 95 91 96 92 return random; 97 93 }