Skip to content

Commit a70857e

Browse files
Aaron TomlinIngo Molnar
Aaron Tomlin
authored and
Ingo Molnar
committed
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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: Andrew Morton <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Seiji Aguchi <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Yasuaki Ishimatsu <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent d4311ff commit a70857e

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

arch/powerpc/mm/fault.c

+1-3
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

+1-3
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

+2
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

+1-1
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)