aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/kernel/traps.c
diff options
context:
space:
mode:
authorMark Rutland <mark.rutland@arm.com>2017-01-18 12:23:41 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-26 02:24:40 -0500
commitde327948c009792ea49b07139c21e3a953137344 (patch)
tree2f57318f545e86e2ce69f39751590c3562b50402 /arch/arm64/kernel/traps.c
parent71c49649551460f484c97f79c4fd51728ae55495 (diff)
arm64: avoid returning from bad_mode
commit 7d9e8f71b989230bc613d121ca38507d34ada849 upstream. Generally, taking an unexpected exception should be a fatal event, and bad_mode is intended to cater for this. However, it should be possible to contain unexpected synchronous exceptions from EL0 without bringing the kernel down, by sending a SIGILL to the task. We tried to apply this approach in commit 9955ac47f4ba1c95 ("arm64: don't kill the kernel on a bad esr from el0"), by sending a signal for any bad_mode call resulting from an EL0 exception. However, this also applies to other unexpected exceptions, such as SError and FIQ. The entry paths for these exceptions branch to bad_mode without configuring the link register, and have no kernel_exit. Thus, if we take one of these exceptions from EL0, bad_mode will eventually return to the original user link register value. This patch fixes this by introducing a new bad_el0_sync handler to cater for the recoverable case, and restoring bad_mode to its original state, whereby it calls panic() and never returns. The recoverable case branches to bad_el0_sync with a bl, and returns to userspace via the usual ret_to_user mechanism. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Fixes: 9955ac47f4ba1c95 ("arm64: don't kill the kernel on a bad esr from el0") Reported-by: Mark Salter <msalter@redhat.com> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch/arm64/kernel/traps.c')
-rw-r--r--arch/arm64/kernel/traps.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index c9986b3e0a96..11e5eae088ab 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -596,17 +596,34 @@ const char *esr_get_class_string(u32 esr)
596} 596}
597 597
598/* 598/*
599 * bad_mode handles the impossible case in the exception vector. 599 * bad_mode handles the impossible case in the exception vector. This is always
600 * fatal.
600 */ 601 */
601asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) 602asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr)
602{ 603{
603 siginfo_t info;
604 void __user *pc = (void __user *)instruction_pointer(regs);
605 console_verbose(); 604 console_verbose();
606 605
607 pr_crit("Bad mode in %s handler detected on CPU%d, code 0x%08x -- %s\n", 606 pr_crit("Bad mode in %s handler detected on CPU%d, code 0x%08x -- %s\n",
608 handler[reason], smp_processor_id(), esr, 607 handler[reason], smp_processor_id(), esr,
609 esr_get_class_string(esr)); 608 esr_get_class_string(esr));
609
610 die("Oops - bad mode", regs, 0);
611 local_irq_disable();
612 panic("bad mode");
613}
614
615/*
616 * bad_el0_sync handles unexpected, but potentially recoverable synchronous
617 * exceptions taken from EL0. Unlike bad_mode, this returns.
618 */
619asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr)
620{
621 siginfo_t info;
622 void __user *pc = (void __user *)instruction_pointer(regs);
623 console_verbose();
624
625 pr_crit("Bad EL0 synchronous exception detected on CPU%d, code 0x%08x -- %s\n",
626 smp_processor_id(), esr, esr_get_class_string(esr));
610 __show_regs(regs); 627 __show_regs(regs);
611 628
612 info.si_signo = SIGILL; 629 info.si_signo = SIGILL;
@@ -614,7 +631,10 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr)
614 info.si_code = ILL_ILLOPC; 631 info.si_code = ILL_ILLOPC;
615 info.si_addr = pc; 632 info.si_addr = pc;
616 633
617 arm64_notify_die("Oops - bad mode", regs, &info, 0); 634 current->thread.fault_address = 0;
635 current->thread.fault_code = 0;
636
637 force_sig_info(info.si_signo, &info, current);
618} 638}
619 639
620void __pte_error(const char *file, int line, unsigned long val) 640void __pte_error(const char *file, int line, unsigned long val)