diff options
author | Mark Rutland | 2017-01-18 11:23:41 -0600 |
---|---|---|
committer | Greg Kroah-Hartman | 2017-01-26 01:23:50 -0600 |
commit | 8323d0555fe332e35d052d7c1185d299bd8724d9 (patch) | |
tree | 404cbbae43a6ea6c1b6b71240663a7934afde3a9 | |
parent | 6e65a4c698cf8a296f042ab3b9d7b459564ffcd9 (diff) | |
download | kernel-omap-8323d0555fe332e35d052d7c1185d299bd8724d9.tar.gz kernel-omap-8323d0555fe332e35d052d7c1185d299bd8724d9.tar.xz kernel-omap-8323d0555fe332e35d052d7c1185d299bd8724d9.zip |
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>
-rw-r--r-- | arch/arm64/kernel/entry.S | 2 | ||||
-rw-r--r-- | arch/arm64/kernel/traps.c | 28 |
2 files changed, 25 insertions, 5 deletions
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 5a3753d09e20..bd14849beb73 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S | |||
@@ -562,7 +562,7 @@ el0_inv: | |||
562 | mov x0, sp | 562 | mov x0, sp |
563 | mov x1, #BAD_SYNC | 563 | mov x1, #BAD_SYNC |
564 | mov x2, x25 | 564 | mov x2, x25 |
565 | bl bad_mode | 565 | bl bad_el0_sync |
566 | b ret_to_user | 566 | b ret_to_user |
567 | ENDPROC(el0_sync) | 567 | ENDPROC(el0_sync) |
568 | 568 | ||
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index e9b9b5364393..ca7f0ac5f708 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c | |||
@@ -434,16 +434,33 @@ const char *esr_get_class_string(u32 esr) | |||
434 | } | 434 | } |
435 | 435 | ||
436 | /* | 436 | /* |
437 | * bad_mode handles the impossible case in the exception vector. | 437 | * bad_mode handles the impossible case in the exception vector. This is always |
438 | * fatal. | ||
438 | */ | 439 | */ |
439 | asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) | 440 | asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) |
440 | { | 441 | { |
441 | siginfo_t info; | ||
442 | void __user *pc = (void __user *)instruction_pointer(regs); | ||
443 | console_verbose(); | 442 | console_verbose(); |
444 | 443 | ||
445 | pr_crit("Bad mode in %s handler detected, code 0x%08x -- %s\n", | 444 | pr_crit("Bad mode in %s handler detected, code 0x%08x -- %s\n", |
446 | handler[reason], esr, esr_get_class_string(esr)); | 445 | handler[reason], esr, esr_get_class_string(esr)); |
446 | |||
447 | die("Oops - bad mode", regs, 0); | ||
448 | local_irq_disable(); | ||
449 | panic("bad mode"); | ||
450 | } | ||
451 | |||
452 | /* | ||
453 | * bad_el0_sync handles unexpected, but potentially recoverable synchronous | ||
454 | * exceptions taken from EL0. Unlike bad_mode, this returns. | ||
455 | */ | ||
456 | asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr) | ||
457 | { | ||
458 | siginfo_t info; | ||
459 | void __user *pc = (void __user *)instruction_pointer(regs); | ||
460 | console_verbose(); | ||
461 | |||
462 | pr_crit("Bad EL0 synchronous exception detected on CPU%d, code 0x%08x -- %s\n", | ||
463 | smp_processor_id(), esr, esr_get_class_string(esr)); | ||
447 | __show_regs(regs); | 464 | __show_regs(regs); |
448 | 465 | ||
449 | info.si_signo = SIGILL; | 466 | info.si_signo = SIGILL; |
@@ -451,7 +468,10 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) | |||
451 | info.si_code = ILL_ILLOPC; | 468 | info.si_code = ILL_ILLOPC; |
452 | info.si_addr = pc; | 469 | info.si_addr = pc; |
453 | 470 | ||
454 | arm64_notify_die("Oops - bad mode", regs, &info, 0); | 471 | current->thread.fault_address = 0; |
472 | current->thread.fault_code = 0; | ||
473 | |||
474 | force_sig_info(info.si_signo, &info, current); | ||
455 | } | 475 | } |
456 | 476 | ||
457 | void __pte_error(const char *file, int line, unsigned long val) | 477 | void __pte_error(const char *file, int line, unsigned long val) |