From 19bfb92e50799a82f7ce6179fb35ccd82061bafd Mon Sep 17 00:00:00 2001 From: HATAYAMA Daisuke Date: Wed, 18 Nov 2020 23:22:02 +0900 Subject: [PATCH] arm64: Fix miscalculation of the starting address of the pt_regs structure on the kernel stack Fix miscalculation of the starting address of the pt_regs structure on the kernel stack, causing bt command to display corrupt backtrace. (gdb) bt #0 android::Mutex::lock (this=) at system/core/libutils/include/utils/Mutex.h:183 #1 android::Looper::pollInner (this=0x704ad1c590 , timeoutMillis=1291145664) at system/core/libutils/Looper.cpp:243 #2 0xbc5e696a00000018 in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) This fix correspnds to the following commit for crash utility: commit c975008e61121ef8785622c3bc26964da8fe0deb Author: Dave Anderson Date: Fri Sep 22 14:59:10 2017 -0400 Fix for the ARM64 "bt" command's display of the user mode exception frame at the top of the stack in Linux 4.7 and later kernels. Without the patch, the contents of the user mode exception frame are invalid due to the miscalculation of the starting address of the pt_regs structure on the kernel stack. (anderson@redhat.com) Signed-off-by: zhaoqianli Signed-off-by: HATAYAMA Daisuke --- src/libgcore/gcore_arm64.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libgcore/gcore_arm64.c b/src/libgcore/gcore_arm64.c index 3257389..678da8d 100644 --- a/src/libgcore/gcore_arm64.c +++ b/src/libgcore/gcore_arm64.c @@ -28,7 +28,8 @@ static int gpr_get(struct task_context *target, BZERO(regs, sizeof(*regs)); - readmem(machdep->get_stacktop(target->task) - 16 - SIZE(pt_regs), KVADDR, + readmem(machdep->get_stacktop(target->task) - + machdep->machspec->user_eframe_offset - SIZE(pt_regs), KVADDR, regs, sizeof(struct user_pt_regs), "gpr_get: user_pt_regs", gcore_verbose_error_handle()); @@ -124,7 +125,8 @@ static int compat_gpr_get(struct task_context *target, BZERO(&pt_regs, sizeof(pt_regs)); BZERO(regs, sizeof(*regs)); - readmem(machdep->get_stacktop(target->task) - 16 - SIZE(pt_regs), KVADDR, + readmem(machdep->get_stacktop(target->task) - + machdep->machspec->user_eframe_offset - SIZE(pt_regs), KVADDR, &pt_regs, sizeof(struct pt_regs), "compat_gpr_get: pt_regs", gcore_verbose_error_handle());