Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Donggeun Yoo" <donggeunyoo.kernel@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] tracing: hist: undo the registration when enabling the trigger fails
Date: Mon, 07 Sep 2026 13:01:05 +0000	[thread overview]
Message-ID: <20260907130105.94DD51F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260907124420.607097-3-donggeunyoo.kernel@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing cleanup in hist_register_trigger() on error path leads to UAF on named_triggers and memory leaks.
--

commit 49cdf06bdd569065174c429403dc447ea4cdf44e
Author: Donggeun Yoo <donggeunyoo.kernel@gmail.com>

tracing: hist: undo the registration when enabling the trigger fails

This commit fixes a use-after-free issue when a trigger fails to enable in
hist_trigger_enable(). It ensures that if
trace_event_trigger_enable_disable() fails, hist_unregister_trigger() will
properly undo the registration, preventing the trigger from being freed
while still on the named_triggers list.

Closes: https://lore.kernel.org/linux-trace-kernel/20260907092944.3950E1F00A3D@smtp.kernel.org/

> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index c6c04926bdf0c..1de224a5a2bba 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
[ ... ]
> @@ -6972,6 +6973,8 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
>  	return ret;
>   out_unreg:
>  	event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
> +	/* The unregister frees trigger_data, skip out_free */
> +	goto out;
>   out_free:

[Severity: High]
This is a pre-existing issue, but missing cleanup in the error path before
this label can lead to a use-after-free on the global named_triggers list.

When hist_register_trigger() fails after successfully executing
data->cmd_ops->init(data), it returns a negative error code without undoing
the initialization. For instance, if tracing_set_clock() fails due to an
invalid clock name:

kernel/trace/trace_events_hist.c:hist_register_trigger() {
    ...
		ret = tracing_set_clock(file->tr, hist_data->attrs->clock);
		if (ret) {
			hist_err(tr, HIST_ERR_SET_CLOCK_FAIL, errpos(clock));
			goto out;
		}
    ...
}

The caller event_hist_trigger_parse() handles this error from
event_trigger_register() by jumping to out_free:

kernel/trace/trace_events_hist.c:event_hist_trigger_parse() {
    ...
	ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
	if (ret < 0)
		goto out_free;
    ...
}

Since trigger_data_free(trigger_data) is called unconditionally under
out_free, it frees the memory while it remains linked in named_triggers.
Could this missing cleanup cause memory corruption or a kernel panic on
subsequent list traversals?

>  	remove_hist_vars(hist_data);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260907124420.607097-1-donggeunyoo.kernel@gmail.com?part=2

  reply	other threads:[~2026-09-07 13:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 12:44 [PATCH 0/2] tracing: hist: two named trigger error paths that free a published trigger Donggeun Yoo
2026-09-07 12:44 ` [PATCH 1/2] tracing: hist: take the reference before publishing the named trigger Donggeun Yoo
2026-09-07 12:59   ` sashiko-bot
2026-09-07 13:13     ` Donggeun Yoo
2026-09-07 21:01   ` Tom Zanussi
2026-09-07 12:44 ` [PATCH 2/2] tracing: hist: undo the registration when enabling the trigger fails Donggeun Yoo
2026-09-07 13:01   ` sashiko-bot [this message]
2026-09-07 13:13     ` Donggeun Yoo
2026-09-10  1:10 ` [PATCH 0/2] tracing: hist: two named trigger error paths that free a published trigger Donggeun Yoo

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=20260907130105.94DD51F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=donggeunyoo.kernel@gmail.com \
    --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