Skip to content

Commit e361362

Browse files
committed
x86/dumpstack/64: Don't evaluate exception stacks before setup
Cyrill reported the following crash: BUG: unable to handle page fault for address: 0000000000001ff0 #PF: supervisor read access in kernel mode RIP: 0010:get_stack_info+0xb3/0x148 It turns out that if the stack tracer is invoked before the exception stack mappings are initialized in_exception_stack() can erroneously classify an invalid address as an address inside of an exception stack: begin = this_cpu_read(cea_exception_stacks); <- 0 end = begin + sizeof(exception stacks); i.e. any address between 0 and end will be considered as exception stack address and the subsequent code will then try to derefence the resulting stack frame at a non mapped address. end = begin + (unsigned long)ep->size; ==> end = 0x2000 regs = (struct pt_regs *)end - 1; ==> regs = 0x2000 - sizeof(struct pt_regs *) = 0x1ff0 info->next_sp = (unsigned long *)regs->sp; ==> Crashes due to accessing 0x1ff0 Prevent this by checking the validity of the cea_exception_stack base address and bailing out if it is zero. Fixes: afcd21d ("x86/dumpstack/64: Use cpu_entry_area instead of orig_ist") Reported-by: Cyrill Gorcunov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Cyrill Gorcunov <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent fe6f85c commit e361362

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kernel/dumpstack_64.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ static bool in_exception_stack(unsigned long *stack, struct stack_info *info)
9494
BUILD_BUG_ON(N_EXCEPTION_STACKS != 6);
9595

9696
begin = (unsigned long)__this_cpu_read(cea_exception_stacks);
97+
/*
98+
* Handle the case where stack trace is collected _before_
99+
* cea_exception_stacks had been initialized.
100+
*/
101+
if (!begin)
102+
return false;
103+
97104
end = begin + sizeof(struct cea_exception_stacks);
98105
/* Bail if @stack is outside the exception stack area. */
99106
if (stk < begin || stk >= end)

0 commit comments

Comments
 (0)