From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org, mingo@redhat.com,
anderson@redhat.com, esandeen@redhat.com
Cc: Prarit Bhargava <prarit@redhat.com>
Subject: [PATCH]: Write STACK_END_MAGIC to the init_task's stack
Date: Fri, 16 Apr 2010 14:37:19 -0400 [thread overview]
Message-ID: <20100416183719.8100.12732.sendpatchset@prarit.bos.redhat.com> (raw)
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 <prarit@redhat.com>
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index f627779..8f4e2ac 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -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;
diff --git a/include/linux/stackprotector.h b/include/linux/stackprotector.h
index 6f3e54c..fefdfdd 100644
--- a/include/linux/stackprotector.h
+++ b/include/linux/stackprotector.h
@@ -13,4 +13,5 @@ static inline void boot_init_stack_canary(void)
}
#endif
+void task_stack_end_magic(struct task_struct *tsk);
#endif
diff --git a/init/main.c b/init/main.c
index 5c85402..a054403 100644
--- a/init/main.c
+++ b/init/main.c
@@ -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();
/*
diff --git a/kernel/fork.c b/kernel/fork.c
index 44b0791..66b8928 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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();
reply other threads:[~2010-04-16 18:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20100416183719.8100.12732.sendpatchset@prarit.bos.redhat.com \
--to=prarit@redhat.com \
--cc=anderson@redhat.com \
--cc=esandeen@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=x86@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
Powered by JetHome