public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Koudai Iwahori <koudai@google.com>
To: gdb-patches@sourceware.org
Cc: Koudai Iwahori <koudai@google.com>
Subject: [PATCH] AArch64 pauth: Support backtrace in EL1 (kernel space)
Date: Wed, 28 Sep 2022 02:59:09 +0000	[thread overview]
Message-ID: <20220928025909.190260-1-koudai@google.com> (raw)

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


             reply	other threads:[~2022-09-28  2:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28  2:59 Koudai Iwahori [this message]
2022-10-04  9:24 ` Luis Machado
2022-10-05  2:07   ` Koudai Iwahori
2022-10-05  2:07     ` Koudai Iwahori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220928025909.190260-1-koudai@google.com \
    --to=koudai@google.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).