Skip to content

Commit 372a8ea

Browse files
jpoimboeKAGA-KOKO
authored andcommitted
x86/unwind/orc: Fix ORC for newly forked tasks
The ORC unwinder fails to unwind newly forked tasks which haven't yet run on the CPU. It correctly reads the 'ret_from_fork' instruction pointer from the stack, but it incorrectly interprets that value as a call stack address rather than a "signal" one, so the address gets incorrectly decremented in the call to orc_find(), resulting in bad ORC data. Fix it by forcing 'ret_from_fork' frames to be signal frames. Reported-by: Wang ShaoBo <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Wang ShaoBo <[email protected]> Link: https://lkml.kernel.org/r/f91a8778dde8aae7f71884b5df2b16d552040441.1594994374.git.jpoimboe@redhat.com
1 parent de2b41b commit 372a8ea

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/x86/kernel/unwind_orc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,11 @@ bool unwind_next_frame(struct unwind_state *state)
440440
/*
441441
* Find the orc_entry associated with the text address.
442442
*
443-
* Decrement call return addresses by one so they work for sibling
444-
* calls and calls to noreturn functions.
443+
* For a call frame (as opposed to a signal frame), state->ip points to
444+
* the instruction after the call. That instruction's stack layout
445+
* could be different from the call instruction's layout, for example
446+
* if the call was to a noreturn function. So get the ORC data for the
447+
* call instruction itself.
445448
*/
446449
orc = orc_find(state->signal ? state->ip : state->ip - 1);
447450
if (!orc) {
@@ -662,6 +665,7 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
662665
state->sp = task->thread.sp;
663666
state->bp = READ_ONCE_NOCHECK(frame->bp);
664667
state->ip = READ_ONCE_NOCHECK(frame->ret_addr);
668+
state->signal = (void *)state->ip == ret_from_fork;
665669
}
666670

667671
if (get_stack_info((unsigned long *)state->sp, state->task,

0 commit comments

Comments
 (0)