kprobes: Fix check for probe enabled in kill_kprobe()
PATCH 1/1 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:
0cb2f1372baa ("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.
--- kernel/kprobes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
kernel/kprobes.c +8 -8
@@ -2364,6 +2364,14 @@ static void kill_kprobe(struct kprobe *p)lockdep_assert_held (&kprobe_mutex); +/* +* The module is going away. We should disarm the kprobe which +* is using ftrace, because ftrace framework is still available at +* 'MODULE_STATE_GOING' notification. +*/ +if (kprobe_ftrace (p) && !kprobe_disabled (p) && !kprobes_all_disarmed) +disarm_kprobe_ftrace (p); + p->flags |=KPROBE_FLAG_GONE ;if (kprobe_aggrprobe (p)) {/*
@@ -2380,14 +2388,6 @@ static void kill_kprobe(struct kprobe *p)* the original probed function (which will be freed soon) any more. */ arch_remove_kprobe (p); - -/* -* The module is going away. We should disarm the kprobe which -* is using ftrace, because ftrace framework is still available at -* 'MODULE_STATE_GOING' notification. -*/ -if (kprobe_ftrace (p) && !kprobe_disabled (p) && !kprobes_all_disarmed) -disarm_kprobe_ftrace (p); }/* Disable one kprobe */
Signature · 1 line
2.17.1
Quoted 4 lines · On Sat, 26 Nov 2022 19:43:16 +0800 Li Huafei <[email protected]> wrote:
In
kill_kprobe(), the check whetherdisarm_kprobe_ftrace()needs to be called always fails. This is because before that we set theKPROBE_FLAG_GONEflag for kprobe so that "!kprobe_disabled(p)" is always false.
Good catch!
Thank you!
Quoted 54 lines
The
disarm_kprobe_ftrace()call introduced by commit:
0cb2f1372baa("kprobes: Fix NULL pointer dereference atkprobe_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_GONEflag.Fixes 3031313eb3d54 ("kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()")Signed-off-by Li Huafei <[email protected]>--- kernel/kprobes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)kernel/kprobes.c +8
-8@@ -2364,6 +2364,14 @@ static void kill_kprobe(struct kprobe *p)lockdep_assert_held (&kprobe_mutex); +/* +* The module is going away. We should disarm the kprobe which +* is using ftrace, because ftrace framework is still available at +* 'MODULE_STATE_GOING' notification. +*/ +if (kprobe_ftrace (p) && !kprobe_disabled (p) && !kprobes_all_disarmed) +disarm_kprobe_ftrace (p); + p->flags |=KPROBE_FLAG_GONE ;if (kprobe_aggrprobe (p)) {/* @@ -2380,14 +2388,6 @@ static void kill_kprobe(struct kprobe *p)* the original probed function (which will be freed soon) any more. */ arch_remove_kprobe (p); - -/* -* The module is going away. We should disarm the kprobe which -* is using ftrace, because ftrace framework is still available at -* 'MODULE_STATE_GOING' notification. -*/ -if (kprobe_ftrace (p) && !kprobe_disabled (p) && !kprobes_all_disarmed) -disarm_kprobe_ftrace (p); }/* Disable one kprobe */ Signature · 1 line
2.17.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Steven Rostedt
Reviewed-byQuoted 8 lines · On Mon, 28 Nov 2022 17:48:43 +0900 Masami Hiramatsu (Google)…
Quoted 4 lines · On Sat, 26 Nov 2022 19:43:16 +0800 Li Huafei <[email protected]> wrote:
In
kill_kprobe(), the check whetherdisarm_kprobe_ftrace()needs to be called always fails. This is because before that we set theKPROBE_FLAG_GONEflag for kprobe so that "!kprobe_disabled(p)" is always false.
Quoted 5 lines
Good catch!
Thank you!
Looks good.
-- Steve