public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Aaron Tomlin <atomlin@redhat•com>
To: peterz@infradead•org
Cc: dzickus@redhat•com, jcastillo@redhat•com, riel@redhat•com,
	x86@kernel•org, akpm@linux-foundation•org, minchan@kernel•org,
	bmr@redhat•com, prarit@redhat•com, oleg@redhat•com,
	rostedt@goodmis•org, linux-kernel@vger•kernel.org,
	hannes@cmpxchg•org, mingo@redhat•com,
	aneesh.kumar@linux•vnet.ibm.com, atomlin@redhat•com,
	jgh@redhat•com, linuxppc-dev@lists•ozlabs.org,
	tglx@linutronix•de, akpm@google•com
Subject: [PATCH v4 2/3] sched: Add helper for task stack page overrun checking
Date: Fri, 12 Sep 2014 14:16:18 +0100	[thread overview]
Message-ID: <1410527779-8133-3-git-send-email-atomlin@redhat.com> (raw)
In-Reply-To: <1410527779-8133-1-git-send-email-atomlin@redhat.com>

This facility is used in a few places so let's introduce
a helper function to improve code readability.

Signed-off-by: Aaron Tomlin <atomlin@redhat•com>
---
 arch/powerpc/mm/fault.c    | 4 +---
 arch/x86/mm/fault.c        | 4 +---
 include/linux/sched.h      | 2 ++
 kernel/trace/trace_stack.c | 2 +-
 4 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 35d0760c..99b2f27 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -507,7 +507,6 @@ bail:
 void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 {
 	const struct exception_table_entry *entry;
-	unsigned long *stackend;
 
 	/* Are we prepared to handle this fault?  */
 	if ((entry = search_exception_tables(regs->nip)) != NULL) {
@@ -536,8 +535,7 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 	printk(KERN_ALERT "Faulting instruction address: 0x%08lx\n",
 		regs->nip);
 
-	stackend = end_of_stack(current);
-	if (*stackend != STACK_END_MAGIC)
+	if (task_stack_end_corrupted(current))
 		printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
 
 	die("Kernel access of bad area", regs, sig);
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index bc23a70..6240bc7 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -648,7 +648,6 @@ no_context(struct pt_regs *regs, unsigned long error_code,
 	   unsigned long address, int signal, int si_code)
 {
 	struct task_struct *tsk = current;
-	unsigned long *stackend;
 	unsigned long flags;
 	int sig;
 
@@ -708,8 +707,7 @@ no_context(struct pt_regs *regs, unsigned long error_code,
 
 	show_fault_oops(regs, error_code, address);
 
-	stackend = end_of_stack(tsk);
-	if (*stackend != STACK_END_MAGIC)
+	if (task_stack_end_corrupted(tsk))
 		printk(KERN_EMERG "Thread overran stack, or stack corrupted\n");
 
 	tsk->thread.cr2		= address;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 7ef34b7..a80e35d 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2615,6 +2615,8 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
 }
 
 #endif
+#define task_stack_end_corrupted(task) \
+		(*(end_of_stack(task)) != STACK_END_MAGIC)
 
 static inline int object_is_on_stack(void *obj)
 {
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index 1636e41..16eddb3 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -170,7 +170,7 @@ check_stack(unsigned long ip, unsigned long *stack)
 			i++;
 	}
 
-	if (*end_of_stack(current) != STACK_END_MAGIC) {
+	if (task_stack_end_corrupted(current)) {
 		print_max_stack();
 		BUG();
 	}
-- 
1.9.3

  parent reply	other threads:[~2014-09-12 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12 13:16 [PATCH v4 0/3] sched: Always check the integrity of the canary Aaron Tomlin
2014-09-12 13:16 ` [PATCH v4 1/3] init/main.c: Give init_task a canary Aaron Tomlin
2014-09-18 20:27   ` Oleg Nesterov
2014-09-12 13:16 ` Aaron Tomlin [this message]
2014-09-12 13:16 ` [PATCH v4 3/3] sched: BUG when stack end location is over written Aaron Tomlin

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=1410527779-8133-3-git-send-email-atomlin@redhat.com \
    --to=atomlin@redhat$(echo .)com \
    --cc=akpm@google$(echo .)com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=aneesh.kumar@linux$(echo .)vnet.ibm.com \
    --cc=bmr@redhat$(echo .)com \
    --cc=dzickus@redhat$(echo .)com \
    --cc=hannes@cmpxchg$(echo .)org \
    --cc=jcastillo@redhat$(echo .)com \
    --cc=jgh@redhat$(echo .)com \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=minchan@kernel$(echo .)org \
    --cc=mingo@redhat$(echo .)com \
    --cc=oleg@redhat$(echo .)com \
    --cc=peterz@infradead$(echo .)org \
    --cc=prarit@redhat$(echo .)com \
    --cc=riel@redhat$(echo .)com \
    --cc=rostedt@goodmis$(echo .)org \
    --cc=tglx@linutronix$(echo .)de \
    --cc=x86@kernel$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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