]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/include/asm/stackprotector.h
Merge branch 'core/percpu' into stackprotector
[linux-2.6-omap-h63xx.git] / arch / x86 / include / asm / stackprotector.h
1 #ifndef _ASM_STACKPROTECTOR_H
2 #define _ASM_STACKPROTECTOR_H 1
3
4 #include <asm/tsc.h>
5 #include <asm/pda.h>
6
7 /*
8  * Initialize the stackprotector canary value.
9  *
10  * NOTE: this must only be called from functions that never return,
11  * and it must always be inlined.
12  */
13 static __always_inline void boot_init_stack_canary(void)
14 {
15         u64 canary;
16         u64 tsc;
17
18         /*
19          * If we're the non-boot CPU, nothing set the PDA stack
20          * canary up for us - and if we are the boot CPU we have
21          * a 0 stack canary. This is a good place for updating
22          * it, as we wont ever return from this function (so the
23          * invalid canaries already on the stack wont ever
24          * trigger).
25          *
26          * We both use the random pool and the current TSC as a source
27          * of randomness. The TSC only matters for very early init,
28          * there it already has some randomness on most systems. Later
29          * on during the bootup the random pool has true entropy too.
30          */
31         get_random_bytes(&canary, sizeof(canary));
32         tsc = __native_read_tsc();
33         canary += tsc + (tsc << 32UL);
34
35         current->stack_canary = canary;
36         write_pda(stack_canary, canary);
37 }
38
39 #endif