Skip to content

Commit

Permalink
Add support for Indirect Branch Tracking (IBT)
Browse files Browse the repository at this point in the history
Indirect Branch Tracking(IBT) is part of Intel's Control-Flow
Enforcement Technology(CET). IBT is hardware based, forward edge
Control-Flow-Integrity mechanism where any indirect CALL/JMP must
target an ENDBR instruction or suffer #CP.

This commit inserts endbr64 instruction in assembly to support IBT.
  • Loading branch information
PeterYang12 authored and sdp committed May 16, 2022
1 parent fb8cda1 commit b62a991
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/asm/jump_x86_64_sysv_elf_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# else
# define _CET_ENDBR
# endif
.file "jump_x86_64_sysv_elf_gas.S"
.text
.globl jump_fcontext
.type jump_fcontext,@function
.align 16
jump_fcontext:
_CET_ENDBR
leaq -0x38(%rsp), %rsp /* prepare stack */

#if !defined(BOOST_USE_TSX)
Expand Down
9 changes: 8 additions & 1 deletion src/asm/make_x86_64_sysv_elf_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# else
# define _CET_ENDBR
# endif
.file "make_x86_64_sysv_elf_gas.S"
.text
.globl make_fcontext
.type make_fcontext,@function
.align 16
make_fcontext:
_CET_ENDBR
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax

Expand Down Expand Up @@ -64,13 +69,15 @@ make_fcontext:
ret /* return pointer to context-data */

trampoline:
_CET_ENDBR
/* store return address on stack */
/* fix stack alignment */
push %rbp
/* jump to context-function */
jmp *%rbx

finish:
_CET_ENDBR
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
Expand Down
7 changes: 6 additions & 1 deletion src/asm/ontop_x86_64_sysv_elf_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# else
# define _CET_ENDBR
# endif
.file "ontop_x86_64_sysv_elf_gas.S"
.text
.globl ontop_fcontext
.type ontop_fcontext,@function
.align 16
ontop_fcontext:
_CET_ENDBR
/* preserve ontop-function in R8 */
movq %rdx, %r8

Expand Down

0 comments on commit b62a991

Please sign in to comment.