Skip to content

Commit

Permalink
Fix assembler call frame information (CFI) directives
Browse files Browse the repository at this point in the history
Current macros emit an ENDBR instruction between the function label and
corresponding cfi_start, which confuses binary analysis tools like llvm-bolt.

Also add missing cfi_start/end directives for other assembly functions.

See also: https://sourceware.org/binutils/docs/as/CFI-directives.html

Signed-off-by: Jo Van Bulck <[email protected]>
  • Loading branch information
jovanbulck authored and lzha101 committed Jun 3, 2024
1 parent d1c3b8a commit 29321db
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion common/inc/internal/linux/linux-regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
.globl \name
.type \name, @function
\name:
.cfi_startproc
_CET_ENDBR
.endm

Expand All @@ -153,6 +154,7 @@
.hidden \name
.type \name, @function
\name:
.cfi_startproc
_CET_ENDBR
.endm

Expand Down Expand Up @@ -215,7 +217,6 @@
/*******************************************************************/

.macro SE_PROLOG
.cfi_startproc

#ifdef LINUX32
pushl %ebp
Expand Down
2 changes: 2 additions & 0 deletions common/src/linux/xsave_gnu.S
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ DECLARE_LOCAL_FUNC restore_xregs
DO_FXRSTOR
2:
ret
.cfi_endproc

DECLARE_LOCAL_FUNC save_xregs
#if defined(LINUX32)
Expand All @@ -121,4 +122,5 @@ DECLARE_LOCAL_FUNC save_xregs
DO_FXSAVE
2:
ret
.cfi_endproc

7 changes: 6 additions & 1 deletion psw/urts/linux/enter_enclave.S
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DECLARE_GLOBAL_FUNC set_xsave_info
lea_symbol g_clean_ymm, %xax
movl %edx, (%xax)
ret
.cfi_endproc

DECLARE_GLOBAL_FUNC vdso_sgx_enter_enclave_wrapper
EENTER_PROLOG
Expand Down Expand Up @@ -169,14 +170,17 @@ EENTER_PROLOG
DECLARE_GLOBAL_FUNC get_aep
lea_pic .Lasync_exit_pointer, %xax
ret
.cfi_endproc

DECLARE_GLOBAL_FUNC get_eenterp
lea_pic .Leenter_inst, %xax
ret
.cfi_endproc

DECLARE_GLOBAL_FUNC get_eretp
lea_pic .Leret, %xax
ret
.cfi_endproc

/*
* function stack_sticker is the wrapper of ocall,
Expand Down Expand Up @@ -208,7 +212,6 @@ DECLARE_GLOBAL_FUNC stack_sticker
.hidden push_ocall_frame
.type pop_ocall_frame,@function
.hidden pop_ocall_frame
.cfi_startproc
push %xbp
.cfi_def_cfa_offset 2*SE_WORDSIZE
.cfi_offset xbp,-2*SE_WORDSIZE
Expand Down Expand Up @@ -317,6 +320,7 @@ DECLARE_GLOBAL_FUNC sgx_debug_load_state_add_element
movq %rdi, (%rsi)
#endif
ret
.cfi_endproc

/*
* void sgx_debug_unload_state_remove_element(debug_enclave_info_t* enclave_info, debug_enclave_info_t** pre_enclave_info, debug_enclave_info_t* next_enclave_info)
Expand All @@ -332,6 +336,7 @@ DECLARE_GLOBAL_FUNC sgx_debug_unload_state_remove_element
movq %rdx, (%rsi)
#endif
ret
.cfi_endproc

/* We do not need executable stack.*/
.section .note.GNU-stack,"",@progbits
1 change: 0 additions & 1 deletion psw/urts/linux/enter_enclave.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ lea \symbol, \reg
/* macro for enter_enclave
*/
.macro EENTER_PROLOG
.cfi_startproc
push %xbp
.cfi_def_cfa_offset 2 * SE_WORDSIZE
.cfi_offset xbp, -2 * SE_WORDSIZE
Expand Down
2 changes: 2 additions & 0 deletions sdk/simulation/assembly/linux/lowlib.S
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
DECLARE_LOCAL_FUNC get_bp
mov %xbp, %xax
ret
.cfi_endproc

#define reg_xax (0 * SE_WORDSIZE)
#define reg_xbx (1 * SE_WORDSIZE)
Expand All @@ -62,3 +63,4 @@ DECLARE_LOCAL_FUNC load_regs
push reg_xip(%xdx)
mov reg_xdx(%xdx), %xdx
ret
.cfi_endproc
1 change: 1 addition & 0 deletions sdk/trts/linux/trts_mitigation.S
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ __ct_mitigation_end:
.global __ct_mitigation_ret
__ct_mitigation_ret:
ret
.cfi_endproc

