All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwon.cho@skku.edu>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tracing: unwind trigger state when event enable fails
Date: Thu, 03 Dec 2026 20:10:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-248595@kernel.org> (raw)
In-Reply-To: <179632407670.3855722.18244996359414774386@skku.edu>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] tracing: unwind soft-mode state in
  __ftrace_event_enable_disable()
--

commit a525e3a4784142c4cf32486246b9686d2dbe57ae
Author: Kyuwon Cho <kyuwon.cho@skku.edu>

tracing: unwind trigger state when event enable fails

This commit unwinds trigger and soft-mode state in
trace_event_trigger_enable_disable() when enabling an event fails, and
updates histogram and eprobe error paths to remove failed triggers without
re-disabling the already unwound state.

> diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
> index a2487ad7fef85..f6ad7e5caf308 100644
> --- a/kernel/trace/trace_events_trigger.c
> +++ b/kernel/trace/trace_events_trigger.c
> @@ -610,6 +610,13 @@ int trace_event_trigger_enable_disable(struct trace_event_file *file,
>  			return ret;
>  		set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
>  		ret = trace_event_enable_disable(file, 1, 1);
> +		if (ret) {
> +			trace_event_enable_disable(file, 0, 1);
> +			clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
> +			clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
> +			clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
> +			atomic_dec(&file->tm_ref);
> +		}
>  	} else {
>  		if (atomic_dec_return(&file->tm_ref) > 0)
>  			return ret;

[Severity: High]
Should the soft-mode and flag cleanup happen inside
__ftrace_event_enable_disable() instead of working around it here?

When call->class->reg(call, TRACE_REG_REGISTER, file) fails,
__ftrace_event_enable_disable() leaves file->sm_ref,
trace_buffered_event_ref, EVENT_FILE_FL_SOFT_DISABLED_BIT, and
EVENT_FILE_FL_RECORDED_{CMD,TGID}_BIT set.

Working around that here reaches into RECORDED_{CMD,TGID}_BIT flags
internal to trace_events.c and leaves direct callers such as
event_enable_trigger_parse() and event_enable_func() leaking file->sm_ref
and trace_buffered_event_ref on enable failure.

Once file->sm_ref is leaked, trace instance removal via
event_trace_del_tracer() skips TRACE_REG_UNREGISTER and frees file while
the callback remains registered, causing a use-after-free.

On non-soft ftrace_event_enable_disable(file, 1) failures, the stale
RECORDED_{CMD,TGID}_BIT flags can also cause an unbalanced decrement and
underflow of sched_cmdline_ref or sched_tgid_ref in
tracing_stop_sched_switch().

Unwinding sm_ref, trace_buffered_event_enable(), and those flags in the
error path of __ftrace_event_enable_disable() fixes all callers and leaves
this function to clear only EVENT_FILE_FL_TRIGGER_MODE_BIT and
file->tm_ref.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179632407670.3855722.18244996359414774386@skku.edu?part=1

      reply	other threads:[~2026-12-03 20:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 19:49 [PATCH v2] tracing: unwind trigger state when event enable fails Kyuwon Cho
2026-12-03 20:10 ` sashiko-bot [this message]

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=sashiko-outbox-248595@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kyuwon.cho@skku.edu \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.