Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1565696

[PATCH 4.4 42/42] arm64: avoid returning from bad_mode

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.4 42/42] arm64: avoid returning from bad_mode
Date 2017-01-24 09:40 +0100
Message-ID <t34NZ-1Xv-41@gated-at.bofh.it> (permalink)
References <t34bf-1t2-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Mark Rutland <mark.rutland@arm.com>

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>

---
 arch/arm64/kernel/entry.S |    2 +-
 arch/arm64/kernel/traps.c |   28 ++++++++++++++++++++++++----
 2 files changed, 25 insertions(+), 5 deletions(-)

--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -562,7 +562,7 @@ el0_inv:
 	mov	x0, sp
 	mov	x1, #BAD_SYNC
 	mov	x2, x25
-	bl	bad_mode
+	bl	bad_el0_sync
 	b	ret_to_user
 ENDPROC(el0_sync)
 
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -434,16 +434,33 @@ const char *esr_get_class_string(u32 esr
 }
 
 /*
- * bad_mode handles the impossible case in the exception vector.
+ * bad_mode handles the impossible case in the exception vector. This is always
+ * fatal.
  */
 asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr)
 {
-	siginfo_t info;
-	void __user *pc = (void __user *)instruction_pointer(regs);
 	console_verbose();
 
 	pr_crit("Bad mode in %s handler detected, code 0x%08x -- %s\n",
 		handler[reason], esr, esr_get_class_string(esr));
+
+	die("Oops - bad mode", regs, 0);
+	local_irq_disable();
+	panic("bad mode");
+}
+
+/*
+ * bad_el0_sync handles unexpected, but potentially recoverable synchronous
+ * exceptions taken from EL0. Unlike bad_mode, this returns.
+ */
+asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr)
+{
+	siginfo_t info;
+	void __user *pc = (void __user *)instruction_pointer(regs);
+	console_verbose();
+
+	pr_crit("Bad EL0 synchronous exception detected on CPU%d, code 0x%08x -- %s\n",
+		smp_processor_id(), esr, esr_get_class_string(esr));
 	__show_regs(regs);
 
 	info.si_signo = SIGILL;
@@ -451,7 +468,10 @@ asmlinkage void bad_mode(struct pt_regs
 	info.si_code  = ILL_ILLOPC;
 	info.si_addr  = pc;
 
-	arm64_notify_die("Oops - bad mode", regs, &info, 0);
+	current->thread.fault_address = 0;
+	current->thread.fault_code = 0;
+
+	force_sig_info(info.si_signo, &info, current);
 }
 
 void __pte_error(const char *file, int line, unsigned long val)

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.4 00/42] 4.4.45-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 02/42] IB/mlx5: Wait for all async command completions to complete Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 29/42] ARM: dts: da850-evm: fix read access to SPI flash Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 05/42] IB/mlx4: Fix port query for 56Gb Ethernet links Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 09/42] ARM: dts: imx31: fix clock control module interrupts description Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 37/42] ARM: 8613/1: Fix the uaccess crash on PB11MPCore Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 32/42] arm64/ptrace: Preserve previous registers for short regset write - 3 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 35/42] ARM: dts: imx6qdl-nitrogen6_max: fix sgtl5000 pinctrl init Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 14/42] svcrpc: dont leak contexts on PROC_DESTROY Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 24/42] ubifs: Fix journal replay wrt. xattr nodes Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 03/42] IB/mlx4: Set traffic class in AH Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 42/42] arm64: avoid returning from bad_mode Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 39/42] [media] ite-cir: initialize use_demodulator before using it Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 28/42] ceph: fix bad endianness handling in parse_reply_info_extra Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 31/42] arm64/ptrace: Preserve previous registers for short regset write - 2 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 34/42] arm64/ptrace: Reject attempts to set incomplete hardware breakpoint fields Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:40 +0100
  [PATCH 4.4 16/42] PCI: Enumerate switches below PCI-to-PCIe bridges Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-24 09:50 +0100
  Re: [PATCH 4.4 00/42] 4.4.45-stable review Shuah Khan <shuah.kh@samsung.com> - 2017-01-24 19:30 +0100
  Re: [PATCH 4.4 00/42] 4.4.45-stable review Guenter Roeck <linux@roeck-us.net> - 2017-01-24 20:10 +0100

csiph-web