All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: mark.rutland@arm.com, catalin.marinas@arm.com,
	Will Deacon <will.deacon@arm.com>
Subject: [PATCH 07/10] arm64: kprobes: Avoid calling kprobes debug handlers explicitly
Date: Fri,  1 Mar 2019 13:28:06 +0000	[thread overview]
Message-ID: <20190301132809.24653-8-will.deacon@arm.com> (raw)
In-Reply-To: <20190301132809.24653-1-will.deacon@arm.com>

Kprobes bypasses our debug hook registration code so that it doesn't
get tangled up with recursive debug exceptions from things like lockdep:

  http://lists.infradead.org/pipermail/linux-arm-kernel/2015-February/324385.html

However, since then, (a) the hook list has become RCU protected and (b)
the kprobes hooks were found not to filter out exceptions from userspace
correctly. On top of that, the step handler is invoked directly from
single_step_handler(), which *does* use the debug hook list, so it's
clearly not the end of the world.

For now, have kprobes use the debug hook registration API like everybody
else. We can revisit this in the future if this is found to limit
coverage significantly.

Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/kprobes.h   |  2 --
 arch/arm64/kernel/debug-monitors.c | 10 ----------
 arch/arm64/kernel/probes/kprobes.c | 16 ++++++++++++++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h
index d5a44cf859e9..21721fbf44e7 100644
--- a/arch/arm64/include/asm/kprobes.h
+++ b/arch/arm64/include/asm/kprobes.h
@@ -54,8 +54,6 @@ void arch_remove_kprobe(struct kprobe *);
 int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr);
 int kprobe_exceptions_notify(struct notifier_block *self,
 			     unsigned long val, void *data);
-int kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr);
-int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);
 void kretprobe_trampoline(void);
 void __kprobes *trampoline_probe_handler(struct pt_regs *regs);
 
diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
index 51946ecaf8e5..d9616c34a270 100644
--- a/arch/arm64/kernel/debug-monitors.c
+++ b/arch/arm64/kernel/debug-monitors.c
@@ -258,10 +258,6 @@ static int single_step_handler(unsigned long unused, unsigned int esr,
 	if (!reinstall_suspended_bps(regs))
 		return 0;
 
-#ifdef	CONFIG_KPROBES
-	if (kprobe_single_step_handler(regs, esr) == DBG_HOOK_HANDLED)
-		handler_found = true;
-#endif
 	if (!handler_found && call_step_hook(regs, esr) == DBG_HOOK_HANDLED)
 		handler_found = true;
 
@@ -334,12 +330,6 @@ static int brk_handler(unsigned long unused, unsigned int esr,
 {
 	bool handler_found = false;
 
-#ifdef	CONFIG_KPROBES
-	if ((esr & BRK64_ESR_MASK) == BRK64_ESR_KPROBES) {
-		if (kprobe_breakpoint_handler(regs, esr) == DBG_HOOK_HANDLED)
-			handler_found = true;
-	}
-#endif
 	if (!handler_found && call_break_hook(regs, esr) == DBG_HOOK_HANDLED)
 		handler_found = true;
 
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 7fb6f3aa5ceb..3066ffd70cf5 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -444,7 +444,7 @@ kprobe_ss_hit(struct kprobe_ctlblk *kcb, unsigned long addr)
 	return DBG_HOOK_ERROR;
 }
 
-int __kprobes
+static int __kprobes
 kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr)
 {
 	struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -466,7 +466,11 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr)
 	return retval;
 }
 
-int __kprobes
+static struct step_hook kprobes_step_hook = {
+	.fn = kprobe_single_step_handler,
+};
+
+static int __kprobes
 kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)
 {
 	if (user_mode(regs))
@@ -476,6 +480,11 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)
 	return DBG_HOOK_HANDLED;
 }
 
+static struct break_hook kprobes_break_hook = {
+	.imm = BRK64_ESR_KPROBES,
+	.fn = kprobe_breakpoint_handler,
+};
+
 bool arch_within_kprobe_blacklist(unsigned long addr)
 {
 	if ((addr >= (unsigned long)__kprobes_text_start &&
@@ -593,5 +602,8 @@ int __kprobes arch_trampoline_kprobe(struct kprobe *p)
 
 int __init arch_init_kprobes(void)
 {
+	register_kernel_break_hook(&kprobes_break_hook);
+	register_kernel_step_hook(&kprobes_step_hook);
+
 	return 0;
 }
-- 
2.11.0


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

  parent reply	other threads:[~2019-03-01 13:29 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01 13:27 [PATCH 00/10] Rework debug exception handling code Will Deacon
2019-03-01 13:28 ` [PATCH 01/10] arm64: debug: Don't propagate UNKNOWN FAR into si_code for debug signals Will Deacon
2019-03-01 13:28   ` Will Deacon
2019-03-01 13:45   ` Mark Rutland
2019-03-01 13:45     ` Mark Rutland
2019-03-05 13:35   ` Sasha Levin
2019-03-01 13:28 ` [PATCH 02/10] arm64: debug: Ensure debug handlers check triggering exception level Will Deacon
2019-03-01 13:28   ` Will Deacon
2019-03-01 13:46   ` Mark Rutland
2019-03-01 13:46     ` Mark Rutland
2019-03-05 13:35   ` Sasha Levin
2019-03-01 13:28 ` [PATCH 03/10] arm64: debug: Remove unused return value from do_debug_exception() Will Deacon
2019-03-01 13:48   ` Mark Rutland
2019-03-01 13:28 ` [PATCH 04/10] arm64: debug: Rename addr parameter for non-watchpoint exception hooks Will Deacon
2019-03-01 13:49   ` Mark Rutland
2019-03-01 13:28 ` [PATCH 05/10] arm64: debug: Remove meaningless comment Will Deacon
2019-03-01 14:08   ` Mark Rutland
2019-03-01 13:28 ` [PATCH 06/10] arm64: debug: Separate debug hooks based on target exception level Will Deacon
2019-03-01 14:07   ` Mark Rutland
2019-03-01 13:28 ` Will Deacon [this message]
2019-03-01 14:12   ` [PATCH 07/10] arm64: kprobes: Avoid calling kprobes debug handlers explicitly Mark Rutland
2019-03-01 13:28 ` [PATCH 08/10] arm64: debug: Remove redundant user_mode(regs) checks from debug handlers Will Deacon
2019-03-01 14:13   ` Mark Rutland
2019-03-01 13:28 ` [PATCH 09/10] arm64: probes: Move magic BRK values into brk-imm.h Will Deacon
2019-03-01 14:16   ` Mark Rutland
2019-03-01 13:28 ` [PATCH 10/10] arm64: debug: Clean up brk_handler() Will Deacon
2019-03-01 14:17   ` Mark Rutland
2019-03-01 16:24 ` [PATCH 00/10] Rework debug exception handling code Catalin Marinas

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=20190301132809.24653-8-will.deacon@arm.com \
    --to=will.deacon@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.