提交 960a672b 编写于 作者: I Ingo Molnar 提交者: Thomas Gleixner

x86: stackprotector: mix TSC to the boot canary

mix the TSC to the boot canary.
Signed-off-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 42059429
#ifndef _ASM_STACKPROTECTOR_H #ifndef _ASM_STACKPROTECTOR_H
#define _ASM_STACKPROTECTOR_H 1 #define _ASM_STACKPROTECTOR_H 1
#include <asm/tsc.h>
/* /*
* Initialize the stackprotector canary value. * Initialize the stackprotector canary value.
* *
...@@ -9,16 +11,28 @@ ...@@ -9,16 +11,28 @@
*/ */
static __always_inline void boot_init_stack_canary(void) static __always_inline void boot_init_stack_canary(void)
{ {
u64 canary;
u64 tsc;
/* /*
* If we're the non-boot CPU, nothing set the PDA stack * If we're the non-boot CPU, nothing set the PDA stack
* canary up for us - and if we are the boot CPU we have * canary up for us - and if we are the boot CPU we have
* a 0 stack canary. This is a good place for updating * a 0 stack canary. This is a good place for updating
* it, as we wont ever return from this function (so the * it, as we wont ever return from this function (so the
* invalid canaries already on the stack wont ever * invalid canaries already on the stack wont ever
* trigger): * trigger).
*
* We both use the random pool and the current TSC as a source
* of randomness. The TSC only matters for very early init,
* there it already has some randomness on most systems. Later
* on during the bootup the random pool has true entropy too.
*/ */
current->stack_canary = get_random_int(); get_random_bytes(&canary, sizeof(canary));
write_pda(stack_canary, current->stack_canary); tsc = __native_read_tsc();
canary += tsc + (tsc << 32UL);
current->stack_canary = canary;
write_pda(stack_canary, canary);
} }
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册