diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 15:19:34 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 15:20:08 +0000 |
commit | 72b2e72dc0f0bcc64f3a91f1e1d5986c186b7880 (patch) | |
tree | f9e635b447789995362b8aca162ad6d855bb28c2 /sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | |
parent | 2838aa1289bec5055c33d2c00bfe6e3ed3d52e0f (diff) | |
parent | 9f9bd6ac848e9acee2c1072cdb14955c1abb8725 (diff) |
Merge commit 'refs/top-bases/t/UTIME' into t/UTIME
Diffstat (limited to 'sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S')
-rw-r--r-- | sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S index fca9dc08e2..5d2d275721 100644 --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2016 Free Software Foundation, Inc. +/* Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -19,8 +19,13 @@ #include <jmpbuf-offsets.h> #include <asm-syntax.h> #include <stap-probe.h> - #include <sigaltstack-offsets.h> +#include <jmp_buf-ssp.h> + +/* Don't restore shadow stack register if shadow stack isn't enabled. */ +#if !SHSTK_ENABLED +# undef SHADOW_STACK_POINTER_OFFSET +#endif .section .rodata.str1.1,"aMS",@progbits,1 .type longjmp_msg,@object @@ -105,6 +110,38 @@ ENTRY(____longjmp_chk) cfi_restore (%rsi) .Lok: +#ifdef SHADOW_STACK_POINTER_OFFSET +# if IS_IN (libc) && defined SHARED && defined FEATURE_1_OFFSET + /* Check if Shadow Stack is enabled. */ + testl $X86_FEATURE_1_SHSTK, %fs:FEATURE_1_OFFSET + jz L(skip_ssp) +# else + xorl %eax, %eax +# endif + /* Check and adjust the Shadow-Stack-Pointer. */ + rdsspq %rax + /* And compare it with the saved ssp value. */ + subq SHADOW_STACK_POINTER_OFFSET(%rdi), %rax + je L(skip_ssp) + /* Count the number of frames to adjust and adjust it + with incssp instruction. The instruction can adjust + the ssp by [0..255] value only thus use a loop if + the number of frames is bigger than 255. */ + negq %rax + shrq $3, %rax + /* NB: We saved Shadow-Stack-Pointer of setjmp. Since we are + restoring Shadow-Stack-Pointer of setjmp's caller, we + need to unwind shadow stack by one more frame. */ + addq $1, %rax + movl $255, %ebx +L(loop): + cmpq %rbx, %rax + cmovb %rax, %rbx + incsspq %rbx + subq %rbx, %rax + ja L(loop) +L(skip_ssp): +#endif LIBC_PROBE (longjmp, 3, LP_SIZE@%RDI_LP, -4@%esi, LP_SIZE@%RDX_LP) /* We add unwind information for the target here. */ cfi_def_cfa(%rdi, 0) |