* [PATCH v2] AArch64 pauth: Indicate unmasked address in backtrace for kernel
@ 2021-10-27 3:32 Kuan-Ying Lee
2021-10-27 13:32 ` Luis Machado
0 siblings, 1 reply; 2+ messages in thread
From: Kuan-Ying Lee @ 2021-10-27 3:32 UTC (permalink / raw)
To: gdb-patches, Luis Machado
Cc: chinwen.chang, zhiyong.wang, nicholas.tang, james.hsu, Kuan-Ying Lee
Armv8.3-a Pointer Authentication causes the function return address to
be changed. GDB needs to use address bit[55] to know which mode is active
and unmask the link register in order to get backtrace.
---
v2:
- Rewrite the commit message
- Add a new function aarch64_unmask_address() for PAC
suggested by Luis in [1]
- Define VA range select bit
[1] https://sourceware.org/pipermail/gdb-patches/2021-October/182835.html
gdb/aarch64-tdep.c | 16 +++++++++++++++-
gdb/aarch64-tdep.h | 4 ++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 42b8494980..a96aed7567 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -243,6 +243,20 @@ class instruction_reader : public abstract_instruction_reader
} // namespace
+/* Return unmasked address by using different unmask method
+ depending on AARCH64_PAC_VA_RANGE_BIT */
+
+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)
+ return address | mask;
+ else
+ return address & ~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. */
@@ -257,7 +271,7 @@ 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;
+ addr = aarch64_unmask_address(addr, cmask);
/* Record in the frame that the link register required unmasking. */
set_frame_previous_pc_masked (this_frame);
diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
index 7bf612b012..9c50988d6e 100644
--- a/gdb/aarch64-tdep.h
+++ b/gdb/aarch64-tdep.h
@@ -59,6 +59,10 @@ struct regset;
single-stepped instruction. */
#define AARCH64_DISPLACED_MODIFIED_INSNS 1
+/* VA range select bit for Pointer Authentication Code (PAC) feature */
+#define AARCH64_PAC_VA_RANGE_BIT 55
+#define AARCH64_PAC_VA_RANGE_MASK (1ULL << AARCH64_PAC_VA_RANGE_BIT)
+
/* Target-dependent structure in gdbarch. */
struct gdbarch_tdep
{
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] AArch64 pauth: Indicate unmasked address in backtrace for kernel
2021-10-27 3:32 [PATCH v2] AArch64 pauth: Indicate unmasked address in backtrace for kernel Kuan-Ying Lee
@ 2021-10-27 13:32 ` Luis Machado
0 siblings, 0 replies; 2+ messages in thread
From: Luis Machado @ 2021-10-27 13:32 UTC (permalink / raw)
To: Kuan-Ying Lee, gdb-patches
Cc: chinwen.chang, zhiyong.wang, nicholas.tang, james.hsu
Thanks. That looks much better.
One thing I forgot to ask. Do you have the copyright assignment papers
in place so you can contribute code on behalf of MediaTek?
I couldn't find those, but they may be pending.
Regards,
Luis
On 10/27/21 12:32 AM, Kuan-Ying Lee wrote:
> Armv8.3-a Pointer Authentication causes the function return address to
> be changed. GDB needs to use address bit[55] to know which mode is active
> and unmask the link register in order to get backtrace.
> ---
> v2:
> - Rewrite the commit message
> - Add a new function aarch64_unmask_address() for PAC
> suggested by Luis in [1]
> - Define VA range select bit
> [1] https://sourceware.org/pipermail/gdb-patches/2021-October/182835.html
>
> gdb/aarch64-tdep.c | 16 +++++++++++++++-
> gdb/aarch64-tdep.h | 4 ++++
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 42b8494980..a96aed7567 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -243,6 +243,20 @@ class instruction_reader : public abstract_instruction_reader
>
> } // namespace
>
> +/* Return unmasked address by using different unmask method
> + depending on AARCH64_PAC_VA_RANGE_BIT */
> +
> +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)
> + return address | mask;
> + else
> + return address & ~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. */
> @@ -257,7 +271,7 @@ 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;
> + addr = aarch64_unmask_address(addr, cmask);
>
> /* Record in the frame that the link register required unmasking. */
> set_frame_previous_pc_masked (this_frame);
> diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
> index 7bf612b012..9c50988d6e 100644
> --- a/gdb/aarch64-tdep.h
> +++ b/gdb/aarch64-tdep.h
> @@ -59,6 +59,10 @@ struct regset;
> single-stepped instruction. */
> #define AARCH64_DISPLACED_MODIFIED_INSNS 1
>
> +/* VA range select bit for Pointer Authentication Code (PAC) feature */
> +#define AARCH64_PAC_VA_RANGE_BIT 55
> +#define AARCH64_PAC_VA_RANGE_MASK (1ULL << AARCH64_PAC_VA_RANGE_BIT)
> +
> /* Target-dependent structure in gdbarch. */
> struct gdbarch_tdep
> {
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-27 13:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 3:32 [PATCH v2] AArch64 pauth: Indicate unmasked address in backtrace for kernel Kuan-Ying Lee
2021-10-27 13:32 ` Luis Machado
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).