summaryrefslogtreecommitdiff
path: root/sys/arch/arm64
diff options
context:
space:
mode:
authormortimer <mortimer@cvs.openbsd.org>2018-09-07 01:32:02 +0000
committermortimer <mortimer@cvs.openbsd.org>2018-09-07 01:32:02 +0000
commitce63742534bc2b6e45f50ac773a7a685b8b8c43c (patch)
treea011f91668140a4385e244e51b6297cddff8b06c /sys/arch/arm64
parent8568083a4818915a0b1d498dbd0fe7d6dd79a68c (diff)
Add retguard macros to cpu_switchto, setjmp, longjmp.
ok kettenis@
Diffstat (limited to 'sys/arch/arm64')
-rw-r--r--sys/arch/arm64/arm64/cpuswitch.S7
-rw-r--r--sys/arch/arm64/arm64/support.S8
-rw-r--r--sys/arch/arm64/include/asm.h25
3 files changed, 31 insertions, 9 deletions
diff --git a/sys/arch/arm64/arm64/cpuswitch.S b/sys/arch/arm64/arm64/cpuswitch.S
index 4cdda217f4c..0eaa6d583e3 100644
--- a/sys/arch/arm64/arm64/cpuswitch.S
+++ b/sys/arch/arm64/arm64/cpuswitch.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpuswitch.S,v 1.3 2018/03/29 19:25:39 patrick Exp $ */
+/* $OpenBSD: cpuswitch.S,v 1.4 2018/09/07 01:32:01 mortimer Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
*
@@ -59,6 +59,8 @@ ENTRY(cpu_switchto)
mov x1, x19
1:
+ RETGUARD_SYMBOL(cpu_switchto)
+ RETGUARD_LOAD_RANDOM(cpu_switchto, x20)
mrs x2, tpidr_el1 // load curcpu
mov w5, #SONPROC
@@ -75,6 +77,7 @@ ENTRY(cpu_switchto)
mov x0, x1
bl pmap_setttb
mov x3, x19
+ mov x15, x20
mov sp, x3
@@ -84,7 +87,9 @@ ENTRY(cpu_switchto)
ldp x25, x26, [x3, #(SF_X25)]
ldp x27, x28, [x3, #(SF_X27)]
ldp x29, x30, [x3, #(SF_X29)]
+ RETGUARD_CALC_COOKIE(x15)
add sp, sp, #(SWITCHFRAME_SZ)
+ RETGUARD_CHECK(cpu_switchto, x15)
ret
ENTRY(proc_trampoline)
diff --git a/sys/arch/arm64/arm64/support.S b/sys/arch/arm64/arm64/support.S
index 765327627ba..da4dbb74583 100644
--- a/sys/arch/arm64/arm64/support.S
+++ b/sys/arch/arm64/arm64/support.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: support.S,v 1.7 2018/08/12 17:15:10 mortimer Exp $ */
+/* $OpenBSD: support.S,v 1.8 2018/09/07 01:32:01 mortimer Exp $ */
/*-
* Copyright (c) 2014 Andrew Turner
* Copyright (c) 2014-2015 The FreeBSD Foundation
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD: head/sys/arm64/arm64/support.S 297615 2016-04-06 14:08:10Z a
#ifdef DDB
ENTRY(setjmp)
+ RETGUARD_SETUP(setjmp, x15)
/* Store the stack pointer */
mov x8, sp
str x8, [x0], #8
@@ -57,10 +58,13 @@ ENTRY(setjmp)
/* Return zero */
mov x0, #0
+ RETGUARD_CHECK(setjmp, x15)
ret
END(setjmp)
ENTRY(longjmp)
+ RETGUARD_SYMBOL(longjmp)
+ RETGUARD_LOAD_RANDOM(longjmp, x15)
/* Restore the stack pointer */
ldr x8, [x0], #8
mov sp, x8
@@ -72,9 +76,11 @@ ENTRY(longjmp)
ldp x25, x26, [x0], #16
ldp x27, x28, [x0], #16
ldp x29, lr, [x0], #16
+ RETGUARD_CALC_COOKIE(x15)
/* Return nonzero */
mov x0, #1
+ RETGUARD_CHECK(longjmp, x15)
ret
END(longjmp)
#endif
diff --git a/sys/arch/arm64/include/asm.h b/sys/arch/arm64/include/asm.h
index f31386ea4d1..874625d4430 100644
--- a/sys/arch/arm64/include/asm.h
+++ b/sys/arch/arm64/include/asm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: asm.h,v 1.4 2018/08/12 17:15:10 mortimer Exp $ */
+/* $OpenBSD: asm.h,v 1.5 2018/09/07 01:32:01 mortimer Exp $ */
/* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt Exp $ */
/*
@@ -83,23 +83,32 @@
#endif
#if defined(_RET_PROTECTOR)
+# define RETGUARD_CALC_COOKIE(reg) \
+ eor reg, reg, x30
+
+# define RETGUARD_LOAD_RANDOM(x, reg) \
+ adrp reg, __CONCAT(__retguard_, x); \
+ ldr reg, [reg, :lo12:__CONCAT(__retguard_, x)]
+
# define RETGUARD_SETUP(x, reg) \
RETGUARD_SYMBOL(x); \
- adrp reg, __CONCAT(__retguard_, x); \
- ldr reg, [reg, :lo12:__CONCAT(__retguard_, x)]; \
- eor reg, reg, x30
+ RETGUARD_LOAD_RANDOM(x, reg); \
+ RETGUARD_CALC_COOKIE(reg)
+
# define RETGUARD_CHECK(x, reg) \
- eor reg, reg, x30; \
- adrp x9, __CONCAT(__retguard_, x); \
- ldr x9, [x9, :lo12:__CONCAT(__retguard_, x)]; \
+ RETGUARD_CALC_COOKIE(reg); \
+ RETGUARD_LOAD_RANDOM(x, x9); \
subs reg, reg, x9; \
cbz reg, 66f; \
brk #0x1; \
66:
+
# define RETGUARD_PUSH(reg) \
str reg, [sp, #-16]!
+
# define RETGUARD_POP(reg) \
ldr reg, [sp, #16]!
+
# define RETGUARD_SYMBOL(x) \
.ifndef __CONCAT(__retguard_, x); \
.hidden __CONCAT(__retguard_, x); \
@@ -113,6 +122,8 @@
.popsection; \
.endif
#else
+# define RETGUARD_CALC_COOKIE(reg)
+# define RETGUARD_LOAD_RANDOM(x, reg)
# define RETGUARD_SETUP(x, reg)
# define RETGUARD_CHECK(x, reg)
# define RETGUARD_PUSH(reg)