10000 Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S · python/cpython@d97e78d · GitHub
[go: up one dir, main page]

Skip to content

Commit d97e78d

Browse files
committed
Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S
The BTI flag must be applied in assembler sources for this class of attacks to be mitigated on newer aarch64 processors. See also: https://sourceware.org/annobin/annobin.html/Test-branch-protection.html and https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64
1 parent afa01db commit d97e78d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/asm_trampoline.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ _Py_trampoline_func_start:
1818
#if defined(__aarch64__) && defined(__AARCH64EL__) && !defined(__ILP32__)
1919
// ARM64 little endian, 64bit ABI
2020
// generate with aarch64-linux-gnu-gcc 12.1
21+
bti c
2122
stp x29, x30, [sp, -16]!
2223
mov x29, sp
2324
blr x3
@@ -53,3 +54,20 @@ _Py_trampoline_func_end:
5354
.align 8
5455
4:
5556
#endif // __x86_64__
57+
#if defined(__aarch64__) && defined(__AARCH64EL__) && !defined(__ILP32__) \
58+
&& defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
59+
.pushsection .note.gnu.property, "a"
60+
.align 3
61+
.word 2f - 1f
62+
.word 4f - 3f
63+
.word 5 /* NT_GNU_PROPERTY_TYPE_0 */
64+
1: .asciz "GNU"
65+
66+
2: .align 3
67+
3: .word 0xc0000000 /* type: GNU_PROPERTY_AARCH64_FEATURE_1_AND */
68+
.word 6f - 5f /* size */
69+
5: .word 1 /* value: GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
70+
71+
6: .align 3
72+
4: .popsection
73+
#endif

0 commit comments

Comments
 (0)
0