Skip to content

Commit a70857e

Browse files
Aaron Tomliningomolnar
authored andcommitted
sched: Add helper for task stack page overrun checking
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>
1 parent d4311ff commit a70857e

4 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎arch/powerpc/mm/fault.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
507507
void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
508508
{
509509
const struct exception_table_entry *entry;
510-
unsigned long *stackend;
511510

512511
/* Are we prepared to handle this fault? */
513512
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)
536535
printk(KERN_ALERT "Faulting instruction address: 0x%08lx\n",
537536
regs->nip);
538537

539-
stackend = end_of_stack(current);
540-
if (*stackend != STACK_END_MAGIC)
538+
if (task_stack_end_corrupted(current))
541539
printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
542540

543541
die("Kernel access of bad area", regs, sig);

‎arch/x86/mm/fault.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ no_context(struct pt_regs *regs, unsigned long error_code,
648648
unsigned long address, int signal, int si_code)
649649
{
650650
struct task_struct *tsk = current;
651-
unsigned long *stackend;
652651
unsigned long flags;
653652
int sig;
654653

@@ -708,8 +707,7 @@ no_context(struct pt_regs *regs, unsigned long error_code,
708707

709708
show_fault_oops(regs, error_code, address);
710709

711-
stackend = end_of_stack(tsk);
712-
if (*stackend != STACK_END_MAGIC)
710+
if (task_stack_end_corrupted(tsk))
713711
printk(KERN_EMERG "Thread overran stack, or stack corrupted\n");
714712

715713
tsk->thread.cr2 = address;

‎include/linux/sched.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,8 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
26172617
}
26182618

26192619
#endif
2620+
#define task_stack_end_corrupted(task) \
2621+
(*(end_of_stack(task)) != STACK_END_MAGIC)
26202622

26212623
static inline int object_is_on_stack(void *obj)
26222624
{

‎kernel/trace/trace_stack.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ check_stack(unsigned long ip, unsigned long *stack)
170170
i++;
171171
}
172172

173-
if (*end_of_stack(current) != STACK_END_MAGIC) {
173+
if (task_stack_end_corrupted(current)) {
174174
print_max_stack();
175175
BUG();
176176
}

0 commit comments

Comments
 (0)