* [for-next][PATCH 0/3] probes: Updates for 6.2
@ 2022-12-10 14:03 Steven Rostedt
2022-12-10 14:03 ` [for-next][PATCH 1/3] tracing: Fix race where eprobes can be called before the event Steven Rostedt
2022-12-10 14:03 ` [for-next][PATCH 3/3] kprobes: Fix check for probe enabled in kill_kprobe() Steven Rostedt
0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-12-10 14:03 UTC (permalink / raw)
To: linux-kernel; +Cc: Masami Hiramatsu, Andrew Morton
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(-)
^ permalink raw reply [flat|nested] 3+ messages in thread* [for-next][PATCH 1/3] tracing: Fix race where eprobes can be called before the event
2022-12-10 14:03 [for-next][PATCH 0/3] probes: Updates for 6.2 Steven Rostedt
@ 2022-12-10 14:03 ` Steven Rostedt
2022-12-10 14:03 ` [for-next][PATCH 3/3] kprobes: Fix check for probe enabled in kill_kprobe() Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-12-10 14:03 UTC (permalink / raw)
To: linux-kernel; +Cc: Masami Hiramatsu, Andrew Morton, stable, Rafael Mendonca
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
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.
Link: https://lore.kernel.org/linux-trace-kernel/20221116192552.1066630-1-rafaelmendsr@gmail.com/
Link: https://lore.kernel.org/all/20221117214249.2addbe10@gandalf.local.home/
Cc: stable@vger.kernel.org
Fixes: 7491e2c442781 ("tracing: Add a probe that attaches to trace events")
Reported-by: Rafael Mendonca <rafaelmendsr@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
kernel/trace/trace_eprobe.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
index 123d2c0a6b68..352b65e2b910 100644
--- a/kernel/trace/trace_eprobe.c
+++ b/kernel/trace/trace_eprobe.c
@@ -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);
}
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [for-next][PATCH 3/3] kprobes: Fix check for probe enabled in kill_kprobe()
2022-12-10 14:03 [for-next][PATCH 0/3] probes: Updates for 6.2 Steven Rostedt
2022-12-10 14:03 ` [for-next][PATCH 1/3] tracing: Fix race where eprobes can be called before the event Steven Rostedt
@ 2022-12-10 14:03 ` Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-12-10 14:03 UTC (permalink / raw)
To: linux-kernel; +Cc: Masami Hiramatsu, Andrew Morton, Li Huafei
From: Li Huafei <lihuafei1@huawei.com>
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.
Link: https://lore.kernel.org/all/20221126114316.201857-1-lihuafei1@huawei.com/
Fixes: 3031313eb3d54 ("kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()")
Signed-off-by: Li Huafei <lihuafei1@huawei.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
kernel/kprobes.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 3050631e528d..a35074f0daa1 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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 */
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-10 14:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-10 14:03 [for-next][PATCH 0/3] probes: Updates for 6.2 Steven Rostedt
2022-12-10 14:03 ` [for-next][PATCH 1/3] tracing: Fix race where eprobes can be called before the event Steven Rostedt
2022-12-10 14:03 ` [for-next][PATCH 3/3] kprobes: Fix check for probe enabled in kill_kprobe() Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox