Skip to content

Commit 549b894

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 549b894

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Python/asm_trampoline.S

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ _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+
#if defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 || \
22+
defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
23+
hint 25
24+
#endif
2125
stp x29, x30, [sp, -16]!
2226
mov x29, sp
2327
blr x3
2428
ldp x29, x30, [sp], 16
29+
#if defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 || \
30+
defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
31+
hint 29
32+
#endif
2533
ret
2634
#endif
2735
#ifdef __riscv
@@ -53,3 +61,22 @@ _Py_trampoline_func_end:
5361
.align 8
5462
4:
5563
#endif // __x86_64__
64+
#if defined(__aarch64__) && defined(__AARCH64EL__) && !defined(__ILP32__)
65+
#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1 || \
66+
defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT & 1) == 1
67+
.pushsection .note.gnu.property, "a"
68+
.align 3
69+
.word 2f - 1f
70+
.word 4f - 3f
71+
.word 5 /* NT_GNU_PROPERTY_TYPE_0 */
72+
1: .asciz "GNU"
73+
74+
2: .align 3
75+
3: .word 0xc0000000 /* type: GNU_PROPERTY_AARCH64_FEATURE_1_AND */
76+
.word 6f - 5f /* size */
77+
5: .word 3 /* value: GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
78+
79+
6: .align 3
80+
4: .popsection
81+
#endif
82+
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy