Skip to content

Commit

Permalink
X86 64: fix a regression issue about kernel stack padding
Browse files Browse the repository at this point in the history
The commit 48764a1 may cause a regression issue when the CONFIG_X86_FRED
is not enabled, this is because the SIZE(fred_frame) will call the
SIZE_verify() to determine if the fred_frame is valid, otherwise it will
emit an error:

  crash> bt 1

  bt: invalid structure size: fred_frame
        FILE: x86_64.c  LINE: 4089  FUNCTION: x86_64_low_budget_back_trace_cmd()

  [/home/k-hagio/bin/crash] error trace: 588df3 => 5cbc72 => 5eb3e1 => 5eb366
  PID: 1        TASK: ffff9f94c024b980  CPU: 2    COMMAND: "systemd"
     #0 [ffffade44001bca8] __schedule at ffffffffb948ebbb
     crash-utility#1 [ffffade44001bd10] schedule at ffffffffb948f04d
     crash-utility#2 [ffffade44001bd20] schedule_hrtimeout_range_clock at ffffffffb9494fef
     crash-utility#3 [ffffade44001bda8] ep_poll at ffffffffb8c91be8
     crash-utility#4 [ffffade44001be48] do_epoll_wait at ffffffffb8c91d11
     crash-utility#5 [ffffade44001be80] __x64_sys_epoll_wait at ffffffffb8c92590
     crash-utility#6 [ffffade44001bed0] do_syscall_64 at ffffffffb947f459
     crash-utility#7 [ffffade44001bf50] entry_SYSCALL_64_after_hwframe at ffffffffb96000ea

      5eb366: SIZE_verify.part.42+70
      5eb3e1: SIZE_verify+49
      5cbc72: x86_64_low_budget_back_trace_cmd+3010
      588df3: back_trace+1523

  bt: invalid structure size: fred_frame
        FILE: x86_64.c  LINE: 4089  FUNCTION: x86_64_low_budget_back_trace_cmd()

Let's replace the SIZE(fred_frame) with the VALID_SIZE(fred_frame) to
fix it.

Fixes: 48764a1 ("x86_64: fix for adding top_of_kernel_stack_padding for kernel stack")
Reported-by: Kazuhito Hagio <[email protected]>
Signed-off-by: Lianbo Jiang <[email protected]>
  • Loading branch information
lian-bo authored and liutgnu committed Dec 1, 2024
1 parent 76cbd7c commit d6a39f3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -4086,7 +4086,7 @@ x86_64_low_budget_back_trace_cmd(struct bt_info *bt_in)

if (!irq_eframe && !is_kernel_thread(bt->tc->task) &&
(GET_STACKBASE(bt->tc->task) == bt->stackbase)) {
long stack_padding_size = SIZE(fred_frame) > 0 ? (2*8) : 0;
long stack_padding_size = VALID_SIZE(fred_frame) ? (2*8) : 0;
user_mode_eframe = bt->stacktop - SIZE(pt_regs);
if (last_process_stack_eframe < user_mode_eframe)
x86_64_exception_frame(EFRAME_PRINT, 0, bt->stackbuf +
Expand Down Expand Up @@ -4408,7 +4408,7 @@ x86_64_dwarf_back_trace_cmd(struct bt_info *bt_in)

if (!irq_eframe && !is_kernel_thread(bt->tc->task) &&
(GET_STACKBASE(bt->tc->task) == bt->stackbase)) {
long stack_padding_size = SIZE(fred_frame) > 0 ? (2*8) : 0;
long stack_padding_size = VALID_SIZE(fred_frame) ? (2*8) : 0;
user_mode_eframe = bt->stacktop - SIZE(pt_regs);
if (last_process_stack_eframe < user_mode_eframe)
x86_64_exception_frame(EFRAME_PRINT, 0, bt->stackbuf +
Expand Down

0 comments on commit d6a39f3

Please sign in to comment.