Commit 0d054d4e authored by Kees Cook's avatar Kees Cook Committed by Peter Zijlstra
Browse files

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: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20211013175742.1197608-3-keescook@chromium.org
parent a54c401a
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -56,10 +56,13 @@ unsigned long kaslr_get_random_long(const char *purpose)
	unsigned long raw, random = get_boot_seed();
	bool use_i8254 = true;

	if (purpose) {
		debug_putstr(purpose);
		debug_putstr(" KASLR using");
	}

	if (has_cpuflag(X86_FEATURE_RDRAND)) {
		if (purpose)
			debug_putstr(" RDRAND");
		if (rdrand_long(&raw)) {
			random ^= raw;
@@ -68,6 +71,7 @@ unsigned long kaslr_get_random_long(const char *purpose)
	}

	if (has_cpuflag(X86_FEATURE_TSC)) {
		if (purpose)
			debug_putstr(" RDTSC");
		raw = rdtsc();

@@ -76,6 +80,7 @@ unsigned long kaslr_get_random_long(const char *purpose)
	}

	if (use_i8254) {
		if (purpose)
			debug_putstr(" i8254");
		random ^= i8254();
	}
@@ -86,6 +91,7 @@ unsigned long kaslr_get_random_long(const char *purpose)
	    : "a" (random), "rm" (mix_const));
	random += raw;

	if (purpose)
		debug_putstr("...\n");

	return random;