Skip to contentSkip to conversation

init: Move stack canary initialization after setup_arch

PATCH Superseded Laura Abbott 2 participants 2 messages Aug 16, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init: Move stack canary initialization after setup_arch

From: Laura Abbott <[email protected]>

Stack canary intialization involves getting a random number. Getting this random number may involve accessing caches or other architectural specific features which are not available until after the architecture is setup. Move the stack canary initialization later to accomodate this.

---
This was a patch I did a while ago as part of some out of tree work to make the stack canary randomized on arm. The overall work didn't really go anywhere but there is interest in this part for other approaches to adding randomeness.

I can re-send with more Cc for anyone else who might have opinions.

---
 init/main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
init/main.c +4 -4
index 052481fbe363..c71c4451094c 100644
@@ -515,11 +515,7 @@ asmlinkage __visible void __init start_kernel(void)
 	smp_setup_processor_id();
 	debug_objects_early_init();
 
-	/*
-	 * Set up the initial canary ASAP:
-	 */
 	add_latent_entropy();
-	boot_init_stack_canary();
 
 	cgroup_init_early();
 
@@ -534,6 +530,10 @@ asmlinkage __visible void __init start_kernel(void)
 	page_address_init();
 	pr_notice("%s", linux_banner);
 	setup_arch(&command_line);
+	/*
+	 * Set up the the initial canary ASAP:
+	 */
+	boot_init_stack_canary();
 	mm_init_cpumask(&init_mm);
 	setup_command_line(command_line);
 	setup_nr_cpu_ids();
Signature · 1 line
2.13.0
#1 lore raw
Quoted 8 lines · Laura Abbott

From: Laura Abbott <[email protected]>

Stack canary intialization involves getting a random number. Getting this random number may involve accessing caches or other architectural specific features which are not available until after the architecture is setup. Move the stack canary initialization later to accomodate this.

Quoted 8 lines

---
This was a patch I did a while ago as part of some out of tree work to make the stack canary randomized on arm. The overall work didn't really go anywhere but there is interest in this part for other approaches to adding randomeness.

I can re-send with more Cc for anyone else who might have opinions.

Combined with adding the kernel cmdline to entropy, this would be desirable. This should probably go via -mm (as far a CCs go).

Quoted 9 lines
---
 init/main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
init/main.c +0 -0
index 052481fbe363..c71c4451094c 100644

init/main.c asmlinkage __visible void __init start_kernel(void) · line 522

Quoted 8 lines
init/main.c +0 -4
@@ -515,11 +515,7 @@ asmlinkage __visible void __init start_kernel(void)
        smp_setup_processor_id();
        debug_objects_early_init();
 
-       /*
-        * Set up the initial canary ASAP:
-        */
        add_latent_entropy();
-       boot_init_stack_canary();

Please move the entropy call too, since that should be just before the stack canary initialization (in an effort to gather as much as possible).

init/main.c asmlinkage __visible void __init start_kernel(void) · line 534

Quoted 9 lines
init/main.c +2 -0
        cgroup_init_early();
 
@@ -534,6 +530,10 @@ asmlinkage __visible void __init start_kernel(void)
        page_address_init();
        pr_notice("%s", linux_banner);
        setup_arch(&command_line);
+       /*
+        * Set up the the initial canary ASAP:

Maybe change "ASAP" to "after reasonable entropy has been gathered"

Quoted 8 lines
init/main.c +2 -1
+        */
+       boot_init_stack_canary();
        mm_init_cpumask(&init_mm);
        setup_command_line(command_line);
        setup_nr_cpu_ids();
--

2.13.0

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Pixel Security