]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
sched: Add helper for task stack page overrun checking
authorAaron Tomlin <atomlin@redhat.com>
Fri, 12 Sep 2014 13:16:18 +0000 (14:16 +0100)
committerIngo Molnar <mingo@kernel.org>
Fri, 19 Sep 2014 10:35:23 +0000 (12:35 +0200)
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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: aneesh.kumar@linux.vnet.ibm.com
Cc: dzickus@redhat.com
Cc: bmr@redhat.com
Cc: jcastillo@redhat.com
Cc: oleg@redhat.com
Cc: riel@redhat.com
Cc: prarit@redhat.com
Cc: jgh@redhat.com
Cc: minchan@kernel.org
Cc: mpe@ellerman.id.au
Cc: tglx@linutronix.de
Cc: hannes@cmpxchg.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Seiji Aguchi <seiji.aguchi@hds.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1410527779-8133-3-git-send-email-atomlin@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/powerpc/mm/fault.c
arch/x86/mm/fault.c
include/linux/sched.h
kernel/trace/trace_stack.c

index 35d0760c3fa44f46db3e25dc6efb454af0d7bf24..99b2f2775658b61059e74f45de3d451eb0d739c4 100644 (file)
@@ -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);
index bc23a7043c6599e9dcb209e65fe209fe46fc2f29..6240bc7ae741b1c6400ab7e96fd270dcd8bfbdeb 100644 (file)
@@ -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;
index 118dca7d5a28b9d2d25f589ef79cb4d962550a57..18f52624eaa692981a65073aab0b83d351dd4e56 100644 (file)
@@ -2617,6 +2617,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)
 {
index 1636e41828c241ad35f89b8d4629bb7a9272aea0..16eddb308c336aac2636ee43c4dcdfab7bb4a3f7 100644 (file)
@@ -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();
        }