summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorgkoehler <gkoehler@openbsd.org>2020-10-26 22:07:05 +0000
committergkoehler <gkoehler@openbsd.org>2020-10-26 22:07:05 +0000
commitd2c5a4743fb945f45b034a3a830a96f7e1bc695d (patch)
tree8c745f80cf672d3f13c743ba003723f26271fba9 /sys
parentMake mapping the "I/O Space" BAR optional. POWER9 systems don't support (diff)
downloadwireguard-openbsd-d2c5a4743fb945f45b034a3a830a96f7e1bc695d.tar.xz
wireguard-openbsd-d2c5a4743fb945f45b034a3a830a96f7e1bc695d.zip
Retguard asm macros for powerpc libc, ld.so
Add retguard to some, but not all, asm functions in libc. Edit SYS.h in libc to remove the PREFIX macros and add SYSENTRY (more like aarch64 and powerpc64), so we can insert RETGUARD_SETUP after SYSENTRY. Some .S files in this commit don't get retguard, but do stop using the old prefix macros. Tested by deraadt@, who put this diff in a macppc snap.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/powerpc/include/asm.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/sys/arch/powerpc/include/asm.h b/sys/arch/powerpc/include/asm.h
index 467c8724c29..60fbac38f17 100644
--- a/sys/arch/powerpc/include/asm.h
+++ b/sys/arch/powerpc/include/asm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: asm.h,v 1.14 2017/06/29 17:36:16 deraadt Exp $ */
+/* $OpenBSD: asm.h,v 1.15 2020/10/26 22:07:06 gkoehler Exp $ */
/* $NetBSD: asm.h,v 1.1 1996/09/30 16:34:20 ws Exp $ */
/*
@@ -97,4 +97,45 @@ _TMP_LABEL(y):; \
#define WEAK_ALIAS(alias,sym) \
.weak alias; .set alias,sym
+#if defined(_RET_PROTECTOR)
+# if defined(__PIC__)
+# define RETGUARD_LOAD_RANDOM(x, reg) \
+ bcl 20, 31, 66f; \
+66: mflr reg; \
+ addis reg, reg, (__retguard_ ## x - 66b)@ha; \
+ lwz reg, ((__retguard_ ## x - 66b)@l)(reg)
+# else
+# define RETGUARD_LOAD_RANDOM(x, reg) \
+ lis reg, (__retguard_ ## x)@ha; \
+ lwz reg, ((__retguard_ ## x)@l)(reg)
+# endif
+# define RETGUARD_SETUP(x) \
+ RETGUARD_SYMBOL(x); \
+ mflr %r12; \
+ RETGUARD_LOAD_RANDOM(x, %r11); \
+ xor %r11, %r11, %r12
+# define RETGUARD_CHECK(x) \
+ xor %r11, %r11, %r12; \
+ RETGUARD_LOAD_RANDOM(x, %r10); \
+ mtlr %r12; \
+ twne %r11, %r10
+# define RETGUARD_SYMBOL(x) \
+ .ifndef __retguard_ ## x; \
+ .hidden __retguard_ ## x; \
+ .type __retguard_ ## x,@object; \
+ .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \
+ .weak __retguard_ ## x; \
+ .p2align 2; \
+ __retguard_ ## x: ; \
+ .long 0; \
+ .size __retguard_ ## x, 4; \
+ .popsection; \
+ .endif
+#else
+# define RETGUARD_LOAD_RANDOM(x, reg)
+# define RETGUARD_SETUP(x)
+# define RETGUARD_CHECK(x)
+# define RETGUARD_SYMBOL(x)
+#endif
+
#endif /* !_POWERPC_ASM_H_ */