linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: <gregkh@linuxfoundation.org>
To: alexandru.elisei@arm.com,anshuman.khandual@arm.com,broonie@kernel.org,catalin.marinas@arm.com,ebiederm@xmission.com,gregkh@linuxfoundation.org,haibinzhang@tencent.com,hewenliang4@huawei.com,james.morse@arm.com,joey.gouly@arm.com,linux-arm-kernel@lists.infradead.org,mark.rutland@arm.com,maz@kernel.org,pcc@google.com,peterz@infradead.org,ruanjinjie@huawei.com,sashal@kernel.org,scott@os.amperecomputing.com,stable@kernel.org,will@kernel.org
Cc: <stable-commits@vger.kernel.org>
Subject: Patch "arm64: factor insn read out of call_undef_hook()" has been added to the 5.15-stable tree
Date: Mon, 16 Oct 2023 10:03:57 +0200	[thread overview]
Message-ID: <2023101656-upfront-aim-e9d8@gregkh> (raw)
In-Reply-To: <20231011100655.979626-10-ruanjinjie@huawei.com>


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

    arm64: factor insn read out of call_undef_hook()

to the 5.15-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-factor-insn-read-out-of-call_undef_hook.patch
and it can be found in the queue-5.15 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:07:46 2023
From: Jinjie Ruan <ruanjinjie@huawei.com>
Date: Wed, 11 Oct 2023 10:06:49 +0000
Subject: arm64: factor insn read out of call_undef_hook()
To: <catalin.marinas@arm.com>, <will@kernel.org>, <mark.rutland@arm.com>, <broonie@kernel.org>, <anshuman.khandual@arm.com>, <alexandru.elisei@arm.com>, <sashal@kernel.org>, <maz@kernel.org>, <gregkh@linuxfoundation.org>, <james.morse@arm.com>, <pcc@google.com>, <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: <20231011100655.979626-10-ruanjinjie@huawei.com>

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

commit dbfbd87efa79575491af0ba1a87bf567eaea6cae upstream.

Subsequent patches will rework EL0 UNDEF handling, removing the need for
struct undef_hook and call_undef_hook. In preparation for those changes,
this patch factors the logic for reading user instructions out of
call_undef_hook() and into a new user_insn_read() helper, matching the
style of the existing aarch64_insn_read() helper used for reading kernel
instructions.

There should be no functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20221019144123.612388-5-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/arm64/kernel/traps.c |   31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -394,25 +394,22 @@ void unregister_undef_hook(struct undef_
 	raw_spin_unlock_irqrestore(&undef_lock, flags);
 }
 
-static int call_undef_hook(struct pt_regs *regs)
+static int user_insn_read(struct pt_regs *regs, u32 *insnp)
 {
-	struct undef_hook *hook;
-	unsigned long flags;
 	u32 instr;
-	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
 	void __user *pc = (void __user *)instruction_pointer(regs);
 
 	if (compat_thumb_mode(regs)) {
 		/* 16-bit Thumb instruction */
 		__le16 instr_le;
 		if (get_user(instr_le, (__le16 __user *)pc))
-			goto exit;
+			return -EFAULT;
 		instr = le16_to_cpu(instr_le);
 		if (aarch32_insn_is_wide(instr)) {
 			u32 instr2;
 
 			if (get_user(instr_le, (__le16 __user *)(pc + 2)))
-				goto exit;
+				return -EFAULT;
 			instr2 = le16_to_cpu(instr_le);
 			instr = (instr << 16) | instr2;
 		}
@@ -420,10 +417,20 @@ static int call_undef_hook(struct pt_reg
 		/* 32-bit ARM instruction */
 		__le32 instr_le;
 		if (get_user(instr_le, (__le32 __user *)pc))
-			goto exit;
+			return -EFAULT;
 		instr = le32_to_cpu(instr_le);
 	}
 
+	*insnp = instr;
+	return 0;
+}
+
+static int call_undef_hook(struct pt_regs *regs, u32 instr)
+{
+	struct undef_hook *hook;
+	unsigned long flags;
+	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
+
 	raw_spin_lock_irqsave(&undef_lock, flags);
 	list_for_each_entry(hook, &undef_hook, node)
 		if ((instr & hook->instr_mask) == hook->instr_val &&
@@ -431,7 +438,7 @@ static int call_undef_hook(struct pt_reg
 			fn = hook->fn;
 
 	raw_spin_unlock_irqrestore(&undef_lock, flags);
-exit:
+
 	return fn ? fn(regs, instr) : 1;
 }
 
@@ -483,13 +490,19 @@ void arm64_notify_segfault(unsigned long
 
 void do_el0_undef(struct pt_regs *regs, unsigned long esr)
 {
+	u32 insn;
+
 	/* check for AArch32 breakpoint instructions */
 	if (!aarch32_break_handler(regs))
 		return;
 
-	if (call_undef_hook(regs) == 0)
+	if (user_insn_read(regs, &insn))
+		goto out_err;
+
+	if (call_undef_hook(regs, insn) == 0)
 		return;
 
+out_err:
 	force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
 }
 


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

queue-5.15/arm64-factor-insn-read-out-of-call_undef_hook.patch
queue-5.15/arm64-rework-el0-mrs-emulation.patch
queue-5.15/arm64-die-pass-err-as-long.patch
queue-5.15/arm64-armv8_deprecated-rework-deprected-instruction-handling.patch
queue-5.15/arm64-armv8_deprecated-fix-unused-function-error.patch
queue-5.15/arm64-armv8_deprecated-move-aarch32-helper-earlier.patch
queue-5.15/arm64-consistently-pass-esr_elx-to-die.patch
queue-5.15/arm64-factor-out-el1-ssbs-emulation-hook.patch
queue-5.15/arm64-report-el1-undefs-better.patch
queue-5.15/arm64-armv8_deprecated-fold-ops-into-insn_emulation.patch
queue-5.15/arm64-rework-bti-exception-handling.patch
queue-5.15/arm64-rework-fpac-exception-handling.patch
queue-5.15/arm64-split-el0-el1-undef-handlers.patch
queue-5.15/arm64-allow-kprobes-on-el0-handlers.patch
queue-5.15/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:06 UTC|newest]

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

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=2023101656-upfront-aim-e9d8@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=alexandru.elisei@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=haibinzhang@tencent.com \
    --cc=hewenliang4@huawei.com \
    --cc=james.morse@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=pcc@google.com \
    --cc=peterz@infradead.org \
    --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 \
    /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).