Skip to content

Commit

Permalink
arm64: Fix miscalculation of the starting address of the pt_regs stru…
Browse files Browse the repository at this point in the history
…cture 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=<optimized out>) at system/core/libutils/include/utils/Mutex.h:183
    #1  android::Looper::pollInner (this=0x704ad1c590 <epoll_wait(int, epoll_event*, int, int)>, 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 <anderson redhat com>
    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 <zhaoqianli@xiaomi.com>
Signed-off-by: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
  • Loading branch information
HATAYAMA Daisuke authored and d-hatayama committed Jan 22, 2021
1 parent 215500b commit 19bfb92
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libgcore/gcore_arm64.c
Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 19bfb92

Please sign in to comment.