Skip to content

Commit

Permalink
[PATCH] x86: Terminate the kernel stacks for the unwinder
Browse files Browse the repository at this point in the history
Always make sure RIP/EIP is 0 in the registers stored on the top
of the stack of a kernel thread. This makes sure the unwinder code
won't try a fallback but knows the stack has ended.

AK: this patch is a bit mysterious. in theory they should be terminated
anyways, but it seems to fix at least one crash. Anyways double termination
probably doesn't hurt.

Signed-off-by: Andi Kleen <ak@suse.de>
  • Loading branch information
Andi Kleen authored and Andi Kleen committed Oct 5, 2006
1 parent f015c6c commit 51ec28e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion arch/i386/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ extern void kernel_thread_helper(void);
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
struct pt_regs regs;
int err;

memset(&regs, 0, sizeof(regs));

Expand All @@ -342,7 +343,10 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
regs.eflags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;

/* Ok, create the new process.. */
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
err = do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
if (err == 0) /* terminate kernel stack */
task_pt_regs(current)->eip = 0;
return err;
}
EXPORT_SYMBOL(kernel_thread);

Expand Down
5 changes: 5 additions & 0 deletions arch/x86_64/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,11 @@ ENTRY(kernel_thread)
call do_fork
movq %rax,RAX(%rsp)
xorl %edi,%edi
test %rax,%rax
jnz 1f
/* terminate stack in child */
movq %rdi,RIP(%rsp)
1:

/*
* It isn't worth to check for reschedule here,
Expand Down

0 comments on commit 51ec28e

Please sign in to comment.