crashpad/util/misc/arm64_pac_bti.S
André Kempe 6bf5e1b5c5 Fix invalid check for valid key of Pointer Authentication
Arm's Pointer Authentication uses two keys for signing pointers, A-key
and B-key. Although by default Clang uses the A-key if PAC support is
enabled at compile time, this behaviour might be overridden via compiler
command line.

This CL fixes the check for the B-key being enabled. The key that shall
be used for Pointer Authentication is denoted by bits 0 (A-key) or
1 (B-key) of __ARM_FEATURE_PAC_DEFAULT. Hence, the previous way of
checking by using bits 0 and 2 does not correctly identify the B-key.

Bug: 40608466
Change-Id: Ib2f226baa12a7145fa0b6e486e49d36e6b0a3cd7
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5341090
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2024-03-15 14:10:46 +00:00

66 lines
2.3 KiB
ArmAsm

// Copyright 2021 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_UTIL_MISC_ARM64_PAC_BTI_S
#define CRASHPAD_UTIL_MISC_ARM64_PAC_BTI_S
/* Support macros for the Armv8.5-A Branch Target Identification and
* Armv8.3-A Pointer Authentication features which require emitting
* a .note.gnu.property section with the appropriate
* architecture-dependent feature bits set.
* Read more: "ELF for the Arm® 64-bit Architecture"
*/
#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
#define GNU_PROPERTY_AARCH64_BTI 1 // Has BTI
#define CRASHPAD_AARCH64_VALID_JUMP_CALL_TARGET bti jc
#define CRASHPAD_AARCH64_VALID_CALL_TARGET bti c
#define CRASHPAD_AARCH64_VALID_JUMP_TARGET bti j
#else
#define GNU_PROPERTY_AARCH64_BTI 0 // No BTI
#define CRASHPAD_AARCH64_VALID_JUMP_CALL_TARGET
#define CRASHPAD_AARCH64_VALID_CALL_TARGET
#define CRASHPAD_AARCH64_VALID_JUMP_TARGET
#endif
#if defined(__ARM_FEATURE_PAC_DEFAULT)
#if ((__ARM_FEATURE_PAC_DEFAULT & ((1<<0)|(1<<1))) == 0)
#error Pointer authentication defines no valid key!
#endif
#define GNU_PROPERTY_AARCH64_PAC 1 // Has PAC
#else
#define GNU_PROPERTY_AARCH64_PAC 0 // No PAC
#endif
/**
* Emit a proper .note.gnu.property section in case of PAC or BTI being enabled.
*/
#if (GNU_PROPERTY_AARCH64_BTI != 0 || GNU_PROPERTY_AARCH64_PAC != 0)
.pushsection .note.gnu.property, "a"
.balign 4
.long 0x4 /* size of field "GNU" */
.long 0x10 /* note descriptor size */
.long 0x5 /* type of note descriptor: NT_GNU_PROPERTY_TYPE_0 */
.asciz "GNU"
.long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
.long 0x4
.long ((GNU_PROPERTY_AARCH64_BTI<<0)|(GNU_PROPERTY_AARCH64_PAC<<1))
.long 0x0
.popsection
#endif
#undef GNU_PROPERTY_AARCH64_BTI
#undef GNU_PROPERTY_AARCH64_PAC
#endif /* CRASHPAD_UTIL_MISC_ARM64_PAC_BTI_S */