Skip to content

Commit 5c0e448

Browse files
committed
Address comments
1 parent ad625da commit 5c0e448

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef SANITIZER_PTRAUTH_H
1010
#define SANITIZER_PTRAUTH_H
1111

12-
#if __has_feature(ptrauth_calls)
12+
#if __has_feature(ptrauth_intrinsics)
1313
# include <ptrauth.h>
1414
#elif defined(__ARM_FEATURE_PAC_DEFAULT) && !defined(__APPLE__)
1515
// On the stack the link register is protected with Pointer

libcxxabi/src/cxa_exception.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
4747
// In Wasm, a destructor returns its argument
4848
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
4949
#else
50-
void(_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor exceptionDestructor)(void*);
50+
void(_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void*);
5151
#endif
5252
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
5353
std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
@@ -61,10 +61,10 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
6161
int propagationCount;
6262
#else
6363
int handlerSwitchValue;
64-
const unsigned char* __ptrauth_cxxabi_action_record actionRecord;
65-
const unsigned char* __ptrauth_cxxabi_lsd languageSpecificData;
66-
void* __ptrauth_cxxabi_catch_temp catchTemp;
67-
void* __ptrauth_cxxabi_adjusted_ptr adjustedPtr;
64+
const unsigned char *__ptrauth_cxxabi_action_record actionRecord;
65+
const unsigned char *__ptrauth_cxxabi_lsd languageSpecificData;
66+
void *__ptrauth_cxxabi_catch_temp catchTemp;
67+
void *__ptrauth_cxxabi_adjusted_ptr adjustedPtr;
6868
#endif
6969

7070
#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)
@@ -88,7 +88,7 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
8888
#endif
8989

9090
std::type_info *exceptionType;
91-
void(_LIBCXXABI_DTOR_FUNC* __ptrauth_cxxabi_exception_destructor exceptionDestructor)(void*);
91+
void(_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void*);
9292
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
9393
std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
9494

@@ -102,10 +102,10 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
102102
#else
103103
int handlerSwitchValue;
104104

105-
const unsigned char* __ptrauth_cxxabi_action_record actionRecord;
106-
const unsigned char* __ptrauth_cxxabi_lsd languageSpecificData;
107-
void* __ptrauth_cxxabi_catch_temp catchTemp;
108-
void* __ptrauth_cxxabi_adjusted_ptr adjustedPtr;
105+
const unsigned char *__ptrauth_cxxabi_action_record actionRecord;
106+
const unsigned char *__ptrauth_cxxabi_lsd languageSpecificData;
107+
void *__ptrauth_cxxabi_catch_temp catchTemp;
108+
void *__ptrauth_cxxabi_adjusted_ptr adjustedPtr;
109109
#endif
110110

111111
#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)

libcxxabi/src/cxa_personality.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,10 @@ get_thrown_object_ptr(_Unwind_Exception* unwind_exception)
564564
namespace
565565
{
566566

567-
typedef const uint8_t* __ptrauth_scan_results_lsd lsd_ptr_t;
568-
typedef const uint8_t* __ptrauth_scan_results_action_record action_ptr_t;
567+
typedef const uint8_t *__ptrauth_scan_results_lsd lsd_ptr_t;
568+
typedef const uint8_t *__ptrauth_scan_results_action_record action_ptr_t;
569569
typedef uintptr_t __ptrauth_scan_results_landingpad_intptr landing_pad_t;
570-
typedef void* __ptrauth_scan_results_landingpad landing_pad_ptr_t;
570+
typedef void *__ptrauth_scan_results_landingpad landing_pad_ptr_t;
571571

572572
struct scan_results
573573
{
@@ -585,12 +585,16 @@ struct scan_results
585585
} // unnamed namespace
586586
} // extern "C"
587587

