@@ -164,5 +164,6 @@ int main(void)
DEFINE(SDEI_EVENT_INTREGS, offsetof(struct sdei_registered_event,
interrupted_regs));
DEFINE(SDEI_EVENT_PRIORITY, offsetof(struct sdei_registered_event,
priority));
#endif
+ DEFINE(TSK_STACK_CANARY, offsetof(struct task_struct, stack_canary));
return 0;
}
@@ -18,6 +18,8 @@
#ifndef __ASM_IMAGE_H
#define __ASM_IMAGE_H
+#include <asm/asm-offsets.h>
+
#ifndef LINKER_SCRIPT
#error This file should only be included in vmlinux.lds.S
#endif
@@ -118,4 +120,6 @@ __efistub_screen_info =
KALLSYMS_HIDE(screen_info);
#endif
+PROVIDE(__stack_chk_guard_tsk_offset = ABSOLUTE(TSK_STACK_CANARY));
+
#endif /* __ASM_IMAGE_H */
---------------------8<--------------------------
GCC patch
---------------------8<--------------------------
@@ -17208,6 +17208,12 @@ aarch64_select_early_remat_modes (sbitmap modes)
}
}
+static tree
+aarch64_init_stack_protect_guard (void)
+{
+ return NULL_TREE;
+}
+
/* Target-specific selftests. */
#if CHECKING_P
@@ -17682,6 +17688,9 @@ aarch64_libgcc_floating_mode_supported_p
#define TARGET_RUN_TARGET_SELFTESTS selftest::aarch64_run_selftests
#endif /* #if CHECKING_P */
+#undef TARGET_STACK_PROTECT_GUARD
+#define TARGET_STACK_PROTECT_GUARD aarch64_init_stack_protect_guard
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-aarch64.h"
@@ -168,6 +168,7 @@
UNSPEC_INSR
UNSPEC_CLASTB
UNSPEC_FADDA
+ UNSPEC_TSK_STACK_CANARY
])
(define_c_enum "unspecv" [
@@ -5834,6 +5835,15 @@
DONE;
})
+(define_insn "aarch64_load_current_stack_canary"
+ [(set (match_operand:DI 0 "register_operand" "=r")
+ (unspec:DI [(const_int 0)] UNSPEC_TSK_STACK_CANARY))]
+ ""
+ "mrs\\t%0, sp_el0\;add\\t%0, %0, :lo12:__stack_chk_guard_tsk_offset"
+ [(set_attr "type" "multiple")
+ (set_attr "length" "8")]
+)
+
;; Named patterns for stack smashing protection.
(define_expand "stack_protect_set"
[(match_operand 0 "memory_operand")
@@ -5842,6 +5852,11 @@
{
machine_mode mode = GET_MODE (operands[0]);
+ rtx reg = gen_reg_rtx (Pmode);
+
+ operands[1] = gen_rtx_MEM (Pmode, reg);
+ emit_insn (gen_aarch64_load_current_stack_canary (reg));
+
emit_insn ((mode == DImode
? gen_stack_protect_set_di
: gen_stack_protect_set_si) (operands[0], operands[1]));
@@ -5867,6 +5882,11 @@
rtx result;
machine_mode mode = GET_MODE (operands[0]);
+ rtx reg = gen_reg_rtx (Pmode);
+
+ operands[1] = gen_rtx_MEM (Pmode, reg);
+ emit_insn (gen_aarch64_load_current_stack_canary (reg));
+
result = gen_reg_rtx(mode);
emit_insn ((mode == DImode