Skip to contentSkip to conversation

probes: Updates for 6.2

PATCH New Steven Rostedt 1 participant 3 messages Dec 10, 2022

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover probes: Updates for 6.2

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
probes/for-next

Head SHA1: 0c76ef3f26d5ef2ac2c21b47e7620cff35809fbb

Li Hua (1):
test_kprobes: Fix implicit declaration error of test_kprobes

Li Huafei (1):
kprobes: Fix check for probe enabled in kill_kprobe()

Steven Rostedt (Google) (1):
tracing: Fix race where eprobes can be called before the event

----

 kernel/kprobes.c            | 16 ++++++++--------
 kernel/trace/trace_eprobe.c |  3 +++
 lib/Kconfig.debug           |  1 +
 3 files changed, 12 insertions(+), 8 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 tracing: Fix race where eprobes can be called before the event

From: "Steven Rostedt (Google)" <[email protected]>

The flag that tells the event to call its triggers after reading the event is set for eprobes after the eprobe is enabled. This leads to a race where the eprobe may be triggered at the beginning of the event where the record information is NULL. The eprobe then dereferences the NULL record causing a NULL kernel pointer bug.

Test for a NULL record to keep this from happening.

---
 kernel/trace/trace_eprobe.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_eprobe.c +3 -0
index 123d2c0a6b68..352b65e2b910 100644
@@ -564,6 +564,9 @@ static void eprobe_trigger_func(struct event_trigger_data *data,
 {
 	struct eprobe_data *edata = data->private_data;
 
+	if (unlikely(!rec))
+		return;
+
 	__eprobe_trace_func(edata, rec);
 }
 
Signature · 1 line
2.35.1
author maintainer
#2 lore raw

PATCH 3/3 kprobes: Fix check for probe enabled in kill_kprobe()

In reply to Steven Rostedt

From: Li Huafei <[email protected]>

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.

Fixes 3031313eb3d54 ("kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()")
---
 kernel/kprobes.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
kernel/kprobes.c +8 -8
index 3050631e528d..a35074f0daa1 100644
@@ -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.35.1