diff mbox series

[tip:,perf/kprobes] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()

Message ID 160010377221.15536.8797457304463305492.tip-bot2@tip-bot2
State New
Headers show
Series [tip:,perf/kprobes] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace() | expand

Commit Message

thermal-bot for Julien Panis Sept. 14, 2020, 5:16 p.m. UTC
The following commit has been merged into the perf/kprobes branch of tip:

Commit-ID:     bcb53209be5cb32d485507452edda19b78f31d84
Gitweb:        https://git.kernel.org/tip/bcb53209be5cb32d485507452edda19b78f31d84
Author:        Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate:    Tue, 01 Sep 2020 00:12:07 +09:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 14 Sep 2020 11:20:03 +02:00

kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()

Commit:

  0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")

fixed one bug but the underlying bugs are not completely fixed yet.

If we run a kprobe_module.tc of ftracetest, a warning triggers:

  # ./ftracetest test.d/kprobe/kprobe_module.tc
  === Ftrace unit tests ===
  [1] Kprobe dynamic event - probing module
  ...
   ------------[ cut here ]------------
   Failed to disarm kprobe-ftrace at trace_printk_irq_work+0x0/0x7e [trace_printk] (-2)
   WARNING: CPU: 7 PID: 200 at kernel/kprobes.c:1091 __disarm_kprobe_ftrace.isra.0+0x7e/0xa0

This is because the kill_kprobe() calls disarm_kprobe_ftrace() even
if the given probe is not enabled. In that case, ftrace_set_filter_ip()
fails because the given probe point is not registered to ftrace.

Fix to check the given (going) probe is enabled before invoking
disarm_kprobe_ftrace().

Fixes: 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/159888672694.1411785.5987998076694782591.stgit@devnote2
---
 kernel/kprobes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 732a701..3b61ae8 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2235,9 +2235,10 @@  static void kill_kprobe(struct kprobe *p)
 
 	/*
 	 * The module is going away. We should disarm the kprobe which
-	 * is using ftrace.
+	 * is using ftrace, because ftrace framework is still available at
+	 * MODULE_STATE_GOING notification.
 	 */
-	if (kprobe_ftrace(p))
+	if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
 		disarm_kprobe_ftrace(p);
 }