@@ -193,6 +193,10 @@ else
KBUILD_RUSTFLAGS += -Cno-redzone=y
KBUILD_RUSTFLAGS += -Ccode-model=kernel
+ ifeq ($(CONFIG_STACKPROTECTOR),y)
+ KBUILD_CFLAGS += -mstack-protector-guard-symbol=fixed_percpu_data
+ endif
+
# Don't emit relaxable GOTPCREL relocations
KBUILD_AFLAGS_KERNEL += -Wa,-mrelax-relocations=no
KBUILD_CFLAGS_KERNEL += -Wa,-mrelax-relocations=no
@@ -2,7 +2,7 @@
#ifndef _ASM_X86_INIT_H
#define _ASM_X86_INIT_H
-#define __head __section(".head.text")
+#define __head __section(".head.text") __no_stack_protector
struct x86_mapping_info {
void *(*alloc_pgt_page)(void *); /* allocate buf for page table */
@@ -402,14 +402,9 @@ struct irq_stack {
#ifdef CONFIG_X86_64
struct fixed_percpu_data {
/*
- * GCC hardcodes the stack canary as %gs:40. Since the
- * irq_stack is the object at %gs:0, we reserve the bottom
- * 48 bytes of the irq stack for the canary.
- *
- * Once we are willing to require -mstack-protector-guard-symbol=
- * support for x86_64 stackprotector, we can get rid of this.
+ * Since the irq_stack is the object at %gs:0, the bottom 8 bytes of
+ * the irq stack are reserved for the canary.
*/
- char gs_base[40];
unsigned long stack_canary;
};
@@ -418,7 +413,7 @@ DECLARE_INIT_PER_CPU(fixed_percpu_data);
static inline unsigned long cpu_kernelmode_gs_base(int cpu)
{
- return (unsigned long)per_cpu(fixed_percpu_data.gs_base, cpu);
+ return (unsigned long)&per_cpu(fixed_percpu_data, cpu);
}
extern asmlinkage void entry_SYSCALL32_ignore(void);
@@ -51,10 +51,6 @@ static __always_inline void boot_init_stack_canary(void)
{
unsigned long canary = get_random_canary();
-#ifdef CONFIG_X86_64
- BUILD_BUG_ON(offsetof(struct fixed_percpu_data, stack_canary) != 40);
-#endif
-
current->stack_canary = canary;
#ifdef CONFIG_X86_64
this_cpu_write(fixed_percpu_data.stack_canary, canary);
@@ -2485,10 +2485,10 @@ static bool is_stack_operation(struct arch *arch, struct disasm_line *dl)
static bool is_stack_canary(struct arch *arch, struct annotated_op_loc *loc)
{
- /* On x86_64, %gs:40 is used for stack canary */
+ /* On x86_64, %gs:0 is used for stack canary */
if (arch__is(arch, "x86")) {
if (loc->segment == INSN_SEG_X86_GS && loc->imm &&
- loc->offset == 40)
+ loc->offset == 0)
return true;
}