aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Hogan <james.hogan@imgtec.com>2015-07-27 08:50:21 -0400
committerRalf Baechle <ralf@linux-mips.org>2015-08-03 03:25:14 -0400
commit55c723e181ccec30fb5c672397fe69ec35967d97 (patch)
tree9c165df18002f434fad8f9828982c5b11d6bcc51
parent4ace6139bf23ab4f152ba4207fc10b76cc01d2a5 (diff)
MIPS: do_mcheck: Fix kernel code dump with EVA
If a machine check exception is raised in kernel mode, user context, with EVA enabled, then the do_mcheck handler will attempt to read the code around the EPC using EVA load instructions, i.e. as if the reads were from user mode. This will either read random user data if the process has anything mapped at the same address, or it will cause an exception which is handled by __get_user, resulting in this output: Code: (Bad address in epc) Fix by setting the current user access mode to kernel if the saved register context indicates the exception was taken in kernel mode. This causes __get_user to use normal loads to read the kernel code. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Markos Chandras <markos.chandras@imgtec.com> Cc: Leonid Yegoshin <leonid.yegoshin@imgtec.com> Cc: linux-mips@linux-mips.org Cc: <stable@vger.kernel.org> # 3.15+ Patchwork: https://patchwork.linux-mips.org/patch/10777/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/kernel/traps.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index e207a43b5f8f..02484d17fb6f 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -1519,6 +1519,7 @@ asmlinkage void do_mcheck(struct pt_regs *regs)
1519 const int field = 2 * sizeof(unsigned long); 1519 const int field = 2 * sizeof(unsigned long);
1520 int multi_match = regs->cp0_status & ST0_TS; 1520 int multi_match = regs->cp0_status & ST0_TS;
1521 enum ctx_state prev_state; 1521 enum ctx_state prev_state;
1522 mm_segment_t old_fs = get_fs();
1522 1523
1523 prev_state = exception_enter(); 1524 prev_state = exception_enter();
1524 show_regs(regs); 1525 show_regs(regs);
@@ -1540,8 +1541,13 @@ asmlinkage void do_mcheck(struct pt_regs *regs)
1540 dump_tlb_all(); 1541 dump_tlb_all();
1541 } 1542 }
1542 1543
1544 if (!user_mode(regs))
1545 set_fs(KERNEL_DS);
1546
1543 show_code((unsigned int __user *) regs->cp0_epc); 1547 show_code((unsigned int __user *) regs->cp0_epc);
1544 1548
1549 set_fs(old_fs);
1550
1545 /* 1551 /*
1546 * Some chips may have other causes of machine check (e.g. SB1 1552 * Some chips may have other causes of machine check (e.g. SB1
1547 * graduation timer) 1553 * graduation timer)