8000 Apply Intel Control-flow Technology for x86-64 on asm_trampoline.S · python/cpython@dfcb630 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfcb630

Browse files
committed
Apply Intel Control-flow Technology for x86-64 on asm_trampoline.S
Intel's Control-flow Technology requires manual application for the assembler files. See also: https://sourceware.org/annobin/annobin.html/Test-cf-protection.html
1 parent 7380186 commit dfcb630

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Python/asm_trampoline.S

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# }
1010
_Py_trampoline_func_start:
1111
#ifdef __x86_64__
12+
#if defined(__CET__) && (__CET__ & 1)
13+
endbr64
14+
#endif
1215
sub $8, %rsp
1316
call *%rcx
1417
add $8, %rsp
@@ -34,3 +37,21 @@ _Py_trampoline_func_start:
3437
.globl _Py_trampoline_func_end
3538
_Py_trampoline_func_end:
3639
.section .note.GNU-stack,"",@progbits
40+
#if defined(__x86_64__) && defined(__CET__) && (__CET__ & 1)
41+
.section .note.gnu.property,"a"
42< 8000 /td>+
.align 8
43+
.long 1f - 0f
44+
.long 4f - 1f
45+
.long 5
46+
0:
47+
.string "GNU"
48+
1:
49+
.align 8
50+
.long 0xc0000002
51+
.long 3f - 2f
52+
2:
53+
.long 0x3
54+
3:
55+
.align 8
56+
4:
57+
#endif // __x86_64__

Python/perf_jit_trampoline.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,11 @@ elf_init_ehframe(ELFObjectContext* ctx)
472472
DWRF_U8(0); /* Augmentation data. */
473473
/* Registers saved in CFRAME. */
474474
#ifdef __x86_64__
475+
# if defined(__CET__) && (__CET__ & 1)
476+
DWRF_U8(DWRF_CFA_advance_loc | 8);
477+
# else
475478
DWRF_U8(DWRF_CFA_advance_loc | 4);
479+
# endif
476480
DWRF_U8(DWRF_CFA_def_cfa_offset); DWRF_UV(16);
477481
DWRF_U8(DWRF_CFA_advance_loc | 6);
478482
DWRF_U8(DWRF_CFA_def_cfa_offset); DWRF_UV(8);

0 commit comments

Comments
 (0)
0