[PATCH] AArch64 pauth: Indicate addresses in backtrace for kernel

Luis Machado luis.machado@linaro.org
Tue Oct 26 12:46:52 GMT 2021


Hi!

Second time's the charm.

On 10/25/21 8:47 AM, Kuan-Ying Lee via Gdb-patches wrote:
> Armv8.3-a Pointer Authentication cause the function return address to
> be changed. GDB need to use address bit[55] to know which mode is active
> and mask/unmask the link register in order to get backtrace.
> 
> If address is in kernel mode, we mask the address. If address is in user mode,
> we need to unmask the address.
> ---
>   gdb/aarch64-tdep.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 4b5af4616af..d4bb4305cea 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -257,7 +257,10 @@ aarch64_frame_unmask_lr (struct gdbarch_tdep *tdep,
>       {
>         int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base);
>         CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, cmask_num);
> -      addr = addr & ~cmask;
> +      if (addr & 0x0080000000000000ULL)

I think we should define this constant in aarch64-tdep.h to make it more 
obvious:

#define AARCH64_PAC_VA_RANGE_BIT 55
#define AARCH64_PAC_VA_RANGE_MASK (1ULL << AARCH64_PAC_VA_RANGE_BIT)

> +        addr = addr | cmask;
> +      else
> +        addr = addr & ~cmask;

For the unmasking of the address, it would be nice to put this into a 
separate function that unmasks an address given a particular mask value. 
Something like this:

static CORE_ADDR
aarch64_unmask_address (CORE_ADDR address, CORE_ADDR mask)
{
   /* Unmask kernel mode and user mode addresses appropriately based on
      the VA range bit.  */
   if (address & AARCH64_PAC_VA_RANGE_MASK)
     address | mask;
   else
     address & ~mask;

   return address;
}

If we ever need to unmask kernel/user addresses somewhere else in the 
code, we can just call this function from now on.

Could you please send a v2 of the patch with the suggested changes?

Thanks for the patch.


More information about the Gdb-patches mailing list