[PATCH] AArch64 pauth: Support backtrace in EL1 (kernel space)

Koudai Iwahori koudai@google.com
Wed Sep 28 02:59:09 GMT 2022


The way to remove the signature bits from the address depends on the
55th bit of the address. If 55th bit is zero, the signature bits should
be all cleared. If the 55th bit is one, the signature bits should be all
set.
---
I found very similar patches after fixing this issue:
  https://sourceware.org/pipermail/gdb-patches/2022-July/190507.html
  https://sourceware.org/pipermail/gdb-patches/2021-October/182859.html
If this issue will be fixed in the near future, I can wait for it

 gdb/aarch64-tdep.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index d0387044934..16d1e44e903 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -244,6 +244,20 @@ class instruction_reader : public abstract_instruction_reader
 
 } // namespace
 
+/* removes the pauth signature bits from the address. */
+
+static CORE_ADDR
+aarch64_remove_pauth_signature (CORE_ADDR addr, CORE_ADDR mask)
+{
+  /* 55th bit in address determines whether the address comes from the top
+     address range or the bottom address range. */
+  constexpr CORE_ADDR pauth_va_range_select_mask = CORE_ADDR(1) << 55;
+  if (addr & pauth_va_range_select_mask)
+    return addr | mask;
+  else
+    return addr & ~mask;
+}
+
 /* If address signing is enabled, mask off the signature bits from the link
    register, which is passed by value in ADDR, using the register values in
    THIS_FRAME.  */
@@ -258,7 +272,7 @@ aarch64_frame_unmask_lr (aarch64_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;
+      addr = aarch64_remove_pauth_signature(addr, cmask);
 
       /* Record in the frame that the link register required unmasking.  */
       set_frame_previous_pc_masked (this_frame);
-- 
2.37.3.998.g577e59143f-goog



More information about the Gdb-patches mailing list