public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Cacheux <paulcacheux@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Paul Cacheux via B4 Relay
	<devnull+paulcacheux.gmail.com@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org,
	 linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing: fix race when creating trace probe log error message
Date: Thu, 01 May 2025 22:56:44 +0200	[thread overview]
Message-ID: <0b13bbd0001c41ca1866ccf58f6e9de6ca2c24d9.camel@gmail.com> (raw)
In-Reply-To: <20250501154503.2308f177@gandalf.local.home>

On Thu, 2025-05-01 at 15:45 -0400, Steven Rostedt wrote:
> On Tue, 22 Apr 2025 20:33:13 +0200
> Paul Cacheux via B4 Relay <devnull+paulcacheux.gmail.com@kernel.org>
> wrote:
> 
> > From: Paul Cacheux <paulcacheux@gmail.com>
> 
> Sorry for the late reply, I just noticed this patch.

No problem at all, thanks for looking at my patch.

> 
> > 
> > When creating a trace probe a global variable is modified and this
> > data used when an error is raised and the error message generated.
> > 
> > Modification of this global variable is done without any lock and
> > multiple trace operations will race, causing some potential issues
> > when generating the error.
> > 
> > This commit moves away from the global variable and passes the
> > error context as a regular function argument.
> > 
> > Fixes: ab105a4fb894 ("tracing: Use tracing error_log with probe
> > events")
> > 
> > Signed-off-by: Paul Cacheux <paulcacheux@gmail.com>
> > ---
> > As reported in [1] a race exists in the shared trace probe log
> > used to build error messages. This can cause kernel crashes
> > when building the actual error message, but the race happens
> > even for non-error tracefs uses, it's just not visible.
> > 
> > Reproducer first reported that is still crashing:
> > 
> >   # 'p4' is invalid command which make kernel run into
> > trace_probe_log_err()
> >   cd /sys/kernel/debug/tracing
> >   while true; do
> >     echo 'p4:myprobe1 do_sys_openat2 dfd=%ax filename=%dx flags=%cx
> > mode=+4($stack)' >> kprobe_events &
> >     echo 'p4:myprobe2 do_sys_openat2' >> kprobe_events &
> >     echo 'p4:myprobe3 do_sys_openat2 dfd=%ax filename=%dx' >>
> > kprobe_events &
> >   done;
> > 
> > The original email suggested to use a mutex or to allocate the
> > trace_probe_log on the stack. The mutex can cause performance
> > issues, and require high confidence in the correctness of the
> > current trace_probe_log_clear calls. This patch implements
> > the stack solution instead and passes a pointer to using
> > functions.
> > 
> > [1]
> > https://lore.kernel.org/all/20221121081103.3070449-1-zhengyejian1@huawei.com/T/
> 
> Honestly, I don't like either approach.
> 
> What could be done is wrap the internals of the function in a mutex
> so they
> are not re-entrant (using guard(mutex)). If two error codes are
> happening
> together, just let it get corrupted. There should never be two
> additions at
> the same time, and if the admin is doing that then they deserve what
> they
> get.

Just to double check, what you are suggesting here is to include a
mutex in the shared trace_probe_log entry, and to lock it in all
accessors functions (trace_probe_log_{init,set_index,clear,err})?

> 
> I don't care if the error log gets garbage if there's multiple
> accesses at
> the same time. The fix should only prevent it from crashing.
> 
> -- Steve
> 
> 
> -- Steve

Thanks for the feedback,
Paul Cacheux

  reply	other threads:[~2025-05-01 20:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 18:33 [PATCH] tracing: fix race when creating trace probe log error message Paul Cacheux via B4 Relay
2025-05-01 19:45 ` Steven Rostedt
2025-05-01 20:56   ` Paul Cacheux [this message]
2025-05-01 20: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=0b13bbd0001c41ca1866ccf58f6e9de6ca2c24d9.camel@gmail.com \
    --to=paulcacheux@gmail.com \
    --cc=devnull+paulcacheux.gmail.com@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 \
    /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