| .. | .. |
|---|
| 13 | 13 | * On x86_64, %gs is shared by percpu area and stack canary. All |
|---|
| 14 | 14 | * percpu symbols are zero based and %gs points to the base of percpu |
|---|
| 15 | 15 | * area. The first occupant of the percpu area is always |
|---|
| 16 | | - * irq_stack_union which contains stack_canary at offset 40. Userland |
|---|
| 16 | + * fixed_percpu_data which contains stack_canary at offset 40. Userland |
|---|
| 17 | 17 | * %gs is always saved and restored on kernel entry and exit using |
|---|
| 18 | 18 | * swapgs, so stack protector doesn't add any complexity there. |
|---|
| 19 | 19 | * |
|---|
| .. | .. |
|---|
| 65 | 65 | */ |
|---|
| 66 | 66 | static __always_inline void boot_init_stack_canary(void) |
|---|
| 67 | 67 | { |
|---|
| 68 | | - u64 uninitialized_var(canary); |
|---|
| 68 | + u64 canary; |
|---|
| 69 | 69 | u64 tsc; |
|---|
| 70 | 70 | |
|---|
| 71 | 71 | #ifdef CONFIG_X86_64 |
|---|
| 72 | | - BUILD_BUG_ON(offsetof(union irq_stack_union, stack_canary) != 40); |
|---|
| 72 | + BUILD_BUG_ON(offsetof(struct fixed_percpu_data, stack_canary) != 40); |
|---|
| 73 | 73 | #endif |
|---|
| 74 | 74 | /* |
|---|
| 75 | 75 | * We both use the random pool and the current TSC as a source |
|---|
| 76 | 76 | * of randomness. The TSC only matters for very early init, |
|---|
| 77 | 77 | * there it already has some randomness on most systems. Later |
|---|
| 78 | 78 | * on during the bootup the random pool has true entropy too. |
|---|
| 79 | | - * For preempt-rt we need to weaken the randomness a bit, as |
|---|
| 80 | | - * we can't call into the random generator from atomic context |
|---|
| 81 | | - * due to locking constraints. We just leave canary |
|---|
| 82 | | - * uninitialized and use the TSC based randomness on top of it. |
|---|
| 83 | 79 | */ |
|---|
| 84 | | -#ifndef CONFIG_PREEMPT_RT_FULL |
|---|
| 85 | 80 | get_random_bytes(&canary, sizeof(canary)); |
|---|
| 86 | | -#endif |
|---|
| 87 | 81 | tsc = rdtsc(); |
|---|
| 88 | 82 | canary += tsc + (tsc << 32UL); |
|---|
| 89 | 83 | canary &= CANARY_MASK; |
|---|
| 90 | 84 | |
|---|
| 91 | 85 | current->stack_canary = canary; |
|---|
| 92 | 86 | #ifdef CONFIG_X86_64 |
|---|
| 93 | | - this_cpu_write(irq_stack_union.stack_canary, canary); |
|---|
| 87 | + this_cpu_write(fixed_percpu_data.stack_canary, canary); |
|---|
| 94 | 88 | #else |
|---|
| 95 | 89 | this_cpu_write(stack_canary.canary, canary); |
|---|
| 90 | +#endif |
|---|
| 91 | +} |
|---|
| 92 | + |
|---|
| 93 | +static inline void cpu_init_stack_canary(int cpu, struct task_struct *idle) |
|---|
| 94 | +{ |
|---|
| 95 | +#ifdef CONFIG_X86_64 |
|---|
| 96 | + per_cpu(fixed_percpu_data.stack_canary, cpu) = idle->stack_canary; |
|---|
| 97 | +#else |
|---|
| 98 | + per_cpu(stack_canary.canary, cpu) = idle->stack_canary; |
|---|
| 96 | 99 | #endif |
|---|
| 97 | 100 | } |
|---|
| 98 | 101 | |
|---|
| .. | .. |
|---|
| 125 | 128 | static inline void setup_stack_canary_segment(int cpu) |
|---|
| 126 | 129 | { } |
|---|
| 127 | 130 | |
|---|
| 131 | +static inline void cpu_init_stack_canary(int cpu, struct task_struct *idle) |
|---|
| 132 | +{ } |
|---|
| 133 | + |
|---|
| 128 | 134 | static inline void load_stack_canary_segment(void) |
|---|
| 129 | 135 | { |
|---|
| 130 | 136 | #ifdef CONFIG_X86_32 |
|---|