: Write STACK_END_MAGIC to the init_task's stack
Subsystems (5)
PATCH 1/1 : Write STACK_END_MAGIC to the init_task's stack
Tasks set STACK_END_MAGIC at the end of the stack to catch stack overruns and corruption of the stack. The only task that does not set the magic value is the init_task.
Set the init_task's end of stack to the magic value and remove the conditional in no_context().
Signed-off-by Prarit Bhargava <[email protected]>
arch/x86/mm/fault.c +1 -1
@@ -659,7 +659,7 @@ no_context(struct pt_regs *regs, unsigned long error_code,show_fault_oops (regs, error_code, address); stackend =end_of_stack (tsk); -if (tsk != &init_task && *stackend !=STACK_END_MAGIC ) +if (*stackend !=STACK_END_MAGIC )printk (KERN_ALERT "Thread overran stack, or stack corrupted\n" ); tsk->thread.cr2 = address;
include/linux/stackprotector.h +1 -0
@@ -13,4 +13,5 @@ static inline void boot_init_stack_canary(void) }#endif +void task_stack_end_magic (struct task_struct *tsk);#endif
init/main.c +1 -0
@@ -530,6 +530,7 @@ asmlinkage void __init start_kernel(void)char * command_line;extern struct kernel_param __start___param[], __stop___param[]; +task_stack_end_magic (&init_task);smp_setup_processor_id ();/*
kernel/fork.c +10 -3
@@ -65,6 +65,7 @@#include <linux/perf_event.h> #include <linux/posix-timers.h> #include <linux/user-return-notifier.h> +#include <linux/stackprotector.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -227,11 +228,18 @@ int __attribute__((weak)) arch_dup_task_struct(struct task_struct *dst,return 0 ; } +void task_stack_end_magic (struct task_struct *tsk) +{ +unsigned long *stackend; + + stackend =end_of_stack (tsk); + *stackend =STACK_END_MAGIC ;/* for overflow detection */ +} +static struct task_struct *dup_task_struct (struct task_struct *orig) {struct task_struct *tsk;struct thread_info *ti; -unsigned long *stackend;int err;
@@ -259,8 +267,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)setup_thread_stack (tsk, orig);clear_user_return_notifier (tsk); - stackend =end_of_stack (tsk); - *stackend =STACK_END_MAGIC ;/* for overflow detection */ +task_stack_end_magic (tsk);#ifdef CONFIG_CC_STACKPROTECTOR tsk->stack_canary =get_random_int ();