mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arjan van de Ven <arjan@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org, ak@suse.de
Subject: [patch 3/5] -fstack-protector feature: Add the canary field to the PDA area
Date: Wed, 16 Aug 2006 18:51:24 +0200	[thread overview]
Message-ID: <1155747085.3023.69.camel@laptopd505.fenrus.org> (raw)
In-Reply-To: <1155746902.3023.63.camel@laptopd505.fenrus.org>

Subject: [patch 3/5] Add the canary field to the PDA area and the task struct
From: Arjan van de Ven <arjan@linux.intel.com>

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: Arjan van Ven <arjan@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
CC: Andi Kleen <ak@suse.de>
---
 arch/x86_64/kernel/process.c |    8 ++++++++
 include/asm-x86_64/pda.h     |    6 +++++-
 include/linux/sched.h        |    5 +++++
 kernel/fork.c                |    5 +++++
 4 files changed, 23 insertions(+), 1 deletion(-)

Index: linux-2.6.18-rc4-stackprot/arch/x86_64/kernel/process.c
===================================================================
--- linux-2.6.18-rc4-stackprot.orig/arch/x86_64/kernel/process.c
+++ linux-2.6.18-rc4-stackprot/arch/x86_64/kernel/process.c
@@ -584,6 +584,14 @@ __switch_to(struct task_struct *prev_p, 
 	unlazy_fpu(prev_p);
 	write_pda(kernelstack,
 		  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
Index: linux-2.6.18-rc4-stackprot/include/asm-x86_64/pda.h
===================================================================
--- linux-2.6.18-rc4-stackprot.orig/include/asm-x86_64/pda.h
+++ linux-2.6.18-rc4-stackprot/include/asm-x86_64/pda.h
@@ -14,7 +14,11 @@ struct x8664_pda {
 	unsigned long kernelstack;	/* 16 */  /* top of kernel stack for current */
 	unsigned long oldrsp;		/* 24 */  /* user rsp for system call */
 	unsigned long debugstack;	/* 32 */  /* #DB/#BP stack. */
-	int irqcount;			/* 40 */  /* Irq nesting counter. Starts with -1 */
+#ifdef CONFIG_CC_STACKPROTECTOR
+	unsigned long stack_canary;	/* 40 */  /* stack canary value */
+					/* gcc-ABI: this canary MUST be at offset 40!!! */
+#endif
+	int irqcount;			/* 48 */  /* Irq nesting counter. Starts with -1 */
 	int cpunumber;		    /* Logical CPU number */
 	char *irqstackptr;	/* top of irqstack */
 	int nodenumber;		    /* number of current node */
Index: linux-2.6.18-rc4-stackprot/include/linux/sched.h
===================================================================
--- linux-2.6.18-rc4-stackprot.orig/include/linux/sched.h
+++ linux-2.6.18-rc4-stackprot/include/linux/sched.h
@@ -819,6 +819,11 @@ struct task_struct {
 	unsigned did_exec:1;
 	pid_t pid;
 	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,
 	 * older sibling, respectively.  (p->father can be replaced with 
Index: linux-2.6.18-rc4-stackprot/kernel/fork.c
===================================================================
--- linux-2.6.18-rc4-stackprot.orig/kernel/fork.c
+++ linux-2.6.18-rc4-stackprot/kernel/fork.c
@@ -45,6 +45,7 @@
 #include <linux/cn_proc.h>
 #include <linux/delayacct.h>
 #include <linux/taskstats_kern.h>
+#include <linux/random.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -174,6 +175,10 @@ static struct task_struct *dup_task_stru
 	tsk->thread_info = ti;
 	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) */
 	atomic_set(&tsk->usage,2);
 	atomic_set(&tsk->fs_excl, 0);


  parent reply	other threads:[~2006-08-16 17:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-16 16:48 [patch 0/5] -fstack-protector feature for the kernel (try 2) Arjan van de Ven
2006-08-16 16:49 ` [patch 1/5] -fstack-protector feature: annotate the PDA offsets Arjan van de Ven
2006-08-16 16:50 ` [patch 2/5] -fstack-protector feature: Add the Kconfig option Arjan van de Ven
2006-08-16 18:12   ` Adrian Bunk
2006-08-18 11:08   ` Andi Kleen
2006-08-18 11:23     ` Arjan van de Ven
2006-08-18 14:05       ` Andi Kleen
2006-08-18 13:10         ` Arjan van de Ven
2006-08-18 13:30           ` Arjan van de Ven
2006-08-18 17:21         ` Sam Ravnborg
2006-08-16 16:51 ` Arjan van de Ven [this message]
2006-08-16 16:52 ` [patch 4/5] -fstack-protector feature: Add the __stack_chk_fail() function Arjan van de Ven
2006-08-16 16:53 ` [patch 5/5] -fstack-protector feature: Enable the compiler flags in CFLAGS Arjan van de Ven
2006-08-16 18:55   ` Sam Ravnborg
2006-08-16 19:24     ` Arjan van de Ven
2006-08-18 11:15 ` [patch 0/5] -fstack-protector feature for the kernel (try 2) Andi Kleen
2006-08-18 11:29   ` Arjan van de Ven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1155747085.3023.69.camel@laptopd505.fenrus.org \
    --to=arjan@linux.intel.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®