diff options
author | Haavard Skinnemoen <hskinnemoen@atmel.com> | 2007-02-21 07:08:06 -0500 |
---|---|---|
committer | Haavard Skinnemoen <hskinnemoen@atmel.com> | 2007-03-07 04:50:27 -0500 |
commit | 3338368e922a6686a3b3d6f4da07babd224788d4 (patch) | |
tree | fa29c8aaef547723cb5f5f81fe60d441947481b6 /arch/avr32/kernel/traps.c | |
parent | 9a596a6236e1b4d6c2e6105bd85eac19c9f4ec4c (diff) |
[AVR32] show_trace: Only walk valid stack addresses
Terminate the frame pointer walk if (a) the address is outside the
task's kernel stack or (b) if the frame pointer isn't monotonically
increasing. Without this fix, show_trace() may enter an infinite
loop, walking through random data anywhere in memory.
Since any address within the kernel stack is guaranteed to be valid,
we may eliminate the __get_user() calls as well.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Diffstat (limited to 'arch/avr32/kernel/traps.c')
-rw-r--r-- | arch/avr32/kernel/traps.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/arch/avr32/kernel/traps.c b/arch/avr32/kernel/traps.c index 7e803f4d7a12..adc01a12d154 100644 --- a/arch/avr32/kernel/traps.c +++ b/arch/avr32/kernel/traps.c | |||
@@ -49,39 +49,45 @@ out: | |||
49 | return; | 49 | return; |
50 | } | 50 | } |
51 | 51 | ||
52 | static inline int valid_stack_ptr(struct thread_info *tinfo, unsigned long p) | ||
53 | { | ||
54 | return (p > (unsigned long)tinfo) | ||
55 | && (p < (unsigned long)tinfo + THREAD_SIZE - 3); | ||
56 | } | ||
57 | |||
52 | #ifdef CONFIG_FRAME_POINTER | 58 | #ifdef CONFIG_FRAME_POINTER |
53 | static inline void __show_trace(struct task_struct *tsk, unsigned long *sp, | 59 | static inline void __show_trace(struct task_struct *tsk, unsigned long *sp, |
54 | struct pt_regs *regs) | 60 | struct pt_regs *regs) |
55 | { | 61 | { |
56 | unsigned long __user *fp; | 62 | unsigned long lr, fp; |
57 | unsigned long __user *last_fp = NULL; | 63 | struct thread_info *tinfo; |
58 | 64 | ||
59 | if (regs) { | 65 | tinfo = (struct thread_info *) |
60 | fp = (unsigned long __user *)regs->r7; | 66 | ((unsigned long)sp & ~(THREAD_SIZE - 1)); |
61 | } else if (tsk == current) { | 67 | |
62 | register unsigned long __user *real_fp __asm__("r7"); | 68 | if (regs) |
63 | fp = real_fp; | 69 | fp = regs->r7; |
64 | } else { | 70 | else if (tsk == current) |
65 | fp = (unsigned long __user *)tsk->thread.cpu_context.r7; | 71 | asm("mov %0, r7" : "=r"(fp)); |
66 | } | 72 | else |
73 | fp = tsk->thread.cpu_context.r7; | ||
67 | 74 | ||
68 | /* | 75 | /* |
69 | * Walk the stack until (a) we get an exception, (b) the frame | 76 | * Walk the stack as long as the frame pointer (a) is within |
70 | * pointer becomes zero, or (c) the frame pointer gets stuck | 77 | * the kernel stack of the task, and (b) it doesn't move |
71 | * at the same value. | 78 | * downwards. |
72 | */ | 79 | */ |
73 | while (fp && fp != last_fp) { | 80 | while (valid_stack_ptr(tinfo, fp)) { |
74 | unsigned long lr, new_fp = 0; | 81 | unsigned long new_fp; |
75 | |||
76 | last_fp = fp; | ||
77 | if (__get_user(lr, fp)) | ||
78 | break; | ||
79 | if (fp && __get_user(new_fp, fp + 1)) | ||
80 | break; | ||
81 | fp = (unsigned long __user *)new_fp; | ||
82 | 82 | ||
83 | lr = *(unsigned long *)fp; | ||
83 | printk(" [<%08lx>] ", lr); | 84 | printk(" [<%08lx>] ", lr); |
84 | print_symbol("%s\n", lr); | 85 | print_symbol("%s\n", lr); |
86 | |||
87 | new_fp = *(unsigned long *)(fp + 4); | ||
88 | if (new_fp <= fp) | ||
89 | break; | ||
90 | fp = new_fp; | ||
85 | } | 91 | } |
86 | printk("\n"); | 92 | printk("\n"); |
87 | } | 93 | } |