Skip to contentSkip to conversation

arm64: kaslr: Print warning if KASLR is disabled due to lack of seed

PATCH In review Mark Brown 3 participants 5 messages Nov 7, 2019 – Nov 8, 2019 arm64

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 arm64: kaslr: Print warning if KASLR is disabled due to lack of seed

It seems to be a relatively common system integration error for system integrators and administrators to enable KASLR in their configuration but not provide the seed at runtime, sometimes due to that breaking at some later point after it is initially enabled. Since KASLR is not announced at boot time unless it forces on KPTI this can lead to users incorrectly believing their system has the feature enabled when in fact it does not, and if they notice the problem the lack of any diagnostics makes it harder to understand the problem. Provide a warning message to assist in these situations.

---
 arch/arm64/kernel/kaslr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kernel/kaslr.c +3 -1
index 416f537bf614..c2ba5e783ada 100644
@@ -98,8 +98,10 @@ u64 __init kaslr_early_init(u64 dt_phys)
 	 * Retrieve (and wipe) the seed from the FDT
 	 */
 	seed = get_kaslr_seed(fdt);
-	if (!seed)
+	if (!seed) {
+		pr_warn("No seed available for KASLR, disabling\n");
 		return 0;
+	}
 
 	/*
 	 * Check if 'nokaslr' appears on the command line, and
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw
Quoted 6 lines · Mark Brown
arch/arm64/kernel/kaslr.c +0 -0
index 416f537bf614..c2ba5e783ada 100644
@@ -98,8 +98,10 @@ u64 __init kaslr_early_init(u64 dt_phys)
 	 * Retrieve (and wipe) the seed from the FDT

arch/arm64/kernel/kaslr.c u64 __init kaslr_early_init(u64 dt_phys) · line 107

Quoted 10 lines
arch/arm64/kernel/kaslr.c +3 -1
 	 */
 	seed = get_kaslr_seed(fdt);
-	if (!seed)
+	if (!seed) {
+		pr_warn("No seed available for KASLR, disabling\n");
 		return 0;
+	}
 
 	/*
 	 * Check if 'nokaslr' appears on the command line, and

For some reason, this patch locks up the VM on TX2, stuck in a recursive fault. Too early for a printk?

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer
#2 lore raw
Quoted 15 lines · Catalin Marinas
Quoted 14 lines · Mark Brown
arch/arm64/kernel/kaslr.c +3 -1
index 416f537bf614..c2ba5e783ada 100644
@@ -98,8 +98,10 @@ u64 __init kaslr_early_init(u64 dt_phys)
 	 * Retrieve (and wipe) the seed from the FDT
 	 */
 	seed = get_kaslr_seed(fdt);
-	if (!seed)
+	if (!seed) {
+		pr_warn("No seed available for KASLR, disabling\n");
 		return 0;
+	}
 
Quoted 5 lines

arch/arm64/kernel/kaslr.c u64 __init kaslr_early_init(u64 dt_phys) · line 107

Quoted 2 lines
arch/arm64/kernel/kaslr.c +0 -0
 	/*
 	 * Check if 'nokaslr' appears on the command line, and

For some reason, this patch locks up the VM on TX2, stuck in a recursive fault. Too early for a printk?

We call kaslr_early_init() before start_kernel(), so we haven't set up things like the per-cpu offset here (and I believe that printk relies on that internally).

To avoid surprises, I think it'd be best to log that state later, in setup.c. We can also do that consistently, so that the user has a positive message when KASLR is in use.

We can either have something like:

void announce_kaslr(void)

{
	if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
		return;
	
	if (kaslr_offset() != 0)
		pr_info("KASLR in use\n");
	else if (in_commandline("nokaslr"))
		pr_info("KASLR disabled (command line)\n");
	else
		pr_info("KASLR disabled (no seed)\n");
}

Or have kaslr.c update something like:

enum kaslr_status {
KASLR_ENABLED,
KASLR_DISABLED,
KASLR_NO_SEED,
};

enum kaslr_status __ro_after_init kaslr_status;

... and switch on that in setup.c.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#3 lore raw
Quoted 1 line · Mark Rutland

To avoid surprises, I think it'd be best to log that state later, in

I was just going to add an initcall in kaslr.c to keep things together.

Quoted 2 lines

setup.c. We can also do that consistently, so that the user has a positive message when KASLR is in use.

So long as people are happy announcing it, I didn't add anything since I wasn't clear if this was a deliberate decision to not provide information but I see now it was more likely just the fact that it's running too early to reliably print.

Quoted 9 lines

enum kaslr_status {
KASLR_ENABLED,
KASLR_DISABLED,
KASLR_NO_SEED,
};

enum kaslr_status __ro_after_init kaslr_status;

... and switch on that in setup.c.

Having the enum seems like it spreads the code out for unclear advantage, apart from the logging nothing particularly cares about anything other than the enabled/disabled decision.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#4 lore raw
In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas

arch/arm64/kernel/kaslr.c u64 __init kaslr_early_init(u64 dt_phys) · line 104

Quoted 6 lines · Mark Brown
arch/arm64/kernel/kaslr.c +3 -1
 	seed = get_kaslr_seed(fdt);
-	if (!seed)
+	if (!seed) {
+		pr_warn("No seed available for KASLR, disabling\n");
 		return 0;
+	}

For some reason, this patch locks up the VM on TX2, stuck in a recursive fault. Too early for a printk?

I guess so - I was able to trigger this print without problems on my system locally, not sure what configuration or system changes would make the difference on TX2 but clearly there's at least some with issues. That's annoying, I'll add an initcall to do the print instead.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel