[Crash-utility] [PATCH] Determine the ARM64 kernel's Pointer Authentication mask value by reading the new KERNELPACMASK vmcoreinfo entry.

Amit Daniel Kachhap amit.kachhap at arm.com
Tue Apr 7 09:59:34 UTC 2020


This value is used to mask the PAC bits and generate correct backtrace.
(amit.kachhap at arm.com)
---
The kernel version for the corresponding vmcoreinfo entry is posted here[1].

[1]: https://lore.kernel.org/patchwork/patch/1211981/

 arm64.c | 20 ++++++++++++++++++++
 defs.h  |  1 +
 2 files changed, 21 insertions(+)

diff --git a/arm64.c b/arm64.c
index 09b1b76..55e084f 100644
--- a/arm64.c
+++ b/arm64.c
@@ -84,6 +84,7 @@ static int arm64_get_kvaddr_ranges(struct vaddr_range *);
 static void arm64_get_crash_notes(void);
 static void arm64_calc_VA_BITS(void);
 static int arm64_is_uvaddr(ulong, struct task_context *);
+static void arm64_calc_KERNELPACMASK(void);
 
 
 /*
@@ -213,6 +214,7 @@ arm64_init(int when)
 		machdep->pagemask = ~((ulonglong)machdep->pageoffset);
 
 		arm64_calc_VA_BITS();
+		arm64_calc_KERNELPACMASK();
 		ms = machdep->machspec;
 		if (ms->VA_BITS_ACTUAL) {
 			ms->page_offset = ARM64_PAGE_OFFSET_ACTUAL;
@@ -472,6 +474,7 @@ arm64_init(int when)
 	case LOG_ONLY:
 		machdep->machspec = &arm64_machine_specific;
 		arm64_calc_VA_BITS();
+		arm64_calc_KERNELPACMASK();
 		arm64_calc_phys_offset();
 		machdep->machspec->page_offset = ARM64_PAGE_OFFSET;
 		break;
@@ -1925,6 +1928,7 @@ arm64_print_stackframe_entry(struct bt_info *bt, int level, struct arm64_stackfr
 	struct syment *sp;
 	struct load_module *lm;
 	char buf[BUFSIZE];
+	struct machine_specific *ms = machdep->machspec;
 
         /*
          * if pc comes from a saved lr, it actually points to an instruction
@@ -1932,6 +1936,9 @@ arm64_print_stackframe_entry(struct bt_info *bt, int level, struct arm64_stackfr
          * See, for example, "bl schedule" before ret_to_user().
          */
 	branch_pc = frame->pc - 4;
+	if (ms->CONFIG_ARM64_KERNELPACMASK)
+		branch_pc |= ms->CONFIG_ARM64_KERNELPACMASK;
+
         name = closest_symbol(branch_pc);
         name_plus_offset = NULL;
 
@@ -4070,6 +4077,19 @@ arm64_swp_offset(ulong pte)
 	return pte;
 }
 
+static void arm64_calc_KERNELPACMASK(void)
+{
+	ulong value;
+	char *string;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(KERNELPACMASK)"))) {
+		value = htol(string, QUIET, NULL);
+		free(string);
+		machdep->machspec->CONFIG_ARM64_KERNELPACMASK = value;
+	}
+	fprintf(fp, " got NUMBER(KERNELPACMASK) =%llx\n", value);
+}
+
 #endif  /* ARM64 */
 
 
diff --git a/defs.h b/defs.h
index a3f828d..f37a957 100644
--- a/defs.h
+++ b/defs.h
@@ -3269,6 +3269,7 @@ struct machine_specific {
 	ulong machine_kexec_end;
 	ulong VA_BITS_ACTUAL;
 	ulong CONFIG_ARM64_VA_BITS;
+	ulong CONFIG_ARM64_KERNELPACMASK;
 	ulong VA_START;
 };
 
-- 
2.7.4





More information about the Crash-utility mailing list