aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86/stackprotector.h
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-02-14 03:56:04 -0500
committerThomas Gleixner <tglx@linutronix.de>2008-05-26 10:15:32 -0400
commit960a672bd9f1ec06e8f197cf81a50fd07ea02e7f (patch)
treeed7372988fb2ca06f0a3dd4719652ab2d370153c /include/asm-x86/stackprotector.h
parent420594296838fdc9a674470d710cda7d1487f9f4 (diff)
x86: stackprotector: mix TSC to the boot canary
mix the TSC to the boot canary. Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/asm-x86/stackprotector.h')
-rw-r--r--include/asm-x86/stackprotector.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/include/asm-x86/stackprotector.h b/include/asm-x86/stackprotector.h
index 0f91f7a2688..3baf7ad89be 100644
--- a/include/asm-x86/stackprotector.h
+++ b/include/asm-x86/stackprotector.h
@@ -1,6 +1,8 @@
1#ifndef _ASM_STACKPROTECTOR_H 1#ifndef _ASM_STACKPROTECTOR_H
2#define _ASM_STACKPROTECTOR_H 1 2#define _ASM_STACKPROTECTOR_H 1
3 3
4#include <asm/tsc.h>
5
4/* 6/*
5 * Initialize the stackprotector canary value. 7 * Initialize the stackprotector canary value.
6 * 8 *
@@ -9,16 +11,28 @@
9 */ 11 */
10static __always_inline void boot_init_stack_canary(void) 12static __always_inline void boot_init_stack_canary(void)
11{ 13{
14 u64 canary;
15 u64 tsc;
16
12 /* 17 /*
13 * If we're the non-boot CPU, nothing set the PDA stack 18 * If we're the non-boot CPU, nothing set the PDA stack
14 * canary up for us - and if we are the boot CPU we have 19 * canary up for us - and if we are the boot CPU we have
15 * a 0 stack canary. This is a good place for updating 20 * a 0 stack canary. This is a good place for updating
16 * it, as we wont ever return from this function (so the 21 * it, as we wont ever return from this function (so the
17 * invalid canaries already on the stack wont ever 22 * invalid canaries already on the stack wont ever
18 * trigger): 23 * trigger).
24 *
25 * We both use the random pool and the current TSC as a source
26 * of randomness. The TSC only matters for very early init,
27 * there it already has some randomness on most systems. Later
28 * on during the bootup the random pool has true entropy too.
19 */ 29 */
20 current->stack_canary = get_random_int(); 30 get_random_bytes(&canary, sizeof(canary));
21 write_pda(stack_canary, current->stack_canary); 31 tsc = __native_read_tsc();
32 canary += tsc + (tsc << 32UL);
33
34 current->stack_canary = canary;
35 write_pda(stack_canary, canary);
22} 36}
23 37
24#endif 38#endif