blob: 2383e5bb475cc25c7d8e98bdef960b0d4f09a9f4 [file] [log] [blame]
Ingo Molnarb2b062b2009-01-18 18:37:14 +01001#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 */
13static __always_inline void boot_init_stack_canary(void)
14{
15 u64 canary;
16 u64 tsc;
17
18 /*
Tejun Heoc6e50f92009-01-20 12:29:19 +090019 * Build time only check to make sure the stack_canary is at
20 * offset 40 in the pda; this is a gcc ABI requirement
21 */
22 BUILD_BUG_ON(offsetof(struct x8664_pda, stack_canary) != 40);
23
24 /*
Ingo Molnarb2b062b2009-01-18 18:37:14 +010025 * 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