linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* arch/sh: Check for kprobe trap number before trying to handle a kprobe trap
@ 2019-06-12 13:35 Michael Karcher
  2019-06-26 10:12 ` Yoshinori Sato
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Karcher @ 2019-06-12 13:35 UTC (permalink / raw)
  To: linux-sh

[-- Attachment #1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2: 0001-arch-sh-Check-for-kprobe-trap-number-before-trying-t.patch --]
[-- Type: application/octet-stream, Size: 1555 bytes --]

From 6d7cc74d8aad33589c6cc6f38e33c4284abc07b8 Mon Sep 17 00:00:00 2001
From: Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>
Date: Wed, 12 Jun 2019 15:08:37 +0200
Subject: [PATCH 1/1] arch/sh: Check for kprobe trap number before trying to
 handle a kprobe trap

The DIE_TRAP notifier chain is run both for kprobe traps and for BUG/WARN
traps. The kprobe code assumes to be only called for
BREAKPOINT_INSTRUCTION, and concludes to have hit a concurrently removed
kprobe if it finds anything else at the faulting locations. This includes
TRAPA_BUG_OPCODE used for BUG and WARN.

The consequence is that kprobe_handler returns 1. This makes
kprobe_exceptions_notify return NOTIFY_STOP, and prevents handling the BUG
statement. This also prevents moving $pc away from the trap instruction,
so the system locks up in an endless loop

Signed-off-by: Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>
---
 arch/sh/kernel/kprobes.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/sh/kernel/kprobes.c b/arch/sh/kernel/kprobes.c
index 1f8c0d30567f..318296f48f1a 100644
--- a/arch/sh/kernel/kprobes.c
+++ b/arch/sh/kernel/kprobes.c
@@ -485,7 +485,8 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
 	struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
 
 	addr = (kprobe_opcode_t *) (args->regs->pc);
-	if (val == DIE_TRAP) {
+	if (val == DIE_TRAP &&
+	    args->trapnr == (BREAKPOINT_INSTRUCTION & 0xff)) {
 		if (!kprobe_running()) {
 			if (kprobe_handler(args->regs)) {
 				ret = NOTIFY_STOP;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: arch/sh: Check for kprobe trap number before trying to handle a kprobe trap
  2019-06-12 13:35 arch/sh: Check for kprobe trap number before trying to handle a kprobe trap Michael Karcher
@ 2019-06-26 10:12 ` Yoshinori Sato
  0 siblings, 0 replies; 2+ messages in thread
From: Yoshinori Sato @ 2019-06-26 10:12 UTC (permalink / raw)
  To: linux-sh

On Wed, 12 Jun 2019 22:35:56 +0900,
Michael Karcher wrote:
> 
> [1  <text/plain; utf-8 (8bit)>]
> 
> [2 0001-arch-sh-Check-for-kprobe-trap-number-before-trying-t.patch <application/octet-stream (base64)>]

Applied sh-next.
Thanks.

-- 
Yosinori Sato

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-26 10:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-12 13:35 arch/sh: Check for kprobe trap number before trying to handle a kprobe trap Michael Karcher
2019-06-26 10:12 ` Yoshinori Sato

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).