diff options
author | Luis Machado <luis.machado@arm.com> | 2022-05-24 23:31:09 +0100 |
---|---|---|
committer | Luis Machado <luis.machado@arm.com> | 2022-12-16 11:18:32 +0000 |
commit | d88cb738e6a7a7179dfaff8af78d69250c852af1 (patch) | |
tree | c34f73f06cea5177a4763afb73baf2e8a41c68f6 /gdbserver | |
parent | 22a8433e00fd33efcb1fa4961eb826cd97f2cd8b (diff) | |
download | gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.zip gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.tar.gz gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.tar.bz2 |
[aarch64] Fix removal of non-address bits for PAuth
PR gdb/28947
The address_significant gdbarch setting was introduced as a way to remove
non-address bits from pointers, and it is specified by a constant. This
constant represents the number of address bits in a pointer.
Right now AArch64 is the only architecture that uses it, and 56 was a
correct option so far.
But if we are using Pointer Authentication (PAuth), we might use up to 2 bytes
from the address space to store the required information. We could also have
cases where we're using both PAuth and MTE.
We could adjust the constant to 48 to cover those cases, but this doesn't
cover the case where GDB needs to sign-extend kernel addresses after removal
of the non-address bits.
This has worked so far because bit 55 is used to select between kernel-space
and user-space addresses. But trying to clear a range of bits crossing the
bit 55 boundary requires the hook to be smarter.
The following patch renames the gdbarch hook from significant_addr_bit to
remove_non_address_bits and passes a pointer as opposed to the number of
bits. The hook is now responsible for removing the required non-address bits
and sign-extending the address if needed.
While at it, make GDB and GDBServer share some more code for aarch64 and add a
new arch-specific testcase gdb.arch/aarch64-non-address-bits.exp.
Bug-url: https://sourceware.org/bugzilla/show_bug.cgi?id=28947
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdbserver')
-rw-r--r-- | gdbserver/linux-aarch64-low.cc | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index b657a26..6f44bc6 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -522,21 +522,30 @@ aarch64_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr, return ret; } -/* Return the address only having significant bits. This is used to ignore - the top byte (TBI). */ - static CORE_ADDR -address_significant (CORE_ADDR addr) +aarch64_remove_non_address_bits (CORE_ADDR pointer) { - /* Clear insignificant bits of a target address and sign extend resulting - address. */ - int addr_bit = 56; + /* By default, we assume TBI and discard the top 8 bits plus the + VA range select bit (55). */ + CORE_ADDR mask = AARCH64_TOP_BITS_MASK; + + /* Check if PAC is available for this target. */ + if (tdesc_contains_feature (current_process ()->tdesc, + "org.gnu.gdb.aarch64.pauth")) + { + /* Fetch the PAC masks. These masks are per-process, so we can just + fetch data from whatever thread we have at the moment. - CORE_ADDR sign = (CORE_ADDR) 1 << (addr_bit - 1); - addr &= ((CORE_ADDR) 1 << addr_bit) - 1; - addr = (addr ^ sign) - sign; + Also, we have both a code mask and a data mask. For now they are the + same, but this may change in the future. */ + + struct regcache *regs = get_thread_regcache (current_thread, 1); + CORE_ADDR dmask = regcache_raw_get_unsigned_by_name (regs, "pauth_dmask"); + CORE_ADDR cmask = regcache_raw_get_unsigned_by_name (regs, "pauth_cmask"); + mask |= aarch64_mask_from_pac_registers (cmask, dmask); + } - return addr; + return aarch64_remove_top_bits (pointer, mask); } /* Implementation of linux target ops method "low_stopped_data_address". */ @@ -563,7 +572,7 @@ aarch64_target::low_stopped_data_address () hardware watchpoint hit. The stopped data addresses coming from the kernel can potentially be tagged addresses. */ const CORE_ADDR addr_trap - = address_significant ((CORE_ADDR) siginfo.si_addr); + = aarch64_remove_non_address_bits ((CORE_ADDR) siginfo.si_addr); /* Check if the address matches any watched address. */ state = aarch64_get_debug_reg_state (pid_of (current_thread)); |