]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/asm-x86/stackprotector.h
Merge branch 'linus' into stackprotector
[linux-2.6-omap-h63xx.git] / include / asm-x86 / stackprotector.h
1 #ifndef _ASM_STACKPROTECTOR_H
2 #define _ASM_STACKPROTECTOR_H 1
3
4 #include <asm/tsc.h>
5
6 /*
7  * Initialize the stackprotector canary value.
8  *
9  * NOTE: this must only be called from functions that never return,
10  * and it must always be inlined.
11  */
12 static __always_inline void boot_init_stack_canary(void)
13 {
14         u64 canary;
15         u64 tsc;
16
17         /*
18          * If we're the non-boot CPU, nothing set the PDA stack
19          * canary up for us - and if we are the boot CPU we have
20          * a 0 stack canary. This is a good place for updating
21          * it, as we wont ever return from this function (so the
22          * invalid canaries already on the stack wont ever
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.
29          */
30         get_random_bytes(&canary, sizeof(canary));
31         tsc = __native_read_tsc();
32         canary += tsc + (tsc << 32UL);
33
34         current->stack_canary = canary;
35         write_pda(stack_canary, canary);
36 }
37
38 #endif