Commit 0a425405 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Andi Kleen

[PATCH] Add the canary field to the PDA area and the task struct

This patch adds the per thread cookie field to the task struct and the PDA.
Also it makes sure that the PDA value gets the new cookie value at context
switch, and that a new task gets a new cookie at task creation time.
Signed-off-by: default avatarArjan van Ven <arjan@linux.intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
CC: Andi Kleen <ak@suse.de>
parent b62a5c74
...@@ -625,6 +625,14 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) ...@@ -625,6 +625,14 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
unlazy_fpu(prev_p); unlazy_fpu(prev_p);
write_pda(kernelstack, write_pda(kernelstack,
task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET); task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET);
#ifdef CONFIG_CC_STACKPROTECTOR
write_pda(stack_canary, next_p->stack_canary);
/*
* Build time only check to make sure the stack_canary is at
* offset 40 in the pda; this is a gcc ABI requirement
*/
BUILD_BUG_ON(offsetof(struct x8664_pda, stack_canary) != 40);
#endif
/* /*
* Now maybe reload the debug registers and handle I/O bitmaps * Now maybe reload the debug registers and handle I/O bitmaps
......
...@@ -16,7 +16,12 @@ struct x8664_pda { ...@@ -16,7 +16,12 @@ struct x8664_pda {
unsigned long oldrsp; /* 24 user rsp for system call */ unsigned long oldrsp; /* 24 user rsp for system call */
int irqcount; /* 32 Irq nesting counter. Starts with -1 */ int irqcount; /* 32 Irq nesting counter. Starts with -1 */
int cpunumber; /* 36 Logical CPU number */ int cpunumber; /* 36 Logical CPU number */
char *irqstackptr; /* 40 top of irqstack */ #ifdef CONFIG_CC_STACKPROTECTOR
unsigned long stack_canary; /* 40 stack canary value */
/* gcc-ABI: this canary MUST be at
offset 40!!! */
#endif
char *irqstackptr;
int nodenumber; /* number of current node */ int nodenumber; /* number of current node */
unsigned int __softirq_pending; unsigned int __softirq_pending;
unsigned int __nmi_count; /* number of NMI on this CPUs */ unsigned int __nmi_count; /* number of NMI on this CPUs */
......
...@@ -819,6 +819,11 @@ struct task_struct { ...@@ -819,6 +819,11 @@ struct task_struct {
unsigned did_exec:1; unsigned did_exec:1;
pid_t pid; pid_t pid;
pid_t tgid; pid_t tgid;
#ifdef CONFIG_CC_STACKPROTECTOR
/* Canary value for the -fstack-protector gcc feature */
unsigned long stack_canary;
#endif
/* /*
* pointers to (original) parent process, youngest child, younger sibling, * pointers to (original) parent process, youngest child, younger sibling,
* older sibling, respectively. (p->father can be replaced with * older sibling, respectively. (p->father can be replaced with
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/cn_proc.h> #include <linux/cn_proc.h>
#include <linux/delayacct.h> #include <linux/delayacct.h>
#include <linux/taskstats_kern.h> #include <linux/taskstats_kern.h>
#include <linux/random.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
...@@ -175,6 +176,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig) ...@@ -175,6 +176,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
tsk->thread_info = ti; tsk->thread_info = ti;
setup_thread_stack(tsk, orig); setup_thread_stack(tsk, orig);
#ifdef CONFIG_CC_STACKPROTECTOR
tsk->stack_canary = get_random_int();
#endif
/* One for us, one for whoever does the "release_task()" (usually parent) */ /* One for us, one for whoever does the "release_task()" (usually parent) */
atomic_set(&tsk->usage,2); atomic_set(&tsk->usage,2);
atomic_set(&tsk->fs_excl, 0); atomic_set(&tsk->fs_excl, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment