cases in kernel and libc.
ok deraadt@
-/* $OpenBSD: byte_swap_2.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */
+/* $OpenBSD: byte_swap_2.S,v 1.2 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: byte_swap_2.S,v 1.3 2003/04/05 23:08:51 bjh21 Exp $ */
/*-
_ENTRY(_C_LABEL(ntohs))
_ENTRY(_C_LABEL(htons))
_PROF_PROLOGUE
+ RETGUARD_SETUP(__bswap16, x15)
and w8, w0, #0xffff
ubfx w0, w0, #8, #8
bfi w0, w8, #8, #16
+ RETGUARD_CHECK(__bswap16, x15)
ret
-/* $OpenBSD: byte_swap_4.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */
+/* $OpenBSD: byte_swap_4.S,v 1.2 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: byte_swap_4.S,v 1.2 2003/04/05 23:08:51 bjh21 Exp $ */
/*-
_ENTRY(_C_LABEL(ntohl))
_ENTRY(_C_LABEL(htonl))
_PROF_PROLOGUE
+ RETGUARD_SETUP(__bswap32, x15)
rev w0, w0
+ RETGUARD_CHECK(__bswap32, x15)
ret
-/* $OpenBSD: Ovfork.S,v 1.3 2017/11/22 20:36:02 kettenis Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.4 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: Ovfork.S,v 1.6 2003/08/07 16:42:03 agc Exp $ */
/*-
#include "SYS.h"
SYSENTRY_HIDDEN(vfork)
+ RETGUARD_SETUP(vfork, x15)
mov x2, x30
SYSTRAP(vfork)
bcs CERROR
mov x30, x2
+ RETGUARD_CHECK(vfork, x15)
ret
SYSCALL_END_HIDDEN(vfork)
-/* $OpenBSD: brk.S,v 1.4 2017/11/22 20:36:02 kettenis Exp $ */
+/* $OpenBSD: brk.S,v 1.5 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: brk.S,v 1.7 2003/12/26 11:23:44 martin Exp $ */
/*-
* Change the data segment size
*/
ENTRY(brk)
+ RETGUARD_SETUP(brk, x15)
#ifdef __PIC__
/* Setup the GOT */
adrp x3, :got:__minbrk
/* Return 0 for success */
mov x0, #0x00000000
+ RETGUARD_CHECK(brk, x15)
ret
.align 3
-/* $OpenBSD: cerror.S,v 1.4 2017/03/19 00:29:02 guenther Exp $ */
+/* $OpenBSD: cerror.S,v 1.5 2018/08/12 17:15:10 mortimer Exp $ */
/*-
* Copyright (c) 2014 Andrew Turner
* All rights reserved.
#define TCB_OFFSET_ERRNO (-12)
_ENTRY(CERROR)
+ RETGUARD_SETUP(CERROR, x15)
mrs x1, tpidr_el0
str w0, [x1, #TCB_OFFSET_ERRNO]
movn x0, #0
+ RETGUARD_CHECK(CERROR, x15)
ret
END(CERROR)
-/* $OpenBSD: sbrk.S,v 1.3 2017/11/22 20:36:02 kettenis Exp $ */
+/* $OpenBSD: sbrk.S,v 1.4 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: sbrk.S,v 1.7 2003/08/07 16:42:05 agc Exp $ */
/*-
* Change the data segment size
*/
ENTRY(sbrk)
+ RETGUARD_SETUP(sbrk, x15)
#ifdef __PIC__
/* Setup the GOT */
adrp x3, :got:__curbrk
str x1, [x2]
/* Return old curbrk value */
+ RETGUARD_CHECK(sbrk, x15)
ret
.align 3
-/* $OpenBSD: sigpending.S,v 1.2 2017/02/23 22:50:07 patrick Exp $ */
+/* $OpenBSD: sigpending.S,v 1.3 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: sigpending.S,v 1.5 2003/08/07 16:42:05 agc Exp $ */
/*-
#include "SYS.h"
SYSENTRY(sigpending)
+ RETGUARD_SETUP(sigpending, x15)
mov x2, x0
SYSTRAP(sigpending)
bcs CERROR
str w0, [x2]
mov x0, #0
+ RETGUARD_CHECK(sigpending, x15)
ret
SYSCALL_END(sigpending)
-/* $OpenBSD: sigprocmask.S,v 1.2 2017/02/22 22:18:51 patrick Exp $ */
+/* $OpenBSD: sigprocmask.S,v 1.3 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: sigprocmask.S,v 1.5 2003/08/07 16:42:05 agc Exp $ */
/*-
#include "SYS.h"
SYSENTRY_HIDDEN(sigprocmask)
+ RETGUARD_SETUP(sigprocmask, x15)
cbz x1, 1f
ldr w1, [x1]
b 2f
str w0, [x2]
1:
mov x0, #0x00000000
+ RETGUARD_CHECK(sigprocmask, x15)
ret
SYSCALL_END_HIDDEN(sigprocmask)
-/* $OpenBSD: sigsuspend.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.2 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: sigsuspend.S,v 1.6 2003/08/07 16:42:05 agc Exp $ */
/*-
#include "SYS.h"
SYSENTRY_HIDDEN(sigsuspend)
+ RETGUARD_SETUP(sigsuspend, x15)
ldr w0, [x0]
SYSTRAP(sigsuspend)
bcs CERROR
mov x0, #0
+ RETGUARD_CHECK(sigsuspend, x15)
ret
SYSCALL_END_HIDDEN(sigsuspend)
-/* $OpenBSD: tfork_thread.S,v 1.2 2017/02/20 08:42:46 patrick Exp $ */
+/* $OpenBSD: tfork_thread.S,v 1.3 2018/08/12 17:15:10 mortimer Exp $ */
/*
* Copyright (c) 2005 Dale Rahn <drahn@openbsd.org>
*
*/
ENTRY(__tfork_thread)
+ RETGUARD_SETUP(__tfork_thread, x15)
SYSTRAP(__tfork)
bcs CERROR
/* check if we are parent or child */
cbz x0, 1f
+ RETGUARD_CHECK(__tfork_thread, x15)
ret
1:
-/* $OpenBSD: copy.S,v 1.4 2017/12/30 10:20:34 kettenis Exp $ */
+/* $OpenBSD: copy.S,v 1.5 2018/08/12 17:15:10 mortimer Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
* XXX should this assert that address spaces are correct for each address?
*/
ENTRY(copyin)
+ RETGUARD_SETUP(copy, x15)
cbnz x2, 1f
mov x0, 0
+ RETGUARD_CHECK(copy, x15)
ret
1:
mrs x3, tpidr_el1 // load cpuinfo
str x4, [x3, #(PCB_ONFAULT)] // clear handler
mov x0, xzr
+ RETGUARD_CHECK(copy, x15)
ret
.Lcopyfault:
mov x0, #EFAULT
ldr x4, [x3, #(PCB_ONFAULT)]
+ RETGUARD_CHECK(copy, x15)
ret
/*
* XXX should this assert that address spaces are correct for each address?
*/
ENTRY(copyin32)
+ RETGUARD_SETUP(copy, x15)
mrs x3, tpidr_el1 // load cpuinfo
ldr x3, [x3, #(CI_CURPCB)]
ldr x4, [x3, #(PCB_ONFAULT)]
str x4, [x3, #(PCB_ONFAULT)] // clear handler
mov x0, xzr
+ RETGUARD_CHECK(copy, x15)
ret
/*
*/
ENTRY(copyout)
+ RETGUARD_SETUP(copy, x15)
cbnz x2, 1f
mov x0, 0
+ RETGUARD_CHECK(copy, x15)
ret
1:
mrs x3, tpidr_el1 // load cpuinfo
str x4, [x3, #(PCB_ONFAULT)] // clear handler
mov x0, xzr
+ RETGUARD_CHECK(copy, x15)
ret
/*
*/
ENTRY(kcopy)
+ RETGUARD_SETUP(copy, x15)
cbnz x2, 1f
mov x0, 0
+ RETGUARD_CHECK(copy, x15)
ret
1:
mrs x3, tpidr_el1 // load cpuinfo
str x4, [x3, #(PCB_ONFAULT)] // clear handler
mov x0, xzr
+ RETGUARD_CHECK(copy, x15)
ret
-/* $OpenBSD: copystr.S,v 1.3 2017/02/15 21:39:50 patrick Exp $ */
+/* $OpenBSD: copystr.S,v 1.4 2018/08/12 17:15:10 mortimer Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
* Copy string from x0 to x1
*/
ENTRY(copystr)
+ RETGUARD_SETUP(copystr, x15)
mrs x6, tpidr_el1 // load curcpu
ldr x6, [x6, #(CI_CURPCB)]
ldr x5, [x6, #(PCB_ONFAULT)]
str x8, [x3]
2:
str x5, [x6, #(PCB_ONFAULT)]
+ RETGUARD_CHECK(copystr, x15)
ret
/*
* Copy string from user space to kernel space
*/
ENTRY(copyinstr)
+ RETGUARD_SETUP(copystr, x15)
mrs x6, tpidr_el1 // load curcpu
ldr x6, [x6, #(CI_CURPCB)]
ldr x5, [x6, #(PCB_ONFAULT)]
* Copy string from kernel space to user space
*/
ENTRY(copyoutstr)
+ RETGUARD_SETUP(copystr, x15)
mrs x6, tpidr_el1 // load curcpu
ldr x6, [x6, #(CI_CURPCB)]
ldr x5, [x6, #(PCB_ONFAULT)]
-/* $OpenBSD: cpufunc_asm.S,v 1.4 2018/01/10 23:27:18 kettenis Exp $ */
+/* $OpenBSD: cpufunc_asm.S,v 1.5 2018/08/12 17:15:10 mortimer Exp $ */
/*-
* Copyright (c) 2014 Robin Randhawa
* Copyright (c) 2015 The FreeBSD Foundation
.if \ic != 0
isb
.endif
- ret
.endm
/*
*/
ENTRY(cpu_setttb)
+ RETGUARD_SETUP(cpu_setttb, x15)
mrs x2, ttbr1_el1
bfi x2, x0, #48, #16
msr ttbr1_el1, x2
isb
msr ttbr0_el1, x1
isb
+ RETGUARD_CHECK(cpu_setttb, x15)
ret
END(cpu_setttb)
ENTRY(cpu_tlb_flush)
+ RETGUARD_SETUP(cpu_tlb_flush, x15)
dsb ishst
tlbi vmalle1is
dsb ish
isb
+ RETGUARD_CHECK(cpu_tlb_flush, x15)
ret
END(cpu_tlb_flush)
ENTRY(cpu_tlb_flush_asid)
+ RETGUARD_SETUP(cpu_tlb_flush_asid, x15)
dsb ishst
tlbi vae1is, x0
dsb ish
isb
+ RETGUARD_CHECK(cpu_tlb_flush_asid, x15)
ret
END(cpu_tlb_flush_asid)
ENTRY(cpu_tlb_flush_all_asid)
+ RETGUARD_SETUP(cpu_tlb_flush_all_asid, x15)
dsb ishst
tlbi vaale1is, x0
dsb ish
isb
+ RETGUARD_CHECK(cpu_tlb_flush_all_asid, x15)
ret
END(cpu_tlb_flush_all_asid)
ENTRY(cpu_tlb_flush_asid_all)
+ RETGUARD_SETUP(cpu_tlb_flush_asid_all, x15)
dsb ishst
tlbi aside1is, x0
dsb ish
isb
+ RETGUARD_CHECK(cpu_tlb_flush_asid_all, x15)
ret
END(cpu_tlb_flush_asid_all)
* void cpu_dcache_wb_range(vaddr_t, vsize_t)
*/
ENTRY(cpu_dcache_wb_range)
+ RETGUARD_SETUP(cpu_dcache_wb_range, x15)
cache_handle_range dcop = cvac
+ RETGUARD_CHECK(cpu_dcache_wb_range, x15)
+ ret
END(cpu_dcache_wb_range)
/*
* void cpu_dcache_wbinv_range(vaddr_t, vsize_t)
*/
ENTRY(cpu_dcache_wbinv_range)
+ RETGUARD_SETUP(cpu_dcache_wbinv_range, x15)
cache_handle_range dcop = civac
+ RETGUARD_CHECK(cpu_dcache_wbinv_range, x15)
+ ret
END(cpu_dcache_wbinv_range)
/*
* must use wb-inv of the entire cache.
*/
ENTRY(cpu_dcache_inv_range)
+ RETGUARD_SETUP(cpu_dcache_inv_range, x15)
cache_handle_range dcop = ivac
+ RETGUARD_CHECK(cpu_dcache_inv_range, x15)
+ ret
END(cpu_dcache_inv_range)
/*
* void cpu_idcache_wbinv_range(vaddr_t, vsize_t)
*/
ENTRY(cpu_idcache_wbinv_range)
+ RETGUARD_SETUP(cpu_idcache_wbinv_range, x15)
cache_handle_range dcop = civac, ic = 1, icop = ivau
+ RETGUARD_CHECK(cpu_idcache_wbinv_range, x15)
+ ret
END(cpu_idcache_wbinv_range)
/*
* void cpu_icache_sync_range(vaddr_t, vsize_t)
*/
ENTRY(cpu_icache_sync_range)
+ RETGUARD_SETUP(cpu_icache_sync_range, x15)
cache_handle_range dcop = cvau, ic = 1, icop = ivau
+ RETGUARD_CHECK(cpu_icache_sync_range, x15)
+ ret
END(cpu_icache_sync_range)
-/* $OpenBSD: support.S,v 1.6 2017/08/09 03:06:55 jsg Exp $ */
+/* $OpenBSD: support.S,v 1.7 2018/08/12 17:15:10 mortimer Exp $ */
/*-
* Copyright (c) 2014 Andrew Turner
* Copyright (c) 2014-2015 The FreeBSD Foundation
* pagezero, simple implementation
*/
ENTRY(pagezero_simple)
+ RETGUARD_SETUP(pagezero_simple, x15)
add x1, x0, #PAGE_SIZE
1:
stp xzr, xzr, [x0], #0x10
cmp x0, x1
b.ne 1b
+ RETGUARD_CHECK(pagezero_simple, x15)
ret
END(pagezero_simple)
* pagezero, cache assisted
*/
ENTRY(pagezero_cache)
+ RETGUARD_SETUP(pagezero_cache, x15)
add x1, x0, #PAGE_SIZE
ldr x2, =dczva_line_size
add x0, x0, x2
cmp x0, x1
b.ne 1b
+ RETGUARD_CHECK(pagezero_cache, x15)
ret
END(pagezero_cache)
-/* $OpenBSD: asm.h,v 1.3 2017/06/29 17:36:16 deraadt Exp $ */
+/* $OpenBSD: asm.h,v 1.4 2018/08/12 17:15:10 mortimer Exp $ */
/* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt Exp $ */
/*
# define _PROF_PROLOGUE
#endif
+#if defined(_RET_PROTECTOR)
+# define RETGUARD_SETUP(x, reg) \
+ RETGUARD_SYMBOL(x); \
+ adrp reg, __CONCAT(__retguard_, x); \
+ ldr reg, [reg, :lo12:__CONCAT(__retguard_, x)]; \
+ eor reg, reg, x30
+# define RETGUARD_CHECK(x, reg) \
+ eor reg, reg, x30; \
+ adrp x9, __CONCAT(__retguard_, x); \
+ ldr x9, [x9, :lo12:__CONCAT(__retguard_, x)]; \
+ 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); \
+ .type __CONCAT(__retguard_, x),@object; \
+ .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \
+ .weak __CONCAT(__retguard_, x); \
+ .p2align 3; \
+ __CONCAT(__retguard_, x): ; \
+ .xword 0; \
+ .size __CONCAT(__retguard_, x), 8; \
+ .popsection; \
+ .endif
+#else
+# define RETGUARD_SETUP(x, reg)
+# define RETGUARD_CHECK(x, reg)
+# define RETGUARD_PUSH(reg)
+# define RETGUARD_POP(reg)
+# define RETGUARD_SYMBOL(x)
+#endif
+
#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
#define ENTRY_NP(y) _ENTRY(_C_LABEL(y))
#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE