/* * The actual disarming is done here on each CPU and synchronized using * stop_machine. This synchronization is necessary on SMP to avoid removing * a probe between the moment the 'Undefined Instruction' exception is raised * and the moment the exception handler reads the faulting instruction from * memory. It is also needed to atomically set the two half-words of a 32-bit * Thumb breakpoint.
*/ struct patch { void *addr; unsignedint insn;
};
/* * Called with IRQs disabled. IRQs must remain disabled from that point * all the way until processing this kprobe is complete. The current * kprobes implementation cannot process more than one nested level of * kprobe, and that level is reserved for user kprobe handlers, so we can't * risk encountering a new kprobe in an interrupt handler.
*/ staticvoid __kprobes kprobe_handler(struct pt_regs *regs)
{ struct kprobe *p, *cur; struct kprobe_ctlblk *kcb;
kcb = get_kprobe_ctlblk();
cur = kprobe_running();
#ifdef CONFIG_THUMB2_KERNEL /* * First look for a probe which was registered using an address with * bit 0 set, this is the usual situation for pointers to Thumb code. * If not found, fallback to looking for one with bit 0 clear.
*/
p = get_kprobe((kprobe_opcode_t *)(regs->ARM_pc | 1)); if (!p)
p = get_kprobe((kprobe_opcode_t *)regs->ARM_pc);
#else/* ! CONFIG_THUMB2_KERNEL */
p = get_kprobe((kprobe_opcode_t *)regs->ARM_pc); #endif
if (p) { if (!p->ainsn.insn_check_cc(regs->ARM_cpsr)) { /* * Probe hit but conditional execution check failed, * so just skip the instruction and continue as if * nothing had happened. * In this case, we can skip recursing check too.
*/
singlestep_skip(p, regs);
} elseif (cur) { /* Kprobe is pending, so we're recursing. */ switch (kcb->kprobe_status) { case KPROBE_HIT_ACTIVE: case KPROBE_HIT_SSDONE: case KPROBE_HIT_SS: /* A pre- or post-handler probe got us here. */
kprobes_inc_nmissed_count(p);
save_previous_kprobe(kcb);
set_current_kprobe(p);
kcb->kprobe_status = KPROBE_REENTER;
singlestep(p, regs, kcb);
restore_previous_kprobe(kcb); break; case KPROBE_REENTER: /* A nested probe was hit in FIQ, it is a BUG */
pr_warn("Failed to recover from reentered kprobes.\n");
dump_kprobe(p);
fallthrough; default: /* impossible cases */
BUG();
}
} else { /* Probe hit and conditional execution check ok. */
set_current_kprobe(p);
kcb->kprobe_status = KPROBE_HIT_ACTIVE;
/* * If we have no pre-handler or it returned 0, we * continue with normal processing. If we have a * pre-handler and it returned non-zero, it will * modify the execution path and no need to single * stepping. Let's just reset current kprobe and exit.
*/ if (!p->pre_handler || !p->pre_handler(p, regs)) {
kcb->kprobe_status = KPROBE_HIT_SS;
singlestep(p, regs, kcb); if (p->post_handler) {
kcb->kprobe_status = KPROBE_HIT_SSDONE;
p->post_handler(p, regs, 0);
}
}
reset_current_kprobe();
}
} else { /* * The probe was removed and a race is in progress. * There is nothing we can do about it. Let's restart * the instruction. By the time we can restart, the * real instruction will be there.
*/
}
}
switch (kcb->kprobe_status) { case KPROBE_HIT_SS: case KPROBE_REENTER: /* * We are here because the instruction being single * stepped caused a page fault. We reset the current * kprobe and the PC to point back to the probe address * and allow the page fault handler to continue as a * normal page fault.
*/
regs->ARM_pc = (long)cur->addr; if (kcb->kprobe_status == KPROBE_REENTER) {
restore_previous_kprobe(kcb);
} else {
reset_current_kprobe();
} break;
}
return 0;
}
int __kprobes kprobe_exceptions_notify(struct notifier_block *self, unsignedlong val, void *data)
{ /* * notify_die() is currently never called on ARM, * so this callback is currently empty.
*/ return NOTIFY_DONE;
}
/* * When a retprobed function returns, trampoline_handler() is called, * calling the kretprobe's handler. We construct a struct pt_regs to * give a view of registers r0-r11, sp, lr, and pc to the user * return-handler. This is not a complete pt_regs structure, but that * should be enough for stacktrace from the return handler with or * without pt_regs.
*/ void __naked __kprobes __kretprobe_trampoline(void)
{
__asm__ __volatile__ ( #ifdef CONFIG_FRAME_POINTER "ldr lr, =__kretprobe_trampoline \n\t" /* __kretprobe_trampoline makes a framepointer on pt_regs. */ #ifdef CONFIG_CC_IS_CLANG "stmdb sp, {sp, lr, pc} \n\t" "sub sp, sp, #12 \n\t" /* In clang case, pt_regs->ip = lr. */ "stmdb sp!, {r0 - r11, lr} \n\t" /* fp points regs->r11 (fp) */ "add fp, sp, #44 \n\t" #else/* !CONFIG_CC_IS_CLANG */ /* In gcc case, pt_regs->ip = fp. */ "stmdb sp, {fp, sp, lr, pc} \n\t" "sub sp, sp, #16 \n\t" "stmdb sp!, {r0 - r11} \n\t" /* fp points regs->r15 (pc) */ "add fp, sp, #60 \n\t" #endif/* CONFIG_CC_IS_CLANG */ #else/* !CONFIG_FRAME_POINTER */ "sub sp, sp, #16 \n\t" "stmdb sp!, {r0 - r11} \n\t" #endif/* CONFIG_FRAME_POINTER */ "mov r0, sp \n\t" "bl trampoline_handler \n\t" "mov lr, r0 \n\t" "ldmia sp!, {r0 - r11} \n\t" "add sp, sp, #16 \n\t" #ifdef CONFIG_THUMB2_KERNEL "bx lr \n\t" #else "mov pc, lr \n\t" #endif
: : : "memory");
}
/* Called from __kretprobe_trampoline */ static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
{ return (void *)kretprobe_trampoline_handler(regs, (void *)regs->ARM_fp);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.