.ct_aexnotify_end:

Expand Down
16 changes: 14 additions & 2 deletions sdk/trts/linux/trts_pic.S
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,23 @@
DECLARE_LOCAL_FUNC get_enclave_base
lea_pic __ImageBase, %xax
ret
.cfi_endproc

DECLARE_LOCAL_FUNC get_enclave_state
lea_pic g_enclave_state, %xcx
xor %xax, %xax
movl (%xcx), %eax
ret
.cfi_endproc

DECLARE_LOCAL_FUNC set_enclave_state
lea_pic g_enclave_state, %xax
#ifdef LINUX32
mov SE_WORDSIZE(%esp), %edi
#endif
movl %edi, (%xax)
ret
.cfi_endproc

DECLARE_LOCAL_FUNC lock_enclave
lea_pic g_enclave_state, %xdx
Expand All @@ -66,6 +71,7 @@ DECLARE_LOCAL_FUNC lock_enclave
mov $ENCLAVE_INIT_IN_PROGRESS, %ecx /* if (g_global_data.enclave_state == ENCLAVE_INIT_NOT_STARTED) */
lock cmpxchgl %ecx, (%xdx) /* g_global_data.enclave_state == ENCLAVE_INIT_IN_PROGRESS */
ret /* xax: the initial value of enclave state */
.cfi_endproc

/*
* ---------------------------------------------------------------------
Expand All @@ -77,6 +83,7 @@ DECLARE_LOCAL_FUNC lock_enclave
DECLARE_LOCAL_FUNC get_thread_data
READ_TD_DATA self_addr
ret
.cfi_endproc

/*
* ---------------------------------------------------------------------
Expand All @@ -88,6 +95,7 @@ DECLARE_LOCAL_FUNC get_thread_data
DECLARE_LOCAL_FUNC get_stack_guard
READ_TD_DATA stack_guard
ret
.cfi_endproc

/*
* ---------------------------------------------------------------------
Expand All @@ -113,7 +121,6 @@ DECLARE_GLOBAL_FUNC enclave_entry
* No need to use any register during the dispatch
* ----------------------------------------------------------------------
*/
.cfi_startproc

/* Clear unused general registers */
xor %xdx, %xdx
Expand Down Expand Up @@ -446,6 +453,7 @@ DECLARE_LOCAL_FUNC do_ocall
cld /* DF = 0 */

ENCLU
.cfi_endproc

/*
* ------------------------------------------------------------------
Expand All @@ -454,7 +462,6 @@ DECLARE_LOCAL_FUNC do_ocall
* ------------------------------------------------------------------
*/
DECLARE_LOCAL_FUNC __morestack
.cfi_startproc
push %xbp
.cfi_def_cfa_offset 2*SE_WORDSIZE
.cfi_offset xbp,-2*SE_WORDSIZE
Expand Down Expand Up @@ -518,6 +525,7 @@ DECLARE_GLOBAL_FUNC asm_oret
ret
/* should not come here */
ud2
.cfi_endproc

/*
* ------------------------------------------------------------------------
Expand Down Expand Up @@ -625,6 +633,7 @@ DECLARE_LOCAL_FUNC do_rdrand
movl %eax, (%xcx)
mov $1, %xax
ret
.cfi_endproc

/*
* -------------------------------------------------------------------------
Expand All @@ -635,6 +644,7 @@ DECLARE_LOCAL_FUNC abort
lea_pic g_enclave_state, %xax
movl $ENCLAVE_CRASHED, (%xax)
ud2
.cfi_endproc

/*
* -------------------------------------------------------------------------
Expand Down Expand Up @@ -692,6 +702,7 @@ DECLARE_LOCAL_FUNC continue_execution
xchg %xax, %xsp

ret $(RED_ZONE_SIZE) /* pop xip and red zone (if any) */
.cfi_endproc

/*
* -------------------------------------------------------------------------
Expand All @@ -704,4 +715,5 @@ DECLARE_LOCAL_FUNC second_phase
mov $SE_EDECCSSA, %xax
enclu /* DECCSSA */
jmp *%xdx
.cfi_endproc

2 changes: 2 additions & 0 deletions sdk/tsetjmp/_setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ DECLARE_GLOBAL_FUNC setjmp
ret
.crash:
ud2
.cfi_endproc

DECLARE_GLOBAL_FUNC longjmp
#ifdef LINUX32
Expand Down Expand Up @@ -272,6 +273,7 @@ DECLARE_GLOBAL_FUNC longjmp
jnz 1f
incl %eax
1: ret
.cfi_endproc


.weak _setjmp
Expand Down

0 comments on commit 29321db

Please sign in to comment.