Skip to content

Commit 2c118f5

Browse files
thejhIngo Molnar
authored and
Ingo Molnar
committed
x86/dumpstack: Fix inaccurate unwinding from exception stacks due to misplaced assignment
Commit: 2e4be0d ("x86/show_trace_log_lvl: Ensure stack pointer is aligned, again") was intended to ensure alignment of the stack pointer; but it also moved the initialization of the "stack" variable down into the loop header. This was likely intended as a no-op cleanup, since the commit message does not mention it; however, this caused a behavioral change because the value of "regs" is different between the two places. Originally, get_stack_pointer() used the regs provided by the caller; after that commit, get_stack_pointer() instead uses the regs at the top of the stack frame the unwinder is looking at. Often, there are no such regs at all, and "regs" is NULL, causing get_stack_pointer() to fall back to the task's current stack pointer, which is not what we want here, but probably happens to mostly work. Other times, the original regs will point to another regs frame - in that case, the linear guess unwind logic in show_trace_log_lvl() will start unwinding too far up the stack, causing the first frame found by the proper unwinder to never be visited, resulting in a stack trace consisting purely of guess lines. Fix it by moving the "stack = " assignment back where it belongs. Fixes: 2e4be0d ("x86/show_trace_log_lvl: Ensure stack pointer is aligned, again") Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 57e2428 commit 2c118f5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/x86/kernel/dumpstack.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
195195
printk("%sCall Trace:\n", log_lvl);
196196

197197
unwind_start(&state, task, regs, stack);
198+
stack = stack ?: get_stack_pointer(task, regs);
198199
regs = unwind_get_entry_regs(&state, &partial);
199200

200201
/*
@@ -213,9 +214,7 @@ static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
213214
* - hardirq stack
214215
* - entry stack
215216
*/
216-
for (stack = stack ?: get_stack_pointer(task, regs);
217-
stack;
218-
stack = stack_info.next_sp) {
217+
for (; stack; stack = stack_info.next_sp) {
219218
const char *stack_name;
220219

221220
stack = PTR_ALIGN(stack, sizeof(long));

0 commit comments

Comments
 (0)