linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: <gregkh@linuxfoundation.org>
To: alexandru.elisei@arm.com,amit.kachhap@arm.com,anshuman.khandual@arm.com,ardb@kernel.org,broonie@kernel.org,catalin.marinas@arm.com,ebiederm@xmission.com,f.fainelli@gmail.com,gregkh@linuxfoundation.org,haibinzhang@tencent.com,hewenliang4@huawei.com,james.morse@arm.com,linux-arm-kernel@lists.infradead.org,mark.rutland@arm.com,ruanjinjie@huawei.com,sashal@kernel.org,scott@os.amperecomputing.com,stable@kernel.org,will@kernel.org,youngmin.nam@samsung.com,yuzenghui@huawei.com
Cc: <stable-commits@vger.kernel.org>
Subject: Patch "arm64: rework BTI exception handling" has been added to the 5.10-stable tree
Date: Mon, 16 Oct 2023 10:02:25 +0200	[thread overview]
Message-ID: <2023101624-decrease-endorphin-be1d@gregkh> (raw)
In-Reply-To: <20231011100545.979577-6-ruanjinjie@huawei.com>


This is a note to let you know that I've just added the patch titled

    arm64: rework BTI exception handling

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     arm64-rework-bti-exception-handling.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


From ruanjinjie@huawei.com Wed Oct 11 12:06:32 2023
From: Jinjie Ruan <ruanjinjie@huawei.com>
Date: Wed, 11 Oct 2023 10:05:35 +0000
Subject: arm64: rework BTI exception handling
To: <catalin.marinas@arm.com>, <will@kernel.org>, <yuzenghui@huawei.com>, <anshuman.khandual@arm.com>, <gregkh@linuxfoundation.org>, <mark.rutland@arm.com>, <broonie@kernel.org>, <youngmin.nam@samsung.com>, <ardb@kernel.org>, <f.fainelli@gmail.com>, <james.morse@arm.com>, <sashal@kernel.org>, <scott@os.amperecomputing.com>, <ebiederm@xmission.com>, <haibinzhang@tencent.com>, <hewenliang4@huawei.com>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <stable@kernel.org>
Cc: <ruanjinjie@huawei.com>
Message-ID: <20231011100545.979577-6-ruanjinjie@huawei.com>

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

commit 830a2a4d853f2c4a1e4606aa03341b7f273b0e9b upstream.

If a BTI exception is taken from EL1, the entry code will treat this as
an unhandled exception and will panic() the kernel. This is inconsistent
with the way we handle FPAC exceptions, which have a dedicated handler
and only necessarily kill the thread from which the exception was taken
from, and we don't log all the information that could be relevant to
debug the issue.

The code in do_bti() has:

	BUG_ON(!user_mode(regs));

... and it seems like the intent was to call this for EL1 BTI
exceptions, as with FPAC, but this was omitted due to an oversight.

This patch adds separate EL0 and EL1 BTI exception handlers, with the
latter calling die() directly to report the original context the BTI
exception was taken from. This matches our handling of FPAC exceptions.

Prior to this patch, a BTI failure is reported as:

| Unhandled 64-bit el1h sync exception on CPU0, ESR 0x0000000034000002 -- BTI
| CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.19.0-rc3-00131-g7d937ff0221d-dirty #9
| Hardware name: linux,dummy-virt (DT)
| pstate: 20400809 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=-c)
| pc : test_bti_callee+0x4/0x10
| lr : test_bti_caller+0x1c/0x28
| sp : ffff80000800bdf0
| x29: ffff80000800bdf0 x28: 0000000000000000 x27: 0000000000000000
| x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000
| x23: ffff80000a2b8000 x22: 0000000000000000 x21: 0000000000000000
| x20: ffff8000099fa5b0 x19: ffff800009ff7000 x18: fffffbfffda37000
| x17: 3120676e696d7573 x16: 7361202c6e6f6974 x15: 0000000041a90000
| x14: 0040000000000041 x13: 0040000000000001 x12: ffff000001a90000
| x11: fffffbfffda37480 x10: 0068000000000703 x9 : 0001000040000000
| x8 : 0000000000090000 x7 : 0068000000000f03 x6 : 0060000000000f83
| x5 : ffff80000a2b6000 x4 : ffff0000028d0000 x3 : ffff800009f78378
| x2 : 0000000000000000 x1 : 0000000040210000 x0 : ffff8000080257e4
| Kernel panic - not syncing: Unhandled exception
| CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.19.0-rc3-00131-g7d937ff0221d-dirty #9
| Hardware name: linux,dummy-virt (DT)
| Call trace:
|  dump_backtrace.part.0+0xcc/0xe0
|  show_stack+0x18/0x5c
|  dump_stack_lvl+0x64/0x80
|  dump_stack+0x18/0x34
|  panic+0x170/0x360
|  arm64_exit_nmi.isra.0+0x0/0x80
|  el1h_64_sync_handler+0x64/0xd0
|  el1h_64_sync+0x64/0x68
|  test_bti_callee+0x4/0x10
|  smp_cpus_done+0xb0/0xbc
|  smp_init+0x7c/0x8c
|  kernel_init_freeable+0x128/0x28c
|  kernel_init+0x28/0x13c
|  ret_from_fork+0x10/0x20

