mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Antoine Tenart <atenart@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
	vmalik@redhat.com,  linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	 "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Subject: Re: [PATCH] tracing/probes: fix race between probe execution and event unregistering
Date: Tue, 1 Dec 2026 14:21:21 +0100	[thread overview]
Message-ID: <aw6PuVUNR81ggXMP@toolbx> (raw)
In-Reply-To: <20261127140616.20616c68@gandalf.local.home>

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

  parent reply	other threads:[~2026-12-01 13:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:28 Antoine Tenart
2026-11-27 19:06 ` Steven Rostedt
2026-11-28  2:31   ` Masami Hiramatsu (Google)
2026-12-01 13:21   ` Antoine Tenart [this message]
2026-12-01 13:58     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw6PuVUNR81ggXMP@toolbx \
    --to=atenart@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.com \
    --cc=vmalik@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®