Skip to content

Commit

Permalink
arch/sh: Check for kprobe trap number before trying to handle a kprob…
Browse files Browse the repository at this point in the history
…e 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 <[email protected]>
Signed-off-by: Yoshinori Sato <[email protected]>
  • Loading branch information
Michael Karcher authored and ysat0 committed Jun 26, 2019
1 parent 7c04efc commit d302389
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arch/sh/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d302389

Please sign in to comment.