With this patch applied, a BTI failure is reported as:

| Internal error: Oops - BTI: 0000000034000002 [#1] PREEMPT SMP
| Modules linked in:
| CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.19.0-rc3-00132-g0ad98265d582-dirty #8
| Hardware name: linux,dummy-virt (DT)
| pstate: 20400809 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=-c)
| pc : test_bti_callee+0x4/0x10
| lr : test_bti_caller+0x1c/0x28
| sp : ffff80000800bdf0
| x29: ffff80000800bdf0 x28: 0000000000000000 x27: 0000000000000000
| x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000
| x23: ffff80000a2b8000 x22: 0000000000000000 x21: 0000000000000000
| x20: ffff8000099fa5b0 x19: ffff800009ff7000 x18: fffffbfffda37000
| x17: 3120676e696d7573 x16: 7361202c6e6f6974 x15: 0000000041a90000
| x14: 0040000000000041 x13: 0040000000000001 x12: ffff000001a90000
| x11: fffffbfffda37480 x10: 0068000000000703 x9 : 0001000040000000
| x8 : 0000000000090000 x7 : 0068000000000f03 x6 : 0060000000000f83
| x5 : ffff80000a2b6000 x4 : ffff0000028d0000 x3 : ffff800009f78378
| x2 : 0000000000000000 x1 : 0000000040210000 x0 : ffff800008025804
| Call trace:
|  test_bti_callee+0x4/0x10
|  smp_cpus_done+0xb0/0xbc
|  smp_init+0x7c/0x8c
|  kernel_init_freeable+0x128/0x28c
|  kernel_init+0x28/0x13c
|  ret_from_fork+0x10/0x20
| Code: d50323bf d53cd040 d65f03c0 d503233f (d50323bf)

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: Amit Daniel Kachhap <amit.kachhap@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220913101732.3925290-6-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/arm64/include/asm/exception.h |    3 ++-
 arch/arm64/kernel/entry-common.c   |   14 +++++++++++++-
 arch/arm64/kernel/traps.c          |   10 +++++++---
 3 files changed, 22 insertions(+), 5 deletions(-)

--- a/arch/arm64/include/asm/exception.h
+++ b/arch/arm64/include/asm/exception.h
@@ -34,7 +34,8 @@ void arm64_enter_nmi(struct pt_regs *reg
 void arm64_exit_nmi(struct pt_regs *regs);
 void do_mem_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs);
 void do_undefinstr(struct pt_regs *regs, unsigned long esr);
-void do_bti(struct pt_regs *regs);
+void do_el0_bti(struct pt_regs *regs);
+void do_el1_bti(struct pt_regs *regs, unsigned long esr);
 asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr);
 void do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr,
 			struct pt_regs *regs);
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -141,6 +141,15 @@ static void noinstr el1_undef(struct pt_
 	exit_to_kernel_mode(regs);
 }
 
