* [PATCH v2] tracing/probes: fix race between probe execution and event file removal
@ 2026-12-02 16:23 Antoine Tenart
2026-12-02 16:33 ` Steven Rostedt
2026-12-02 16:45 ` sashiko-bot
0 siblings, 2 replies; 13+ messages in thread
From: Antoine Tenart @ 2026-12-02 16:23 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers
Cc: Antoine Tenart, vmalik, linux-kernel, linux-trace-kernel,
Uladzislau Rezki (Sony)
A probe being executed can race with its unregistration happening on a
different CPU and lead to a UaF, which can trigger KASAN or crash the
kernel.
BUG: KASAN: slab-use-after-free in kretprobe_trace_func+0x68d/0x7e0
Read of size 8 at addr ffff888173328390 by task hammer/1619
CPU: 32 UID: 0 PID: 1619 Comm: hammer Tainted: G S 7.4.0-rc1+ #1 PREEMPT(lazy)
Call Trace:
kretprobe_trace_func+0x68d/0x7e0
kretprobe_dispatcher+0x128/0x220
kretprobe_rethook_handler+0x10f/0x1d0
rethook_trampoline_handler+0x181/0x510
arch_rethook_trampoline_callback+0xcd/0x160
arch_rethook_trampoline+0x2c/0x60
entry_SYSCALL_64_after_hwframe+0x76/0x7e
The race is the following:
CPU 0 CPU 1
kretprobe_dispatcher
kretprobe_trace_func
file = link->file
disable_trace_kprobe
trace_probe_remove_file
// Frees link after an RCU grace period.
kvfree_rcu_mightsleep(link)
unregister_trace_kprobe
unregister_kprobe_event
probe_remove_event_call
event_remove
remove_event_from_tracers
// Frees link->file.
event_file_put
// UaF.
file->...
Looking back at history, disable_trace_kprobe used to have the following
snippet:
/* Synchronize with kprobe_trace_func/kretprobe_trace_func
* to ensure disabled (all running handlers are finished).
* This is not only for kfree(), but also the caller,
* trace_remove_event_call() supposes it for releasing
* event_call related objects, which will be accessed in
* the kprobe_trace_func/kretprobe_trace_func.
*/
synchronize_rcu();
kfree(link);
It made clear synchronize_rcu was not only there for link users, but
also related objects. The comment was lost during refactoring in
b5f935ee1339 ("tracing/probe: Add trace_event_file access APIs for
trace_probe") but synchronize_rcu stayed, in trace_probe_remove_file.
Later, a6ed2aee5464 ("tracing: Switch to kvfree_rcu() API") removed the
synchronize_rcu/kfree pair into a single kvfree_rcu call. This works for
freeing the link but the side effect of protecting related objects was
lost, leading to the UaF described here.
We do not want to put back the synchronize_rcu call as it has a
noticeable impact when removing probes. Instead, defer the freeing of
the link after an RCU grace period.
The other snippet of the commit mentioned in the Fixes tag was fixed in commit
fe58f457ad8d ("tracing/osnoise: Call synchronize_rcu() when unregistering").
Fixes: a6ed2aee5464 ("tracing: Switch to kvfree_rcu() API")
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
Since v1:
- Do not add back the synchronize_rcu() call and use Steven's suggestion
instead (freeing the object after an RCU grace period).
kernel/trace/trace_probe.c | 11 ++++++++++-
kernel/trace/trace_probe.h | 1 +
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index cff55dcae36f..c249256dea80 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -2812,6 +2812,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file)
return -ENOMEM;
link->file = file;
+ event_file_get(file);
INIT_LIST_HEAD(&link->list);
list_add_tail_rcu(&link->list, &tp->event->files);
trace_probe_set_flag(tp, TP_FLAG_TRACE);
@@ -2831,6 +2832,14 @@ struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
return NULL;
}
+static void free_link_rcu(struct rcu_head *rcu)
+{
+ struct event_file_link *link = container_of(rcu, struct event_file_link, rcu);
+
+ event_file_put(link->file);
+ kvfree(link);
+}
+
int trace_probe_remove_file(struct trace_probe *tp,
struct trace_event_file *file)
{
@@ -2841,7 +2850,7 @@ int trace_probe_remove_file(struct trace_probe *tp,
return -ENOENT;
list_del_rcu(&link->list);
- kvfree_rcu_mightsleep(link);
+ call_rcu(&link->rcu, free_link_rcu);
if (list_empty(&tp->event->files))
trace_probe_clear_flag(tp, TP_FLAG_TRACE);
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index d1fb3520700f..aecc9f24951d 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -281,6 +281,7 @@ struct trace_probe {
struct event_file_link {
struct trace_event_file *file;
struct list_head list;
+ struct rcu_head rcu;
};
static inline unsigned int trace_probe_load_flag(struct trace_probe *tp)
--
2.56.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-02 16:23 [PATCH v2] tracing/probes: fix race between probe execution and event file removal Antoine Tenart @ 2026-12-02 16:33 ` Steven Rostedt 2026-12-03 1:20 ` Masami Hiramatsu (Google) 2026-12-02 16:45 ` sashiko-bot 1 sibling, 1 reply; 13+ messages in thread From: Steven Rostedt @ 2026-12-02 16:33 UTC (permalink / raw) To: Antoine Tenart Cc: mhiramat, mathieu.desnoyers, vmalik, linux-kernel, linux-trace-kernel, Uladzislau Rezki (Sony) On Wed, 2 Dec 2026 17:23:07 +0100 Antoine Tenart <atenart@kernel.org> wrote: > Since v1: > - Do not add back the synchronize_rcu() call and use Steven's suggestion > instead (freeing the object after an RCU grace period). Masami, If you ack this, I can take this and my patch through the trace/urgent push I'm working on. Otherwise, you can push this through your branch (if you have something already brewing) and I'll push my patch through my branch. -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-02 16:33 ` Steven Rostedt @ 2026-12-03 1:20 ` Masami Hiramatsu (Google) 2026-12-03 2:06 ` Steven Rostedt 0 siblings, 1 reply; 13+ messages in thread From: Masami Hiramatsu (Google) @ 2026-12-03 1:20 UTC (permalink / raw) To: Steven Rostedt Cc: Antoine Tenart, mathieu.desnoyers, vmalik, linux-kernel, linux-trace-kernel, Uladzislau Rezki (Sony) On Wed, 2 Dec 2026 11:33:56 -0500, Steven Rostedt <rostedt@goodmis.org> wrote: > On Wed, 2 Dec 2026 17:23:07 +0100 > Antoine Tenart <atenart@kernel.org> wrote: > > > > Since v1: > > - Do not add back the synchronize_rcu() call and use Steven's suggestion > > instead (freeing the object after an RCU grace period). > > Masami, > > If you ack this, I can take this and my patch through the trace/urgent push > I'm working on. Otherwise, you can push this through your branch (if you > have something already brewing) and I'll push my patch through my branch. I can pick this but it still has a sashiko's comment. Should we wait for v3 to fix sashiko's comment? Thank you, > > -- Steve > -- Masami Hiramatsu (Google) <mhiramat@kernel.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-03 1:20 ` Masami Hiramatsu (Google) @ 2026-12-03 2:06 ` Steven Rostedt 2026-12-04 3:05 ` Masami Hiramatsu (Google) 0 siblings, 1 reply; 13+ messages in thread From: Steven Rostedt @ 2026-12-03 2:06 UTC (permalink / raw) To: Masami Hiramatsu (Google) Cc: Antoine Tenart, mathieu.desnoyers, vmalik, linux-kernel, linux-trace-kernel, Uladzislau Rezki (Sony) On Thu, 03 Dec 2026 10:20:33 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > On Wed, 2 Dec 2026 11:33:56 -0500, Steven Rostedt <rostedt@goodmis.org> wrote: > > On Wed, 2 Dec 2026 17:23:07 +0100 > > Antoine Tenart <atenart@kernel.org> wrote: > > > > > > > Since v1: > > > - Do not add back the synchronize_rcu() call and use Steven's suggestion > > > instead (freeing the object after an RCU grace period). > > > > Masami, > > > > If you ack this, I can take this and my patch through the trace/urgent push > > I'm working on. Otherwise, you can push this through your branch (if you > > have something already brewing) and I'll push my patch through my branch. > > I can pick this but it still has a sashiko's comment. > Should we wait for v3 to fix sashiko's comment? > I believe the Sashiko comment is a separate issue that could be handled separately. -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-03 2:06 ` Steven Rostedt @ 2026-12-04 3:05 ` Masami Hiramatsu (Google) 0 siblings, 0 replies; 13+ messages in thread From: Masami Hiramatsu (Google) @ 2026-12-04 3:05 UTC (permalink / raw) To: rostedt Cc: Antoine Tenart, mathieu.desnoyers, vmalik, linux-kernel, linux-trace-kernel, Uladzislau Rezki (Sony) On Wed, 2 Dec 2026 21:06:31 -0500, Steven Rostedt <rostedt@goodmis.org> wrote: > On Thu, 03 Dec 2026 10:20:33 +0900 > "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > > > I can pick this but it still has a sashiko's comment. > > Should we wait for v3 to fix sashiko's comment? > > > > I believe the Sashiko comment is a separate issue that could be handled > separately. Agreed, so Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Thank you, -- Masami Hiramatsu (Google) <mhiramat@kernel.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-02 16:23 [PATCH v2] tracing/probes: fix race between probe execution and event file removal Antoine Tenart 2026-12-02 16:33 ` Steven Rostedt @ 2026-12-02 16:45 ` sashiko-bot 2026-12-02 18:45 ` Steven Rostedt 1 sibling, 1 reply; 13+ messages in thread From: sashiko-bot @ 2026-12-02 16:45 UTC (permalink / raw) To: Antoine Tenart; +Cc: linux-trace-kernel Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] tracing/probes: UAF on file->filter and file->tr after free_link_rcu() -- commit e46b0b6beaf53f9316361be522e07400739512b0 Author: Antoine Tenart <atenart@kernel.org> tracing/probes: fix race between probe execution and event file removal This commit takes an event_file_get() reference on link->file in trace_probe_add_file() and releases it via call_rcu() in trace_probe_remove_file() so link->file is not freed while a probe handler is still running. > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c > index cff55dcae36f2..c249256dea80d 100644 > --- a/kernel/trace/trace_probe.c > +++ b/kernel/trace/trace_probe.c > @@ -2812,6 +2812,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file) > return -ENOMEM; > > link->file = file; > + event_file_get(file); > INIT_LIST_HEAD(&link->list); > list_add_tail_rcu(&link->list, &tp->event->files); > trace_probe_set_flag(tp, TP_FLAG_TRACE); > @@ -2831,6 +2832,14 @@ struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp, > return NULL; > } > > +static void free_link_rcu(struct rcu_head *rcu) > +{ > + struct event_file_link *link = container_of(rcu, struct event_file_link, rcu); > + > + event_file_put(link->file); > + kvfree(link); > +} > + > int trace_probe_remove_file(struct trace_probe *tp, > struct trace_event_file *file) > { > @@ -2841,7 +2850,7 @@ int trace_probe_remove_file(struct trace_probe *tp, > return -ENOENT; > > list_del_rcu(&link->list); > - kvfree_rcu_mightsleep(link); > + call_rcu(&link->rcu, free_link_rcu); [Severity: High] Can an in-flight probe handler still hit a use-after-free on file->filter or file->tr even with event_file_get() holding a reference on file? event_file_get() only delays freeing the struct trace_event_file slab object itself; it does not delay the teardown of sub-objects hanging off file when trace_probe_remove_file() returns without waiting for an RCU grace period. CPU0 CPU1 kretprobe_trace_func() file = link->file disable_trace_kprobe() trace_probe_remove_file() list_del_rcu(&link->list) call_rcu(&link->rcu, free_link_rcu) unregister_trace_kprobe() unregister_kprobe_event() ... remove_event_file_dir() free_event_filter(file->filter) file->flags |= EVENT_FILE_FL_FREED event_file_put(file) __kretprobe_trace_func() trace_event_buffer_commit() __event_trigger_test_discard() filter_match_preds(file->filter, ...) <-- use-after-free on file->filter remove_event_file_dir() frees file->filter synchronously before calling event_file_put() and leaves EVENT_FILE_FL_FILTERED set in file->flags. Similarly, during trace instance removal (__remove_instance() -> event_trace_del_tracer()), tracepoint_synchronize_unregister() only waits on tracepoint_srcu and rcu_tasks_trace rather than standard RCU, so __remove_instance() can free tr->array_buffer.buffer and tr while an in-flight probe handler is still accessing link->file->tr. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202162333.168965-1-atenart@kernel.org?part=1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-02 16:45 ` sashiko-bot @ 2026-12-02 18:45 ` Steven Rostedt 2026-12-03 2:03 ` Masami Hiramatsu (Google) 0 siblings, 1 reply; 13+ messages in thread From: Steven Rostedt @ 2026-12-02 18:45 UTC (permalink / raw) To: sashiko-bot; +Cc: sashiko-reviews, Antoine Tenart, linux-trace-kernel On Wed, 02 Dec 2026 16:45:48 +0000 sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [High] tracing/probes: UAF on file->filter and file->tr after > free_link_rcu() > -- > > commit e46b0b6beaf53f9316361be522e07400739512b0 > Author: Antoine Tenart <atenart@kernel.org> > > tracing/probes: fix race between probe execution and event file removal > > This commit takes an event_file_get() reference on link->file in > trace_probe_add_file() and releases it via call_rcu() in > trace_probe_remove_file() so link->file is not freed while a probe handler > is still running. > > > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c > > index cff55dcae36f2..c249256dea80d 100644 > > --- a/kernel/trace/trace_probe.c > > +++ b/kernel/trace/trace_probe.c > > @@ -2812,6 +2812,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file) > > return -ENOMEM; > > > > link->file = file; > > + event_file_get(file); > > INIT_LIST_HEAD(&link->list); > > list_add_tail_rcu(&link->list, &tp->event->files); > > trace_probe_set_flag(tp, TP_FLAG_TRACE); > > @@ -2831,6 +2832,14 @@ struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp, > > return NULL; > > } > > > > +static void free_link_rcu(struct rcu_head *rcu) > > +{ > > + struct event_file_link *link = container_of(rcu, struct event_file_link, rcu); > > + > > + event_file_put(link->file); > > + kvfree(link); > > +} > > + > > int trace_probe_remove_file(struct trace_probe *tp, > > struct trace_event_file *file) > > { > > @@ -2841,7 +2850,7 @@ int trace_probe_remove_file(struct trace_probe *tp, > > return -ENOENT; > > > > list_del_rcu(&link->list); > > - kvfree_rcu_mightsleep(link); > > + call_rcu(&link->rcu, free_link_rcu); > > [Severity: High] > Can an in-flight probe handler still hit a use-after-free on file->filter > or file->tr even with event_file_get() holding a reference on file? > > event_file_get() only delays freeing the struct trace_event_file slab > object itself; it does not delay the teardown of sub-objects hanging off > file when trace_probe_remove_file() returns without waiting for an RCU > grace period. > > CPU0 CPU1 > kretprobe_trace_func() > file = link->file > disable_trace_kprobe() > trace_probe_remove_file() > list_del_rcu(&link->list) > call_rcu(&link->rcu, free_link_rcu) > unregister_trace_kprobe() > unregister_kprobe_event() > ... > remove_event_file_dir() > free_event_filter(file->filter) > file->flags |= EVENT_FILE_FL_FREED > event_file_put(file) > __kretprobe_trace_func() > trace_event_buffer_commit() > __event_trigger_test_discard() > filter_match_preds(file->filter, ...) > <-- use-after-free on file->filter > > remove_event_file_dir() frees file->filter synchronously before calling > event_file_put() and leaves EVENT_FILE_FL_FILTERED set in file->flags. I wonder if you had put a lore link to my suggestion if Sashiko would have know that we cover this. > > Similarly, during trace instance removal (__remove_instance() -> > event_trace_del_tracer()), tracepoint_synchronize_unregister() only waits > on tracepoint_srcu and rcu_tasks_trace rather than standard RCU, so > __remove_instance() can free tr->array_buffer.buffer and tr while an > in-flight probe handler is still accessing link->file->tr. > Now this can be an issue where kprobes and tracing use two different synchronization methods. Kprobes uses RCU where as tracing uses RCU tasks. -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-02 18:45 ` Steven Rostedt @ 2026-12-03 2:03 ` Masami Hiramatsu (Google) 2026-12-03 13:11 ` Steven Rostedt 2026-12-04 3:29 ` [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu Masami Hiramatsu (Google) 0 siblings, 2 replies; 13+ messages in thread From: Masami Hiramatsu (Google) @ 2026-12-03 2:03 UTC (permalink / raw) To: Steven Rostedt Cc: sashiko-bot, sashiko-reviews, Antoine Tenart, linux-trace-kernel On Wed, 2 Dec 2026 13:45:34 -0500, Steven Rostedt <rostedt@goodmis.org> wrote: > On Wed, 02 Dec 2026 16:45:48 +0000 > sashiko-bot@kernel.org wrote: > > > Thank you for your contribution! Sashiko AI review found 1 potential > > issue to consider: > > - [High] tracing/probes: UAF on file->filter and file->tr after > > free_link_rcu() > > -- > > > > commit e46b0b6beaf53f9316361be522e07400739512b0 > > Author: Antoine Tenart <atenart@kernel.org> > > > > tracing/probes: fix race between probe execution and event file removal > > > > This commit takes an event_file_get() reference on link->file in > > trace_probe_add_file() and releases it via call_rcu() in > > trace_probe_remove_file() so link->file is not freed while a probe handler > > is still running. > > > > > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c > > > index cff55dcae36f2..c249256dea80d 100644 > > > --- a/kernel/trace/trace_probe.c > > > +++ b/kernel/trace/trace_probe.c > > > @@ -2812,6 +2812,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file) > > > return -ENOMEM; > > > > > > link->file = file; > > > + event_file_get(file); > > > INIT_LIST_HEAD(&link->list); > > > list_add_tail_rcu(&link->list, &tp->event->files); > > > trace_probe_set_flag(tp, TP_FLAG_TRACE); > > > @@ -2831,6 +2832,14 @@ struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp, > > > return NULL; > > > } > > > > > > +static void free_link_rcu(struct rcu_head *rcu) > > > +{ > > > + struct event_file_link *link = container_of(rcu, struct event_file_link, rcu); > > > + > > > + event_file_put(link->file); > > > + kvfree(link); > > > +} > > > + > > > int trace_probe_remove_file(struct trace_probe *tp, > > > struct trace_event_file *file) > > > { > > > @@ -2841,7 +2850,7 @@ int trace_probe_remove_file(struct trace_probe *tp, > > > return -ENOENT; > > > > > > list_del_rcu(&link->list); > > > - kvfree_rcu_mightsleep(link); > > > + call_rcu(&link->rcu, free_link_rcu); > > > > [Severity: High] > > Can an in-flight probe handler still hit a use-after-free on file->filter > > or file->tr even with event_file_get() holding a reference on file? > > > > event_file_get() only delays freeing the struct trace_event_file slab > > object itself; it does not delay the teardown of sub-objects hanging off > > file when trace_probe_remove_file() returns without waiting for an RCU > > grace period. > > > > CPU0 CPU1 > > kretprobe_trace_func() > > file = link->file > > disable_trace_kprobe() > > trace_probe_remove_file() > > list_del_rcu(&link->list) > > call_rcu(&link->rcu, free_link_rcu) > > unregister_trace_kprobe() > > unregister_kprobe_event() > > ... > > remove_event_file_dir() > > free_event_filter(file->filter) > > file->flags |= EVENT_FILE_FL_FREED > > event_file_put(file) > > __kretprobe_trace_func() > > trace_event_buffer_commit() > > __event_trigger_test_discard() > > filter_match_preds(file->filter, ...) > > <-- use-after-free on file->filter > > > > remove_event_file_dir() frees file->filter synchronously before calling > > event_file_put() and leaves EVENT_FILE_FL_FILTERED set in file->flags. > > I wonder if you had put a lore link to my suggestion if Sashiko would have > know that we cover this. > > > > > Similarly, during trace instance removal (__remove_instance() -> > > event_trace_del_tracer()), tracepoint_synchronize_unregister() only waits > > on tracepoint_srcu and rcu_tasks_trace rather than standard RCU, so > > __remove_instance() can free tr->array_buffer.buffer and tr while an > > in-flight probe handler is still accessing link->file->tr. > > > > Now this can be an issue where kprobes and tracing use two different > synchronization methods. Kprobes uses RCU where as tracing uses RCU tasks. Yes, we need to solve this. Hmm, to solve this issue we can take guard(srcu_fast_notrace)(&tracepoint_srcu) in all probe event handlers? Thanks, -- Masami Hiramatsu (Google) <mhiramat@kernel.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-03 2:03 ` Masami Hiramatsu (Google) @ 2026-12-03 13:11 ` Steven Rostedt 2026-12-03 14:36 ` Masami Hiramatsu (Google) 2026-12-04 3:29 ` [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu Masami Hiramatsu (Google) 1 sibling, 1 reply; 13+ messages in thread From: Steven Rostedt @ 2026-12-03 13:11 UTC (permalink / raw) To: Masami Hiramatsu (Google) Cc: sashiko-bot, sashiko-reviews, Antoine Tenart, linux-trace-kernel On Thu, 03 Dec 2026 11:03:54 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > Yes, we need to solve this. Hmm, to solve this issue we can take > guard(srcu_fast_notrace)(&tracepoint_srcu) in all probe event handlers? I'm actually looking at removing tracepoint_srcu and using guard(rcu_tasks_trace)() everywhere. It looks like that is basically the equivalent to tracepoint_srcu. -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-03 13:11 ` Steven Rostedt @ 2026-12-03 14:36 ` Masami Hiramatsu (Google) 2026-12-03 15:37 ` Steven Rostedt 0 siblings, 1 reply; 13+ messages in thread From: Masami Hiramatsu (Google) @ 2026-12-03 14:36 UTC (permalink / raw) To: Steven Rostedt Cc: sashiko-bot, sashiko-reviews, Antoine Tenart, linux-trace-kernel On Thu, 3 Dec 2026 08:11:57 -0500, Steven Rostedt <rostedt@goodmis.org> wrote: > On Thu, 03 Dec 2026 11:03:54 +0900 > "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > > > Yes, we need to solve this. Hmm, to solve this issue we can take > > guard(srcu_fast_notrace)(&tracepoint_srcu) in all probe event handlers? > > I'm actually looking at removing tracepoint_srcu and using > guard(rcu_tasks_trace)() everywhere. It looks like that is basically the > equivalent to tracepoint_srcu. Hmm, but it seems `guard(rcu_tasks_trace)()` can kick a lockdep and may be fragile to NMI. Isn't it better to use (unify to) `guard(srcu_fast_notrace)(&tracepoint_srcu)` or introduce an new `guard(rcu_tasks_trace_notrace)()` which based on local variable (T) and avoid calling lockdep? Thank you, -- Masami Hiramatsu (Google) <mhiramat@kernel.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal 2026-12-03 14:36 ` Masami Hiramatsu (Google) @ 2026-12-03 15:37 ` Steven Rostedt 0 siblings, 0 replies; 13+ messages in thread From: Steven Rostedt @ 2026-12-03 15:37 UTC (permalink / raw) To: Masami Hiramatsu (Google) Cc: sashiko-bot, sashiko-reviews, Antoine Tenart, linux-trace-kernel On Thu, 03 Dec 2026 23:36:19 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > Hmm, but it seems `guard(rcu_tasks_trace)()` can kick a lockdep and may be > fragile to NMI. Isn't it better to use (unify to) > `guard(srcu_fast_notrace)(&tracepoint_srcu)` or introduce an new > `guard(rcu_tasks_trace_notrace)()` which based on local variable (T) > and avoid calling lockdep? Hmm, I guess we could switch everything to tracepoint_srcu as that can sleep and handle faults. -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu 2026-12-03 2:03 ` Masami Hiramatsu (Google) 2026-12-03 13:11 ` Steven Rostedt @ 2026-12-04 3:29 ` Masami Hiramatsu (Google) 2026-12-04 3:57 ` sashiko-bot 1 sibling, 1 reply; 13+ messages in thread From: Masami Hiramatsu (Google) @ 2026-12-04 3:29 UTC (permalink / raw) To: Steven Rostedt, Mathieu Desnoyers Cc: Antoine Tenart, linux-trace-kernel, linux-kernel Since commit a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast"), tracepoint_synchronize_unregister() waits only on rcu_tasks_trace and tracepoint_srcu, and no longer waits for a standard RCU grace period. However, kprobe, fprobe, and uprobe event dispatchers still execute only under standard RCU protection. Once trace_probe_remove_file() defers releasing event_file_link and trace_event_file via call_rcu() without an inline synchronize_rcu(), teardown paths that synchronize via tracepoint_synchronize_unregister() -- such as event_trace_del_tracer(), __ftrace_clear_event_pids(), trigger_data_free(), and perf_trace_event_unreg() -- can free trace_array (file->tr), ring buffers, PID filter lists, trigger data, or perf state while a probe handler is still running. Guard the kprobe, kretprobe, fentry, fexit, uprobe, and uretprobe dispatchers with guard(srcu_fast_notrace)(&tracepoint_srcu) so that probe execution is synchronized with tracepoint_synchronize_unregister() while keeping standard RCU protection for call_rcu()-freed objects and avoiding inline synchronize_rcu() in trace_probe_remove_file(). Also update the stale synchronization comments in disable_trace_kprobe(), disable_trace_fprobe(), and disable_trace_eprobe(). Fixes: a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast") Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> --- kernel/trace/trace_eprobe.c | 5 ++++- kernel/trace/trace_fprobe.c | 16 ++++++++++------ kernel/trace/trace_kprobe.c | 13 ++++++++----- kernel/trace/trace_uprobe.c | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index f65393fb1c10..9e9b2e53b42d 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -711,7 +711,10 @@ static int disable_trace_eprobe(struct trace_event_call *call, for_each_trace_eprobe_tp(ep, tp) disable_eprobe(ep, file->tr); - /* Synchronization is done in below function. */ + /* + * disable_eprobe() synchronizes via tracepoint_synchronize_unregister(), + * and trace_probe_remove_file() defers freeing link and file via call_rcu(). + */ trace_probe_remove_file(tp, file); return 0; diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 9ab0871a6461..1152ec6f1f02 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -519,9 +519,11 @@ static int fentry_dispatcher(struct fprobe *fp, unsigned long entry_ip, void *entry_data) { struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); - unsigned int flags = trace_probe_load_flag(&tf->tp); + unsigned int flags; int ret = 0; + guard(srcu_fast_notrace)(&tracepoint_srcu); + flags = trace_probe_load_flag(&tf->tp); if (flags & TP_FLAG_TRACE) fentry_trace_func(tf, entry_ip, fregs); @@ -538,8 +540,10 @@ static void fexit_dispatcher(struct fprobe *fp, unsigned long entry_ip, void *entry_data) { struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); - unsigned int flags = trace_probe_load_flag(&tf->tp); + unsigned int flags; + guard(srcu_fast_notrace)(&tracepoint_srcu); + flags = trace_probe_load_flag(&tf->tp); if (flags & TP_FLAG_TRACE) fexit_trace_func(tf, entry_ip, ret_ip, fregs, entry_data); #ifdef CONFIG_PERF_EVENTS @@ -1530,10 +1534,10 @@ static int disable_trace_fprobe(struct trace_event_call *call, out: if (file) /* - * Synchronization is done in below function. For perf event, - * file == NULL and perf_trace_event_unreg() calls - * tracepoint_synchronize_unregister() to ensure synchronize - * event. We don't need to care about it. + * trace_probe_remove_file() defers releasing link and file + * via call_rcu(). Teardown paths (e.g. event_trace_del_tracer(), + * perf_trace_event_unreg()) synchronize with in-flight + * dispatchers via tracepoint_synchronize_unregister(). */ trace_probe_remove_file(tp, file); diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 1dd6a6942eb7..474c7fd8da61 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -437,10 +437,10 @@ static int disable_trace_kprobe(struct trace_event_call *call, out: if (file) /* - * Synchronization is done in below function. For perf event, - * file == NULL and perf_trace_event_unreg() calls - * tracepoint_synchronize_unregister() to ensure synchronize - * event. We don't need to care about it. + * trace_probe_remove_file() defers releasing link and file + * via call_rcu(). Teardown paths (e.g. event_trace_del_tracer(), + * perf_trace_event_unreg()) synchronize with in-flight + * dispatchers via tracepoint_synchronize_unregister(). */ trace_probe_remove_file(tp, file); @@ -1834,11 +1834,13 @@ static int kprobe_register(struct trace_event_call *event, static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) { struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp); - unsigned int flags = trace_probe_load_flag(&tk->tp); + unsigned int flags; int ret = 0; raw_cpu_inc(*tk->nhit); + guard(srcu_fast_notrace)(&tracepoint_srcu); + flags = trace_probe_load_flag(&tk->tp); if (flags & TP_FLAG_TRACE) kprobe_trace_func(tk, regs); #ifdef CONFIG_PERF_EVENTS @@ -1867,6 +1869,7 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) tk = container_of(rp, struct trace_kprobe, rp); raw_cpu_inc(*tk->nhit); + guard(srcu_fast_notrace)(&tracepoint_srcu); flags = trace_probe_load_flag(&tk->tp); if (flags & TP_FLAG_TRACE) kretprobe_trace_func(tk, ri, regs); diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index fb7991543db7..a53ffd8b2790 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -1569,6 +1569,7 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs, if (WARN_ON_ONCE(!uprobe_cpu_buffer)) return 0; + guard(srcu_fast_notrace)(&tracepoint_srcu); flags = trace_probe_load_flag(&tu->tp); if (flags & TP_FLAG_TRACE) ret |= uprobe_trace_func(tu, regs, &ucb); @@ -1600,6 +1601,7 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con, if (WARN_ON_ONCE(!uprobe_cpu_buffer)) return 0; + guard(srcu_fast_notrace)(&tracepoint_srcu); flags = trace_probe_load_flag(&tu->tp); if (flags & TP_FLAG_TRACE) uretprobe_trace_func(tu, func, regs, &ucb); -- 2.43.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu 2026-12-04 3:29 ` [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu Masami Hiramatsu (Google) @ 2026-12-04 3:57 ` sashiko-bot 0 siblings, 0 replies; 13+ messages in thread From: sashiko-bot @ 2026-12-04 3:57 UTC (permalink / raw) To: Masami Hiramatsu (Google); +Cc: linux-trace-kernel Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] tracing/uprobe: tracepoint_srcu held across faultable and sleepable paths - [Medium] tracing/kprobes: missing rcu_is_watching() check before SRCU-fast guard - [Low] tracing/probes: comments misstate trace_probe_remove_file() RCU lifetime -- commit d2d94f4e6bcf3ecc5841896141107d3fa875d240 Author: Masami Hiramatsu (Google) <mhiramat@kernel.org> tracing/probes: Guard probe dispatchers with tracepoint_srcu This commit wraps the kprobe, kretprobe, fentry, fexit, uprobe, and uretprobe dispatchers in guard(srcu_fast_notrace)(&tracepoint_srcu) so they synchronize with tracepoint_synchronize_unregister(). It also updates the comments above trace_probe_remove_file() in the eprobe, fprobe, and kprobe disable paths. > diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c > index f65393fb1c102..9e9b2e53b42d2 100644 > --- a/kernel/trace/trace_eprobe.c > +++ b/kernel/trace/trace_eprobe.c > @@ -711,7 +711,10 @@ static int disable_trace_eprobe(struct trace_event_call *call, > for_each_trace_eprobe_tp(ep, tp) > disable_eprobe(ep, file->tr); > > - /* Synchronization is done in below function. */ > + /* > + * disable_eprobe() synchronizes via tracepoint_synchronize_unregister(), > + * and trace_probe_remove_file() defers freeing link and file via call_rcu(). > + */ > trace_probe_remove_file(tp, file); [Severity: Low] Does trace_probe_remove_file() actually defer freeing file via call_rcu()? trace_probe_remove_file() only unlinks and frees the event_file_link via kvfree_rcu_mightsleep(link); it does not hold or release a reference to struct trace_event_file. Instead, remove_event_file_dir() frees file synchronously via event_file_put(). The same wording appears in the commit message, disable_trace_fprobe(), and disable_trace_kprobe(). The disable_trace_kprobe() comment also overstates teardown synchronization, since dynamic kprobe removal through unregister_trace_kprobe() -> trace_remove_event_call() frees file without calling tracepoint_synchronize_unregister(). [ ... ] > diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c > index 1dd6a6942eb7d..474c7fd8da614 100644 > --- a/kernel/trace/trace_kprobe.c > +++ b/kernel/trace/trace_kprobe.c [ ... ] > @@ -1834,11 +1834,13 @@ static int kprobe_register(struct trace_event_call *event, > static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) > { > struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp); > - unsigned int flags = trace_probe_load_flag(&tk->tp); > + unsigned int flags; > int ret = 0; > > raw_cpu_inc(*tk->nhit); > > + guard(srcu_fast_notrace)(&tracepoint_srcu); > + flags = trace_probe_load_flag(&tk->tp); > if (flags & TP_FLAG_TRACE) > kprobe_trace_func(tk, regs); > #ifdef CONFIG_PERF_EVENTS > @@ -1867,6 +1869,7 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) > tk = container_of(rp, struct trace_kprobe, rp); > raw_cpu_inc(*tk->nhit); > > + guard(srcu_fast_notrace)(&tracepoint_srcu); > flags = trace_probe_load_flag(&tk->tp); > if (flags & TP_FLAG_TRACE) > kretprobe_trace_func(tk, ri, regs); [Severity: Medium] Can kprobe_dispatcher() or kretprobe_dispatcher() enter guard(srcu_fast_notrace)(&tracepoint_srcu) while RCU is not watching? srcu_read_lock_fast_notrace() relies on synchronize_rcu() inside synchronize_srcu(&tracepoint_srcu) instead of a read-side smp_mb() and skips lockdep's !rcu_is_watching() check. Unlike fprobe callbacks, ftrace, optprobe, and rethook kprobe paths never check rcu_is_watching(). A kprobe on a non-noinstr, non-blacklisted function running while RCU is not watching (such as snooze_loop() in cpuidle-powernv.c after ct_cpuidle_enter(), or native_play_dead() after rcutree_report_cpu_dead()) can then run on a CPU ignored by synchronize_rcu(): CPU0 (RCU not watching) CPU1 kprobe_dispatcher() guard(srcu_fast_notrace)(...) event_trace_del_tracer() tracepoint_synchronize_unregister() synchronize_srcu(&tracepoint_srcu) synchronize_rcu() /* skips CPU0 */ free_trace_buffer(tr) kprobe_trace_func() ... dereferences file->tr <-- use-after-free Checking rcu_is_watching() (and excluding offline CPUs, since rcutree_report_cpu_dead() leaves CT_RCU_WATCHING set) before acquiring tracepoint_srcu would avoid this race. > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c > index fb7991543db7d..a53ffd8b27903 100644 > --- a/kernel/trace/trace_uprobe.c > +++ b/kernel/trace/trace_uprobe.c > @@ -1569,6 +1569,7 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs, > if (WARN_ON_ONCE(!uprobe_cpu_buffer)) > return 0; > > + guard(srcu_fast_notrace)(&tracepoint_srcu); > flags = trace_probe_load_flag(&tu->tp); > if (flags & TP_FLAG_TRACE) > ret |= uprobe_trace_func(tu, regs, &ucb); > @@ -1600,6 +1601,7 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con, > if (WARN_ON_ONCE(!uprobe_cpu_buffer)) > return 0; > > + guard(srcu_fast_notrace)(&tracepoint_srcu); > flags = trace_probe_load_flag(&tu->tp); > if (flags & TP_FLAG_TRACE) > uretprobe_trace_func(tu, func, regs, &ucb); [Severity: High] Will holding tracepoint_srcu across uprobe_dispatcher() and uretprobe_dispatcher() stall non-faultable tracepoint grace periods system-wide? Every caller in kernel/events/uprobes.c (handle_swbp(), handle_syscall_uprobe(), and handle_uretprobe_chain()) already holds rcu_read_lock_trace(), which tracepoint_synchronize_unregister() waits on via synchronize_rcu_tasks_trace(). Inside these dispatchers, prepare_uprobe_buffer() acquires mutex_lock(&ucb->mutex) and performs faultable user-memory reads (strnlen_user(), copy_from_user(), strncpy_from_user()), and __uprobe_perf_func() runs sleepable BPF programs. If a uprobe sleeps on a slow user page fault (for example via FUSE, NFS, or userfaultfd) or ucb->mutex, it stalls tracepoint_srcu grace periods. That blocks tp_rcu_cond_sync() under the global tracepoints_mutex for unrelated tracepoint register/unregister operations and delays call_srcu() cleanup. Dropping the tracepoint_srcu guard from both uprobe dispatchers keeps faultable readers on rcu_tasks_trace as intended. -- Sashiko AI review · https://sashiko.dev/#/patchset/undine-1796354989220575981-7aae146b9ada56e1@undined.local?part=1 ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-12-04 3:57 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 16:23 [PATCH v2] tracing/probes: fix race between probe execution and event file removal Antoine Tenart 2026-12-02 16:33 ` Steven Rostedt 2026-12-03 1:20 ` Masami Hiramatsu (Google) 2026-12-03 2:06 ` Steven Rostedt 2026-12-04 3:05 ` Masami Hiramatsu (Google) 2026-12-02 16:45 ` sashiko-bot 2026-12-02 18:45 ` Steven Rostedt 2026-12-03 2:03 ` Masami Hiramatsu (Google) 2026-12-03 13:11 ` Steven Rostedt 2026-12-03 14:36 ` Masami Hiramatsu (Google) 2026-12-03 15:37 ` Steven Rostedt 2026-12-04 3:29 ` [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu Masami Hiramatsu (Google) 2026-12-04 3:57 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox