Skip to content

Commit

Permalink
Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stratakis committed Jan 9, 2025
1 parent afa01db commit 6d86e0f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Python/asm_trampoline.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ _Py_trampoline_func_start:
#if defined(__aarch64__) && defined(__AARCH64EL__) && !defined(__ILP32__)
// ARM64 little endian, 64bit ABI
// generate with aarch64-linux-gnu-gcc 12.1
#if defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 || \
defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
hint 25
#endif
stp x29, x30, [sp, -16]!
mov x29, sp
blr x3
ldp x29, x30, [sp], 16
#if defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 || \
defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
hint 29
#endif
ret
#endif
#ifdef __riscv
Expand Down Expand Up @@ -53,3 +61,22 @@ _Py_trampoline_func_end:
.align 8
4:
#endif // __x86_64__
#if defined(__aarch64__) && defined(__AARCH64EL__) && !defined(__ILP32__)
#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1 ||

Check failure on line 65 in Python/asm_trampoline.S

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-aarch64)

operator '||' has no right operand
defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT & 1) == 1
.pushsection .note.gnu.property, "a"
.align 3
.word 2f - 1f
.word 4f - 3f
.word 5 /* NT_GNU_PROPERTY_TYPE_0 */
1: .asciz "GNU"

2: .align 3
3: .word 0xc0000000 /* type: GNU_PROPERTY_AARCH64_FEATURE_1_AND */
.word 6f - 5f /* size */
5: .word 3 /* value: GNU_PROPERTY_AARCH64_FEATURE_1_BTI */

6: .align 3
4: .popsection
#endif
#endif

0 comments on commit 6d86e0f

Please sign in to comment.