summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2016-05-12 15:46:03 +0000
committerderaadt <deraadt@openbsd.org>2016-05-12 15:46:03 +0000
commit9d294f3012b8bf3b592930ba1f7a456527cf33e0 (patch)
treedf69c22952c38c0d136c79ffc6550d4e9591b0c4 /lib/libc
parentRemove bogus rw_exit() call. (diff)
downloadwireguard-openbsd-9d294f3012b8bf3b592930ba1f7a456527cf33e0.tar.xz
wireguard-openbsd-9d294f3012b8bf3b592930ba1f7a456527cf33e0.zip
Using a 3-word buffer in the openbsd.randomdata segment, XOR swizzle
the PC/FP/SP registers in the jmpbuf. An old idea (around 1999?) but the random segment sure makes it easy. Lots of help from kettenis ok kettenis
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/amd64/gen/_setjmp.S31
-rw-r--r--lib/libc/arch/amd64/gen/setjmp.S38
-rw-r--r--lib/libc/arch/amd64/gen/sigsetjmp.S32
3 files changed, 80 insertions, 21 deletions
diff --git a/lib/libc/arch/amd64/gen/_setjmp.S b/lib/libc/arch/amd64/gen/_setjmp.S
index 6895cc2717d..904828d2953 100644
--- a/lib/libc/arch/amd64/gen/_setjmp.S
+++ b/lib/libc/arch/amd64/gen/_setjmp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: _setjmp.S,v 1.2 2015/05/29 08:50:12 uebayasi Exp $ */
+/* $OpenBSD: _setjmp.S,v 1.3 2016/05/12 15:46:03 deraadt Exp $ */
/* $NetBSD: _setjmp.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */
/*
@@ -40,6 +40,8 @@
#include <machine/asm.h>
#include <machine/setjmp.h>
+ .hidden __jmpxor
+
/*
* C library -- _setjmp, _longjmp
*
@@ -52,28 +54,43 @@
ENTRY(_setjmp)
movq (%rsp),%r11
+ leaq __jmpxor(%rip),%rcx
movq %rbx,(_JB_RBX * 8)(%rdi)
- movq %rbp,(_JB_RBP * 8)(%rdi)
+ movq %rbp,%rax
+ xorq (0*8)(%rcx),%rax
+ movq %rax,(_JB_RBP * 8)(%rdi)
movq %r12,(_JB_R12 * 8)(%rdi)
movq %r13,(_JB_R13 * 8)(%rdi)
movq %r14,(_JB_R14 * 8)(%rdi)
movq %r15,(_JB_R15 * 8)(%rdi)
- movq %rsp,(_JB_RSP * 8)(%rdi)
- movq %r11,(_JB_PC * 8)(%rdi)
+ movq %rsp,%rax
+ xorq (1*8)(%rcx),%rax
+ movq %rax,(_JB_RSP * 8)(%rdi)
+ movq %r11,%rax
+ xorq (2*8)(%rcx),%rax
+ movq %rax,(_JB_PC * 8)(%rdi)
+ xorq %rcx,%rcx
- xorl %eax,%eax
+ xorq %rax,%rax
ret
END(_setjmp)
ENTRY(_longjmp)
+ leaq __jmpxor(%rip),%rcx
movq (_JB_RBX * 8)(%rdi),%rbx
- movq (_JB_RBP * 8)(%rdi),%rbp
+ movq (_JB_RBP * 8)(%rdi),%r11
+ xorq (0*8)(%rcx),%r11
+ movq %r11,%rbp
movq (_JB_R12 * 8)(%rdi),%r12
movq (_JB_R13 * 8)(%rdi),%r13
movq (_JB_R14 * 8)(%rdi),%r14
movq (_JB_R15 * 8)(%rdi),%r15
- movq (_JB_RSP * 8)(%rdi),%rsp
+ movq (_JB_RSP * 8)(%rdi),%r11
+ xorq (1*8)(%rcx),%r11
+ movq %r11,%rsp
movq (_JB_PC * 8)(%rdi),%r11
+ xorq (2*8)(%rcx),%r11
+ xorq %rcx,%rcx
movl %esi,%eax
testl %eax,%eax
diff --git a/lib/libc/arch/amd64/gen/setjmp.S b/lib/libc/arch/amd64/gen/setjmp.S
index afb9845c0c7..ecc41dba63f 100644
--- a/lib/libc/arch/amd64/gen/setjmp.S
+++ b/lib/libc/arch/amd64/gen/setjmp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: setjmp.S,v 1.5 2015/09/13 07:36:58 guenther Exp $ */
+/* $OpenBSD: setjmp.S,v 1.6 2016/05/12 15:46:03 deraadt Exp $ */
/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */
/*
@@ -40,6 +40,14 @@
#include <machine/asm.h>
#include <machine/setjmp.h>
+ .section .openbsd.randomdata,"aw",@progbits
+ .align 8
+ .globl __jmpxor
+__jmpxor:
+ .zero 8*3 # (rbp, rsp, pc)
+ END(__jmpxor)
+ .type __jmpxor,@object
+
/*
* C library -- _setjmp, _longjmp
*
@@ -58,16 +66,24 @@ ENTRY(setjmp)
movq %rax,(_JB_SIGMASK * 8)(%rdi)
movq (%rsp),%r11
+ leaq __jmpxor(%rip),%rcx
movq %rbx,(_JB_RBX * 8)(%rdi)
- movq %rbp,(_JB_RBP * 8)(%rdi)
+ movq %rbp,%rax
+ xorq (0*8)(%rcx),%rax
+ movq %rax,(_JB_RBP * 8)(%rdi)
movq %r12,(_JB_R12 * 8)(%rdi)
movq %r13,(_JB_R13 * 8)(%rdi)
movq %r14,(_JB_R14 * 8)(%rdi)
movq %r15,(_JB_R15 * 8)(%rdi)
- movq %rsp,(_JB_RSP * 8)(%rdi)
- movq %r11,(_JB_PC * 8)(%rdi)
+ movq %rsp,%rax
+ xorq (1*8)(%rcx),%rax
+ movq %rax,(_JB_RSP * 8)(%rdi)
+ movq %r11,%rax
+ xorq (2*8)(%rcx),%rax
+ movq %rax,(_JB_PC * 8)(%rdi)
+ xorq %rcx,%rcx
-2: xorl %eax,%eax
+ xorq %rax,%rax
ret
END(setjmp)
@@ -79,14 +95,22 @@ ENTRY(longjmp)
pushq %r8
call _C_LABEL(_libc_sigsetmask)
popq %r8
+
+ leaq __jmpxor(%rip),%rcx
movq (_JB_RBX * 8)(%r12),%rbx
- movq (_JB_RBP * 8)(%r12),%rbp
+ movq (_JB_RBP * 8)(%r12),%r11
+ xorq (0*8)(%rcx),%r11
+ movq %r11,%rbp
movq (_JB_R13 * 8)(%r12),%r13
movq (_JB_R14 * 8)(%r12),%r14
movq (_JB_R15 * 8)(%r12),%r15
- movq (_JB_RSP * 8)(%r12),%rsp
+ movq (_JB_RSP * 8)(%r12),%r11
+ xorq (1*8)(%rcx),%r11
+ movq %r11,%rsp
movq (_JB_PC * 8)(%r12),%r11
+ xorq (2*8)(%rcx),%r11
movq (_JB_R12 * 8)(%r12),%r12
+ xorq %rcx,%rcx
movl %r8d,%eax
testl %eax,%eax
diff --git a/lib/libc/arch/amd64/gen/sigsetjmp.S b/lib/libc/arch/amd64/gen/sigsetjmp.S
index 58a7df7958d..3983af0c0f9 100644
--- a/lib/libc/arch/amd64/gen/sigsetjmp.S
+++ b/lib/libc/arch/amd64/gen/sigsetjmp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsetjmp.S,v 1.5 2015/09/13 07:36:58 guenther Exp $ */
+/* $OpenBSD: sigsetjmp.S,v 1.6 2016/05/12 15:46:03 deraadt Exp $ */
/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */
/*
@@ -40,6 +40,8 @@
#include <machine/asm.h>
#include <machine/setjmp.h>
+ .hidden __jmpxor
+
/*
* C library -- _setjmp, _longjmp
*
@@ -62,16 +64,24 @@ ENTRY(sigsetjmp)
movq %rax,(_JB_SIGMASK * 8)(%rdi)
2: movq (%rsp),%r11
+ leaq __jmpxor(%rip),%rcx
movq %rbx,(_JB_RBX * 8)(%rdi)
- movq %rbp,(_JB_RBP * 8)(%rdi)
+ movq %rbp,%rax
+ xorq (0*8)(%rcx),%rax
+ movq %rax,(_JB_RBP * 8)(%rdi)
movq %r12,(_JB_R12 * 8)(%rdi)
movq %r13,(_JB_R13 * 8)(%rdi)
movq %r14,(_JB_R14 * 8)(%rdi)
movq %r15,(_JB_R15 * 8)(%rdi)
- movq %rsp,(_JB_RSP * 8)(%rdi)
- movq %r11,(_JB_PC * 8)(%rdi)
+ movq %rsp,%rax
+ xorq (1*8)(%rcx),%rax
+ movq %rax,(_JB_RSP * 8)(%rdi)
+ movq %r11,%rax
+ xorq (2*8)(%rcx),%rax
+ movq %rax,(_JB_PC * 8)(%rdi)
+ xorq %rcx,%rcx
-2: xorl %eax,%eax
+ xorq %rax,%rax
ret
END(sigsetjmp)
@@ -84,14 +94,22 @@ ENTRY(siglongjmp)
movq (_JB_SIGMASK * 8)(%rdi),%rdi
call _C_LABEL(_libc_sigsetmask)
2: popq %rax
+
+ leaq __jmpxor(%rip),%rcx
movq (_JB_RBX * 8)(%r12),%rbx
- movq (_JB_RBP * 8)(%r12),%rbp
+ movq (_JB_RBP * 8)(%r12),%r11
+ xorq (0*8)(%rcx),%r11
+ movq %r11,%rbp
movq (_JB_R13 * 8)(%r12),%r13
movq (_JB_R14 * 8)(%r12),%r14
movq (_JB_R15 * 8)(%r12),%r15
- movq (_JB_RSP * 8)(%r12),%rsp
+ movq (_JB_RSP * 8)(%r12),%r11
+ xorq (1*8)(%rcx),%r11
+ movq %r11,%rsp
movq (_JB_PC * 8)(%r12),%r11
+ xorq (2*8)(%rcx),%r11
movq (_JB_R12 * 8)(%r12),%r12
+ xorq %rcx,%rcx
testl %eax,%eax
jnz 1f