Skip to content

Commit 2e7e5bb

Browse files
author
Peter Zijlstra
committed
x86: Fix kthread unwind
The rewrite of ret_from_form() misplaced an unwind hint which caused all kthread stack unwinds to be marked unreliable, breaking livepatching. Restore the annotation and add a comment to explain the how and why of things. Fixes: 3aec4ec ("x86: Rewrite ret_from_fork() in C") Reported-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Petr Mladek <pmladek@suse.com> Link: https://lkml.kernel.org/r/20230719201538.GA3553016@hirez.programming.kicks-ass.net
1 parent fdf0eaf commit 2e7e5bb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

arch/x86/entry/entry_64.S

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,15 @@ SYM_FUNC_END(__switch_to_asm)
285285
*/
286286
.pushsection .text, "ax"
287287
SYM_CODE_START(ret_from_fork_asm)
288-
UNWIND_HINT_REGS
288+
/*
289+
* This is the start of the kernel stack; even through there's a
290+
* register set at the top, the regset isn't necessarily coherent
291+
* (consider kthreads) and one cannot unwind further.
292+
*
293+
* This ensures stack unwinds of kernel threads terminate in a known
294+
* good state.
295+
*/
296+
UNWIND_HINT_END_OF_STACK
289297
ANNOTATE_NOENDBR // copy_thread
290298
CALL_DEPTH_ACCOUNT
291299

@@ -295,6 +303,12 @@ SYM_CODE_START(ret_from_fork_asm)
295303
movq %r12, %rcx /* fn_arg */
296304
call ret_from_fork
297305

306+
/*
307+
* Set the stack state to what is expected for the target function
308+
* -- at this point the register set should be a valid user set
309+
* and unwind should work normally.
310+
*/
311+
UNWIND_HINT_REGS
298312
jmp swapgs_restore_regs_and_return_to_usermode
299313
SYM_CODE_END(ret_from_fork_asm)
300314
.popsection

0 commit comments

Comments
 (0)