Re: [PATCH] tracing/probes: fix race between probe execution and event unregistering
From: Antoine Tenart
Date: Tue Dec 01 2026 - 08:21:31 EST
On Fri, Nov 27, 2026 at 02:06:16PM -0500, Steven Rostedt wrote:
>
> Would something like this work? I haven't fully tested it though:
>
> 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);
While this defers freeing file, this unfortunately won't work because
this is not only about struct trace_event_file but also the pointers it
contains and the lifetime of those objects. E.g. accessing file->filter
will also cause UaF in trace_event_buffer_commit ->
__event_trigger_test_discard. (I haven't looked at the other pointers,
they might be problematic too).
Thanks!
Antoine