summaryrefslogtreecommitdiff
path: root/sys/arch/powerpc
diff options
context:
space:
mode:
authorgkoehler <gkoehler@cvs.openbsd.org>2020-10-26 22:07:07 +0000
committergkoehler <gkoehler@cvs.openbsd.org>2020-10-26 22:07:07 +0000
commita483328bd79c87f28d71a25b795738756e81e7a1 (patch)
tree63abfb1f488176b616133622334001ae2b40c90a /sys/arch/powerpc
parenta8cdbdf061bb5801d09f09a43e6e0f92e895d772 (diff)
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/arch/powerpc')
-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_ */