diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2018-02-24 17:28:04 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2018-02-24 17:59:37 -0800 |
commit | a7112c51e026d3d99aa4f22ecd6c89310ae506f1 (patch) | |
tree | 2263ea48ac8a9ad32c1228e20f37badbce2fca47 | |
parent | 84860fa73aa9146febe450d2cb28511db5558f23 (diff) | |
download | glibc-hjl/setjmp/pad.tar.gz |
x86-64: Check if shadow stack register can be preservedhjl/setjmp/pad
Store (int64_t) -1 as shadow stack register in x86-64 setjmp and read
it back in x86-64 longjmp to verify that it is unchanged.
-rw-r--r-- | sysdeps/x86_64/__longjmp.S | 9 | ||||
-rw-r--r-- | sysdeps/x86_64/setjmp.S | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/sysdeps/x86_64/__longjmp.S b/sysdeps/x86_64/__longjmp.S index a487e0efd0..642f6f81fc 100644 --- a/sysdeps/x86_64/__longjmp.S +++ b/sysdeps/x86_64/__longjmp.S @@ -17,6 +17,7 @@ #include <sysdep.h> #include <jmpbuf-offsets.h> +#include <jmp_buf-ssp.h> #include <asm-syntax.h> #include <stap-probe.h> @@ -25,6 +26,11 @@ void __longjmp (__jmp_buf env, int val). */ .text ENTRY(__longjmp) + /* Verify that shadow stack field isn't changed by struct + pthread_unwind_buf. */ + cmpq $-1, SHADOW_STACK_POINTER_OFFSET(%rdi) + jnz L(hlt) + /* Restore registers. */ mov (JB_RSP*8)(%rdi),%R8_LP mov (JB_RBP*8)(%rdi),%R9_LP @@ -65,4 +71,7 @@ ENTRY(__longjmp) LIBC_PROBE (longjmp_target, 3, LP_SIZE@%RDI_LP, -4@%eax, LP_SIZE@%RDX_LP) jmpq *%rdx + +L(hlt): + hlt END (__longjmp) diff --git a/sysdeps/x86_64/setjmp.S b/sysdeps/x86_64/setjmp.S index e0a648e3e4..c15bbf8b33 100644 --- a/sysdeps/x86_64/setjmp.S +++ b/sysdeps/x86_64/setjmp.S @@ -18,6 +18,7 @@ #include <sysdep.h> #include <jmpbuf-offsets.h> +#include <jmp_buf-ssp.h> #include <asm-syntax.h> #include <stap-probe.h> @@ -54,6 +55,10 @@ ENTRY (__sigsetjmp) #endif movq %rax, (JB_PC*8)(%rdi) + /* Set shadow stack field to see if it works with struct + pthread_unwind_buf. */ + movq $-1, SHADOW_STACK_POINTER_OFFSET(%rdi) + #if IS_IN (rtld) /* In ld.so we never save the signal mask. */ xorl %eax, %eax |