588+
#if !defined(_LIBCXXABI_ARM_EHABI)
588589
namespace {
589590
// The logical model for casting authenticated function pointers makes
590591
// it impossible to directly cast them without breaking the authentication,
591592
// as a result we need this pair of helpers.
593+
//
594+
// __ptrauth_nop_cast cannot be used here as the authentication schemas include
595+
// address diversification.
592596
template <typename PtrType>
593-
[[maybe_unused]] void set_landing_pad_as_ptr(scan_results& results, const PtrType& out) {
597+
void set_landing_pad_as_ptr(scan_results& results, const PtrType& out) {
594598
union {
595599
landing_pad_t* as_landing_pad;
596600
landing_pad_ptr_t* as_pointer;
@@ -599,7 +603,7 @@ template <typename PtrType>
599603
*u.as_pointer = out;
600604
}
601605

602-
[[maybe_unused]] static const landing_pad_ptr_t& get_landing_pad_as_ptr(const scan_results& results) {
606+
static const landing_pad_ptr_t& get_landing_pad_as_ptr(const scan_results& results) {
603607
union {
604608
const landing_pad_t* as_landing_pad;
605609
const landing_pad_ptr_t* as_pointer;
@@ -608,6 +612,7 @@ template <typename PtrType>
608612
return *u.as_pointer;
609613
}
610614
} // unnamed namespace
615+
#endif
611616

612617
extern "C" {
613618
static

libunwind/include/libunwind.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
__unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1, \
120120
__ptrauth_unwind_cie_info_personality_disc)
121121

122+
// ptrauth_string_discriminator("personality") == 0x7EAD)
123+
#define __ptrauth_unwind_pacret_personality_disc 0x7EAD
124+
122125
#else
123126

124127
#define __ptrauth_unwind_upi_handler
@@ -136,7 +139,6 @@
136139
#define __ptrauth_unwind_uis_compact_unwind_section
137140
#define __ptrauth_unwind_uis_compact_unwind_section_length
138141
#define __ptrauth_unwind_cie_info_personality
139-
140142
#endif
141143

142144
#if defined(_WIN32) && defined(__SEH__)

libunwind/src/CompactUnwinder.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,13 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrame(
683683
}
684684

685685
Registers_arm64::reg_t fp = registers.getFP();
686-
// fp points to old fp
687-
registers.setFP(addressSpace.get64(fp));
688686

689-
// old sp is fp less saved fp and lr. Set this before FP & LR because in
690-
// arm64e it's the discriminator used for those registers.
687+
// old sp is fp less saved fp and lr. Set this before LR because in arm64e
688+
// it's the authentication discriminator.
691689
registers.setSP(fp + 16);
692690

693-
Registers_arm64::reg_t oldfp = addressSpace.get64(fp);
694-
695691
// fp points to old fp
696-
registers.setFP(oldfp);
692+
registers.setFP(addressSpace.get64(fp));
697693

698694
// pop return address into pc
699695
registers.setIP(addressSpace.get64(fp + 8));

libunwind/src/DwarfInstructions.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DwarfInstructions {
6363
pint_t cfa, const RegisterLocation &savedReg);
6464

6565
static pint_t getCFA(A &addressSpace, const PrologInfo &prolog,
66-
R &registers) {
66+
const R &registers) {
6767
if (prolog.cfaRegister != 0) {
6868
uintptr_t cfaRegister = registers.getRegister((int)prolog.cfaRegister);
6969
return (pint_t)(cfaRegister + prolog.cfaRegisterOffset);
@@ -209,7 +209,7 @@ bool DwarfInstructions<A, R>::isReturnAddressSignedWithPC(A &addressSpace,
209209

210210
template <typename A, typename R>
211211
int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace,
212-
typename R::link_reg_t &pc,
212+
const typename R::link_reg_t &pc,
213213
pint_t fdeStart, R &registers,
214214
bool &isSignalFrame, bool stage2) {
215215
FDE_Info fdeInfo;
@@ -302,12 +302,12 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace,
302302

303303
isSignalFrame = cieInfo.isSignalFrame;
304304

305-
#if defined(_LIBUNWIND_TARGET_AARCH64)
306-
// If the target is aarch64 then the return address may have been signed
307-
// using the v8.3 pointer authentication extensions. The original
308-
// return address needs to be authenticated before the return address is
309-
// restored. autia1716 is used instead of autia as autia1716 assembles
310-
// to a NOP on pre-v8.3a architectures.
305+
#if defined(__ARM64E__)
306+
// If the target is using the arm64e ABI then the return address has
307+
// been signed using the stack pointer as a diversifier. The original
308+
// return address needs to be authenticated before the it is restored.
309+
// autia1716 is used instead of autia as autia1716 assembles to a NOP on
310+
// pre-v8.3a architectures.
311311
if ((R::getArch() == REGISTERS_ARM64) &&
312312
isReturnAddressSigned(addressSpace, registers, cfa, prolog) &&
313313
returnAddress != 0) {

libunwind/src/DwarfParser.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
405405
// schema. If we could guarantee the encoding of the personality we
406406
// could avoid this by simply giving resultAddr the correct ptrauth
407407
// schema and performing an assignment.
408+
#ifdef __ARM64E__
409+
const auto oldDiscriminator = resultAddr;
410+
#else
411+
const auto oldDiscriminator = ptrauth_blend_discriminator(
412+
(void*)resultAddr, __ptrauth_unwind_pacret_personality_disc);
413+
#endif
408414
const auto discriminator = ptrauth_blend_discriminator(
409415
&cieInfo->personality, __ptrauth_unwind_cie_info_personality_disc);
410416
void *signedPtr = ptrauth_auth_and_resign(

0 commit comments

Comments
 (0)