+static void noinstr el1_bti(struct pt_regs *regs, unsigned long esr)
+{
+	enter_from_kernel_mode(regs);
+	local_daif_inherit(regs);
+	do_el1_bti(regs, esr);
+	local_daif_mask();
+	exit_to_kernel_mode(regs);
+}
+
 static void noinstr el1_inv(struct pt_regs *regs, unsigned long esr)
 {
 	enter_from_kernel_mode(regs);
@@ -212,6 +221,9 @@ asmlinkage void noinstr el1_sync_handler
 	case ESR_ELx_EC_UNKNOWN:
 		el1_undef(regs, esr);
 		break;
+	case ESR_ELx_EC_BTI:
+		el1_bti(regs, esr);
+		break;
 	case ESR_ELx_EC_BREAKPT_CUR:
 	case ESR_ELx_EC_SOFTSTP_CUR:
 	case ESR_ELx_EC_WATCHPT_CUR:
@@ -327,7 +339,7 @@ static void noinstr el0_bti(struct pt_re
 {
 	enter_from_user_mode();
 	local_daif_restore(DAIF_PROCCTX);
-	do_bti(regs);
+	do_el0_bti(regs);
 }
 
 static void noinstr el0_inv(struct pt_regs *regs, unsigned long esr)
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -411,12 +411,16 @@ void do_undefinstr(struct pt_regs *regs,
 }
 NOKPROBE_SYMBOL(do_undefinstr);
 
-void do_bti(struct pt_regs *regs)
+void do_el0_bti(struct pt_regs *regs)
 {
-	BUG_ON(!user_mode(regs));
 	force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
 }
-NOKPROBE_SYMBOL(do_bti);
+
+void do_el1_bti(struct pt_regs *regs, unsigned long esr)
+{
+	die("Oops - BTI", regs, esr);
+}
+NOKPROBE_SYMBOL(do_el1_bti);
 
 void do_el0_fpac(struct pt_regs *regs, unsigned long esr)
 {


Patches currently in stable-queue which might be from ruanjinjie@huawei.com are

queue-5.10/arm64-factor-insn-read-out-of-call_undef_hook.patch
queue-5.10/arm64-rework-el0-mrs-emulation.patch
queue-5.10/arm64-die-pass-err-as-long.patch
queue-5.10/arm64-armv8_deprecated-rework-deprected-instruction-handling.patch
queue-5.10/arm64-armv8_deprecated-fix-unused-function-error.patch
queue-5.10/arm64-armv8_deprecated-move-aarch32-helper-earlier.patch
queue-5.10/arm64-consistently-pass-esr_elx-to-die.patch
queue-5.10/arm64-factor-out-el1-ssbs-emulation-hook.patch
queue-5.10/arm64-report-el1-undefs-better.patch
queue-5.10/arm64-armv8_deprecated-fold-ops-into-insn_emulation.patch
queue-5.10/arm64-rework-bti-exception-handling.patch
queue-5.10/arm64-rework-fpac-exception-handling.patch
queue-5.10/arm64-split-el0-el1-undef-handlers.patch
queue-5.10/arm64-allow-kprobes-on-el0-handlers.patch
queue-5.10/arm64-armv8_deprecated-move-emulation-functions.patch

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-10-16  8:04 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11 10:05 [PATCH v5.10 RESEND 00/15] arm64: Fix a concurrency issue in emulation_proc_handler() Jinjie Ruan
2023-10-11 10:05 ` [PATCH v5.10 RESEND 01/15] arm64: report EL1 UNDEFs better Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: report EL1 UNDEFs better" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 02/15] arm64: die(): pass 'err' as long Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: die(): pass 'err' as long" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 03/15] arm64: consistently pass ESR_ELx to die() Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: consistently pass ESR_ELx to die()" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 04/15] arm64: rework FPAC exception handling Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: rework FPAC exception handling" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 05/15] arm64: rework BTI exception handling Jinjie Ruan
2023-10-16  8:02   ` gregkh [this message]
2023-10-11 10:05 ` [PATCH v5.10 RESEND 06/15] arm64: allow kprobes on EL0 handlers Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: allow kprobes on EL0 handlers" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 07/15] arm64: split EL0/EL1 UNDEF handlers Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: split EL0/EL1 UNDEF handlers" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 08/15] arm64: factor out EL1 SSBS emulation hook Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: factor out EL1 SSBS emulation hook" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 09/15] arm64: factor insn read out of call_undef_hook() Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: factor insn read out of call_undef_hook()" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 10/15] arm64: rework EL0 MRS emulation Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: rework EL0 MRS emulation" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 11/15] arm64: armv8_deprecated: fold ops into insn_emulation Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: armv8_deprecated: fold ops into insn_emulation" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 12/15] arm64: armv8_deprecated move emulation functions Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: armv8_deprecated move emulation functions" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 13/15] arm64: armv8_deprecated: move aarch32 helper earlier Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: armv8_deprecated: move aarch32 helper earlier" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 14/15] arm64: armv8_deprecated: rework deprected instruction handling Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: armv8_deprecated: rework deprected instruction handling" has been added to the 5.10-stable tree gregkh
2023-10-11 10:05 ` [PATCH v5.10 RESEND 15/15] arm64: armv8_deprecated: fix unused-function error Jinjie Ruan
2023-10-16  8:02   ` Patch "arm64: armv8_deprecated: fix unused-function error" has been added to the 5.10-stable tree gregkh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2023101624-decrease-endorphin-be1d@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=alexandru.elisei@arm.com \
    --cc=amit.kachhap@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=ardb@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=f.fainelli@gmail.com \
    --cc=haibinzhang@tencent.com \
    --cc=hewenliang4@huawei.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=ruanjinjie@huawei.com \
    --cc=sashal@kernel.org \
    --cc=scott@os.amperecomputing.com \
    --cc=stable-commits@vger.kernel.org \
    --cc=stable@kernel.org \
    --cc=will@kernel.org \
    --cc=youngmin.nam@samsung.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).