Skip to content

Commit be24a89

Browse files
Mikulas Patockahdeller
authored andcommitted
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC There were several problems: 1) The code that decodes instructions handles instructions that subtract from the stack pointer incorrectly. If the instruction subtracts the number X from the stack pointer the code increases the frame size by (0x100000000-X). This results in invalid accesses to memory and recursive page faults. 2) Because gcc reorders blocks, handling instructions that subtract from the frame pointer is incorrect. For example, this function int f(int a) { if (__builtin_expect(a, 1)) return a; g(); return a; } is compiled in such a way, that the code that decreases the stack pointer for the first "return a" is placed before the code for "g" call. If we recognize this decrement, we mistakenly believe that the frame size for the "g" call is zero. To fix problems 1) and 2), the patch doesn't recognize instructions that decrease the stack pointer at all. To further safeguard the unwind code against nonsense values, we don't allow frame size larger than Total_frame_size. 3) The backtrace is not locked. If stack dump races with module unload, invalid table can be accessed. This patch adds a spinlock when processing module tables. Note, that for correct backtrace, you need recent binutils. Binutils 2.18 from Debian 5 produce garbage unwind tables. Binutils 2.21 work better (it sometimes forgets function frames, but at least it doesn't generate garbage). Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 049ec1b commit be24a89

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎arch/parisc/kernel/unwind.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ find_unwind_entry(unsigned long addr)
7575
if (addr >= kernel_unwind_table.start &&
7676
addr <= kernel_unwind_table.end)
7777
e = find_unwind_entry_in_table(&kernel_unwind_table, addr);
78-
else
78+
else {
79+
unsigned long flags;
80+
81+
spin_lock_irqsave(&unwind_lock, flags);
7982
list_for_each_entry(table, &unwind_tables, list) {
8083
if (addr >= table->start &&
8184
addr <= table->end)
@@ -86,6 +89,8 @@ find_unwind_entry(unsigned long addr)
8689
break;
8790
}
8891
}
92+
spin_unlock_irqrestore(&unwind_lock, flags);
93+
}
8994

9095
return e;
9196
}
@@ -303,18 +308,16 @@ static void unwind_frame_regs(struct unwind_frame_info *info)
303308

304309
insn = *(unsigned int *)npc;
305310

306-
if ((insn & 0xffffc000) == 0x37de0000 ||
307-
(insn & 0xffe00000) == 0x6fc00000) {
311+
if ((insn & 0xffffc001) == 0x37de0000 ||
312+
(insn & 0xffe00001) == 0x6fc00000) {
308313
/* ldo X(sp), sp, or stwm X,D(sp) */
309-
frame_size += (insn & 0x1 ? -1 << 13 : 0) |
310-
((insn & 0x3fff) >> 1);
314+
frame_size += (insn & 0x3fff) >> 1;
311315
dbg("analyzing func @ %lx, insn=%08x @ "
312316
"%lx, frame_size = %ld\n", info->ip,
313317
insn, npc, frame_size);
314-
} else if ((insn & 0xffe00008) == 0x73c00008) {
318+
} else if ((insn & 0xffe00009) == 0x73c00008) {
315319
/* std,ma X,D(sp) */
316-
frame_size += (insn & 0x1 ? -1 << 13 : 0) |
317-
(((insn >> 4) & 0x3ff) << 3);
320+
frame_size += ((insn >> 4) & 0x3ff) << 3;
318321
dbg("analyzing func @ %lx, insn=%08x @ "
319322
"%lx, frame_size = %ld\n", info->ip,
320323
insn, npc, frame_size);
@@ -333,6 +336,9 @@ static void unwind_frame_regs(struct unwind_frame_info *info)
333336
}
334337
}
335338

339+
if (frame_size > e->Total_frame_size << 3)
340+
frame_size = e->Total_frame_size << 3;
341+
336342
if (!unwind_special(info, e->region_start, frame_size)) {
337343
info->prev_sp = info->sp - frame_size;
338344
if (e->Millicode)

0 commit comments

Comments
 (0)