Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 136359
b: refs/heads/master
c: 7c9f886
h: refs/heads/master
i:
  136357: 6c1910b
  136355: f4e8a00
  136351: e17dafd
v: v3
  • Loading branch information
Eric Sandeen authored and Thomas Gleixner committed May 26, 2008
1 parent c676666 commit c9efd47
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b40a4392a3c262e0d1b5379b4e142a8eefa63439
refs/heads/master: 7c9f8861e6c9c839f913e49b98c3854daca18f27
7 changes: 7 additions & 0 deletions trunk/arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/kprobes.h>
#include <linux/uaccess.h>
#include <linux/kdebug.h>
#include <linux/magic.h>

#include <asm/system.h>
#include <asm/desc.h>
Expand Down Expand Up @@ -581,6 +582,8 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
unsigned long address;
int write, si_code;
int fault;
unsigned long *stackend;

#ifdef CONFIG_X86_64
unsigned long flags;
#endif
Expand Down Expand Up @@ -850,6 +853,10 @@ void __kprobes do_page_fault(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)
printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");

tsk->thread.cr2 = address;
tsk->thread.trap_no = 14;
tsk->thread.error_code = error_code;
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
#define FUTEXFS_SUPER_MAGIC 0xBAD1DEA
#define INOTIFYFS_SUPER_MAGIC 0x2BAD1DEA

#define STACK_END_MAGIC 0x57AC6E9D
#endif /* __LINUX_MAGIC_H__ */
13 changes: 13 additions & 0 deletions trunk/include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,19 @@ static inline unsigned long *end_of_stack(struct task_struct *p)

extern void thread_info_cache_init(void);

#ifdef CONFIG_DEBUG_STACK_USAGE
static inline unsigned long stack_not_used(struct task_struct *p)
{
unsigned long *n = end_of_stack(p);

do { /* Skip over canary */
n++;
} while (!*n);

return (unsigned long)n - (unsigned long)end_of_stack(p);
}
#endif

/* set thread flags in other task's structures
* - see asm/thread_info.h for TIF_xxxx flags available
*/
Expand Down
5 changes: 1 addition & 4 deletions trunk/kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,12 +899,9 @@ static void check_stack_usage(void)
{
static DEFINE_SPINLOCK(low_water_lock);
static int lowest_to_date = THREAD_SIZE;
unsigned long *n = end_of_stack(current);
unsigned long free;

while (*n == 0)
n++;
free = (unsigned long)n - (unsigned long)end_of_stack(current);
free = stack_not_used(current);

if (free >= lowest_to_date)
return;
Expand Down
5 changes: 5 additions & 0 deletions trunk/kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <linux/tty.h>
#include <linux/proc_fs.h>
#include <linux/blkdev.h>
#include <linux/magic.h>

#include <asm/pgtable.h>
#include <asm/pgalloc.h>
Expand Down Expand Up @@ -186,6 +187,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
{
struct task_struct *tsk;
struct thread_info *ti;
unsigned long *stackend;

int err;

prepare_to_copy(orig);
Expand All @@ -211,6 +214,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
goto out;

setup_thread_stack(tsk, orig);
stackend = end_of_stack(tsk);
*stackend = STACK_END_MAGIC; /* for overflow detection */

#ifdef CONFIG_CC_STACKPROTECTOR
tsk->stack_canary = get_random_int();
Expand Down
7 changes: 1 addition & 6 deletions trunk/kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -5748,12 +5748,7 @@ void sched_show_task(struct task_struct *p)
printk(KERN_CONT " %016lx ", thread_saved_pc(p));
#endif
#ifdef CONFIG_DEBUG_STACK_USAGE
{
unsigned long *n = end_of_stack(p);
while (!*n)
n++;
free = (unsigned long)n - (unsigned long)end_of_stack(p);
}
free = stack_not_used(p);
#endif
printk(KERN_CONT "%5lu %5d %6d\n", free,
task_pid_nr(p), task_pid_nr(p->real_parent));
Expand Down

0 comments on commit c9efd47

Please sign in to comment.