[PATCH -tip v3 3/7] kprobes: Warn if optprobe handler tries to change execution path
From: Masami Hiramatsu
Date: Tue Sep 19 2017 - 06:01:00 EST
Warn if optprobe handler tries to change execution path.
As described in Documentation/kprobes.txt, with optprobe
user handler can not change instruction pointer. In that
case user must avoid optimizing the kprobes by setting
post_handler or break_handler.
Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
---
kernel/kprobes.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index a1606a4224e1..de73b843c623 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -387,7 +387,10 @@ void opt_pre_handler(struct kprobe *p, struct pt_regs *regs)
list_for_each_entry_rcu(kp, &p->list, list) {
if (kp->pre_handler && likely(!kprobe_disabled(kp))) {
set_kprobe_instance(kp);
- kp->pre_handler(kp, regs);
+ if (kp->pre_handler(kp, regs)) {
+ if (WARN_ON_ONCE(1))
+ pr_err("Optprobe ignores instruction pointer changing.(%pF)\n", p->addr);
+ }
}
reset_kprobe_instance();
}