Linux Trace Kernel
 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] tracing: unwind trigger state when event enable fails
Date: Thu, 03 Dec 2026 18:11:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-248352@kernel.org> (raw)
In-Reply-To: <179620737571.2194197.8563884881260690416@skku.edu>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] tracing: double unwind underflows refs on hist_trigger_enable()
  failure
- [High] tracing: refcount underflow after enable_eprobe() ignores
  enable error
--

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

tracing: unwind trigger state when event enable fails

This commit updates trace_event_trigger_enable_disable() to undo the soft
enable, clear the recorded and trigger-mode flags, and decrement tm_ref
when trace_event_enable_disable() fails.

> 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);
> +		}

[Severity: High]
Can this double-unwind file->tm_ref and file->sm_ref when installing a
histogram trigger fails?

On error, hist_trigger_enable() leaves trigger_data on file->triggers so
event_hist_trigger_parse() cleans it up via hist_unregister_trigger().
That calls trace_event_trigger_enable_disable(file, 0) a second time,
underflowing file->tm_ref and file->sm_ref to -1.

It also runs an unbalanced trace_buffered_event_disable().  With
file->sm_ref at -1, __ftrace_event_enable_disable() keeps soft_mode true,
so a later normal enable and instance removal skip unregistering the event
callback and cause a use-after-free on the freed trace_event_file.

[Severity: High]
Will enable_eprobe() also underflow file->tm_ref and file->sm_ref when
enabling the target event fails?

enable_eprobe() in kernel/trace/trace_eprobe.c ignores the return value of
trace_event_trigger_enable_disable(file, 1) and leaves trigger on
file->triggers.  Because this patch now unwinds the refs on error, later
cleanup in disable_eprobe() underflows file->tm_ref and file->sm_ref to -1.

That also runs an unbalanced trace_buffered_event_disable(), and leaving
file->sm_ref at -1 keeps soft_mode true in __ftrace_event_enable_disable()
so a later enable and instance removal can cause a use-after-free.
enable_eprobe() should check the return value and unlink and free trigger.

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

      reply	other threads:[~2026-12-03 18:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:56 [PATCH] tracing: unwind trigger state when event enable fails Kyuwon Cho
2026-12-03 18:11 ` 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-248352@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox