Enable PA and BTI for breakpad

Introduces Arm's Pointer Authentication and Branch Target Identification
to breakpad.

The changes are similar to changes for PA/BTI to Marl, see
https://github.com/google/marl/pull/204

Bug: 1145581
Change-Id: I6a770316ad333bfcfad2ce7f3c1ff78afb35c010
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3226471
Reviewed-by: Primiano Tucci <primiano@chromium.org>
This commit is contained in:
André Kempe 2021-10-15 17:20:23 +01:00 committed by Primiano Tucci
parent 54d878abcb
commit 076073c96b

View File

@ -90,6 +90,47 @@ breakpad_getcontext:
#elif defined(__aarch64__)
#if defined(__ARM_FEATURE_PAC_DEFAULT) && __ARM_FEATURE_PAC_DEFAULT
// ENABLE_PAUTH must be defined to 1 since this value will be used in
// bitwise-shift later!
#define ENABLE_PAUTH 1
#if ((__ARM_FEATURE_PAC_DEFAULT&((1<<0)|(1<<1)))==0)
#error Pointer authentication defines no valid key!
#endif
#else
#define ENABLE_PAUTH 0
#endif
#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT==1)
// ENABLE_BTI must be defined to 1 since this value will be used in
// bitwise-shift later!
#define ENABLE_BTI 1
#else
#define ENABLE_BTI 0
#endif
// Although Pointer Authentication and Branch Target Instructions are technically
// seperate features they work together, i.e. the paciasp and pacibsp instructions
// serve as BTI landing pads.
// Therefore PA-instructions are enabled when PA _or_ BTI is enabled!
#if ENABLE_PAUTH || ENABLE_BTI
// See section "Pointer Authentication" of
// https://developer.arm.com/documentation/101028/0012/5--Feature-test-macros
// for details how to interpret __ARM_FEATURE_PAC_DEFAULT
#if (__ARM_FEATURE_PAC_DEFAULT & (1<<0))
#define PAUTH_SIGN_SP paciasp
#define PAUTH_AUTH_SP autiasp
#else
#define PAUTH_SIGN_SP pacibsp
#define PAUTH_AUTH_SP autibsp
#endif
#else
#define PAUTH_SIGN_SP
#define PAUTH_AUTH_SP
#endif
#define _NSIG 64
#define __NR_rt_sigprocmask 135
@ -101,6 +142,8 @@ breakpad_getcontext:
.cfi_startproc
breakpad_getcontext:
PAUTH_SIGN_SP
/* The saved context will return to the getcontext() call point
with a return value of 0 */
str xzr, [x0, MCONTEXT_GREGS_OFFSET + 0 * REGISTER_SIZE]
@ -170,6 +213,9 @@ breakpad_getcontext:
/* Return x0 for success */
mov x0, 0
PAUTH_AUTH_SP
ret
.cfi_endproc
@ -484,3 +530,23 @@ breakpad_getcontext:
#else
#error "This file has not been ported for your CPU!"
#endif
#if defined(__aarch64__)
// ENABLE_PAUTH and ENABLE_BTI would be enabled at the definition
// of AArch64 specific breakpad_getcontext function
#if ENABLE_PAUTH || ENABLE_BTI
// for further information on the .note.gnu.property section see
// https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#program-property
.pushsection .note.gnu.property, "a";
.balign 8
.long 4
.long 0x10
.long 0x5
.asciz "GNU"
.long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
.long 4
.long ((ENABLE_PAUTH)<<1) | ((ENABLE_BTI)<<0) /* PAuth and BTI */
.long 0
.popsection
#endif
#endif