Skip to content

Commit 0f39e33

Browse files
Guanyou.Chenlian-bo
authored andcommitted
arm64: add pac mask to better support gdb stack unwind
Currently, gdb passthroughs of 'bt', 'frame', 'up', 'down', 'info, locals' don't work on arm64 machine enabled pauth. This is because gdb does not know the lr register actual values to unwind the stack frames. Without the patch: crash> gdb bt #0 __switch_to (prev=0xffffff8001af92c0, next=0xffffff889da7a580) at /proc/self/cwd/common/arch/arm64/kernel/process.c:569 #1 0x9fc5c5d3602132c0 in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) With the patch: crash> gdb bt #0 __switch_to (prev=prev@entry=0xffffff8001af92c0, next=next@entry=0xffffff889da7a580) at /proc/self/cwd/common/arch/arm64/kernel/process.c:569 #1 0xffffffd3602132c0 in context_switch (rq=0xffffff8a7295a080, prev=0xffffff8001af92c0, next=0xffffff889da7a580, rf=<optimized out>) at /proc/self/cwd/common/kernel/sched/core.c:5515 #2 __schedule (sched_mode=<optimized out>, sched_mode@entry=2147859424) at /proc/self/cwd/common/kernel/sched/core.c:6843 #3 0xffffffd3602136d8 in schedule () at /proc/self/cwd/common/kernel/sched/core.c:6917 ... Signed-off-by: Guanyou.Chen <[email protected]>
1 parent 8845309 commit 0f39e33

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

gdb-10.2.patch

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16216,3 +16216,26 @@ exit 0
1621616216
printf_filtered (_("Backtrace stopped: %s\n"),
1621716217
frame_stop_reason_string (trailing));
1621816218
}
16219+
--- gdb-10.2/gdb/frame.c.orig
16220+
+++ gdb-10.2/gdb/frame.c
16221+
@@ -944,6 +944,10 @@ frame_find_by_id (struct frame_id id)
16222+
return NULL;
16223+
}
16224+
16225+
+#ifdef CRASH_MERGE
16226+
+extern "C" void crash_decode_ptrauth_pc(ulong* pc);
16227+
+#endif
16228+
+
16229+
static CORE_ADDR
16230+
frame_unwind_pc (struct frame_info *this_frame)
16231+
{
16232+
@@ -974,6 +978,9 @@ frame_unwind_pc (struct frame_info *this_frame)
16233+
try
16234+
{
16235+
pc = gdbarch_unwind_pc (prev_gdbarch, this_frame);
16236+
+#ifdef CRASH_MERGE
16237+
+ crash_decode_ptrauth_pc(&pc);
16238+
+#endif
16239+
pc_p = true;
16240+
}
16241+
catch (const gdb_exception_error &ex)

gdb_interface.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,3 +1083,13 @@ int crash_get_current_task_reg (int regno, const char *regname,
10831083
return machdep->get_current_task_reg(regno, regname, regsize, value);
10841084
}
10851085

1086+
/* arm64 kernel lr maybe has patuh */
1087+
void crash_decode_ptrauth_pc(ulong *pc);
1088+
void crash_decode_ptrauth_pc(ulong *pc)
1089+
{
1090+
#ifdef ARM64
1091+
struct machine_specific *ms = machdep->machspec;
1092+
if (is_kernel_text(*pc | ms->CONFIG_ARM64_KERNELPACMASK))
1093+
*pc |= ms->CONFIG_ARM64_KERNELPACMASK;
1094+
#endif /* !ARM64 */
1095+
}

0 commit comments

Comments
 (0)