Skip to content

Commit 0c76ef3

Browse files
Li Huafeimhiramat
authored andcommitted
kprobes: Fix check for probe enabled in kill_kprobe()
In kill_kprobe(), the check whether disarm_kprobe_ftrace() needs to be called always fails. This is because before that we set the KPROBE_FLAG_GONE flag for kprobe so that "!kprobe_disabled(p)" is always false. The disarm_kprobe_ftrace() call introduced by commit: 0cb2f13 ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler") to fix the NULL pointer reference problem. When the probe is enabled, if we do not disarm it, this problem still exists. Fix it by putting the probe enabled check before setting the KPROBE_FLAG_GONE flag. Link: https://lore.kernel.org/all/[email protected]/ Fixes: 3031313 ("kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()") Signed-off-by: Li Huafei <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Reviewed-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent 63a4dc0 commit 0c76ef3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

kernel/kprobes.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,14 @@ static void kill_kprobe(struct kprobe *p)
23642364

23652365
lockdep_assert_held(&kprobe_mutex);
23662366

2367+
/*
2368+
* The module is going away. We should disarm the kprobe which
2369+
* is using ftrace, because ftrace framework is still available at
2370+
* 'MODULE_STATE_GOING' notification.
2371+
*/
2372+
if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
2373+
disarm_kprobe_ftrace(p);
2374+
23672375
p->flags |= KPROBE_FLAG_GONE;
23682376
if (kprobe_aggrprobe(p)) {
23692377
/*
@@ -2380,14 +2388,6 @@ static void kill_kprobe(struct kprobe *p)
23802388
* the original probed function (which will be freed soon) any more.
23812389
*/
23822390
arch_remove_kprobe(p);
2383-
2384-
/*
2385-
* The module is going away. We should disarm the kprobe which
2386-
* is using ftrace, because ftrace framework is still available at
2387-
* 'MODULE_STATE_GOING' notification.
2388-
*/
2389-
if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
2390-
disarm_kprobe_ftrace(p);
23912391
}
23922392

23932393
/* Disable one kprobe */

0 commit comments

Comments
 (0)