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] tracing: hist: set the trace clock before registering the trigger
Date: Mon, 07 Sep 2026 09:29:43 +0000	[thread overview]
Message-ID: <20260907092944.3950E1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260907091415.554535-1-donggeunyoo.kernel@gmail.com>

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

Pre-existing issues:
- [High] Use-After-Free list corruption if `event_hist_trigger_init` fails during named trigger initialization.
- [High] Use-After-Free list corruption because a newly created named trigger remains on the global `named_triggers` list if `hist_trigger_enable()` fails.
--

commit 1e5ea6c77dc8e3a10275a88758d5ef5a8d54be44
Author: Donggeun Yoo <donggeunyoo.kernel@gmail.com>

tracing: hist: set the trace clock before registering the trigger

hist_register_trigger() puts the trigger on the global named_triggers
list in cmd_ops->init(), and only then sets the trace clock.
The clock string is not checked anywhere before that call, so a named
trigger using common_timestamp with an unknown clock fails after it has
already become findable.

> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index 963e0d6b61fdf..6c628415468a6 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -6643,12 +6643,6 @@ static int hist_register_trigger(char *glob,
>  		data->cmd_ops = cmd_ops;
>  	}
>  
> -	if (data->cmd_ops->init) {
> -		ret = data->cmd_ops->init(data);
> -		if (ret < 0)
> -			goto out;
> -	}
> -

[ ... ]

> @@ -6661,6 +6655,15 @@ static int hist_register_trigger(char *glob,
>  		tracing_set_filter_buffering(file->tr, true);
>  	}
>  
> +	if (data->cmd_ops->init) {
> +		ret = data->cmd_ops->init(data);
> +		if (ret < 0) {
> +			if (hist_data->enable_timestamps)
> +				tracing_set_filter_buffering(file->tr, false);
> +			goto out;
> +		}
> +	}
> +
>  	if (named_data) {
>  		remove_hist_vars(hist_data);
>  		destroy_hist_data(hist_data);

While reviewing this patch, I noticed a couple of pre-existing issues
related to how named triggers are handled during initialization and error 
paths in this same file.

kernel/trace/trace_events_hist.c:event_hist_trigger_named_init() {
    ...
	save_named_trigger(data->named_data->name, data);

	ret = event_hist_trigger_init(data->named_data);
	if (ret < 0) {
		kfree(data->cmd_ops);
		data->cmd_ops = &trigger_hist_cmd;
	}

	return ret;
}

[Severity: High]
This isn't a bug introduced by this patch, but does this error path leave 
the new trigger on the global named_triggers list? 

If event_hist_trigger_init() fails, the trigger is never removed from the 
list before the function returns the error. The caller then propagates 
this error, eventually calling trigger_data_free() which frees the 
structure. Can this lead to a Use-After-Free list corruption when the 
global named_triggers list is accessed later?

Also, further down in the file:

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;

	ret = hist_trigger_enable(trigger_data, file);
	if (ret)
		goto out_unreg;
    ...
 out_unreg:
	event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
 out_free:
	remove_hist_vars(hist_data);

	trigger_data_free(trigger_data);
    ...
}

[Severity: High]
This is a pre-existing issue, but does this error path also result in 
Use-After-Free list corruption?

If hist_trigger_enable() fails, it drops the trigger from the local file 
list but then we jump to out_unreg. Because the trigger is no longer in 
file->triggers, event_trigger_unregister() won't find it and skips calling 
cmd_ops->free() (which would normally call del_named_trigger()). 

The code then falls through to trigger_data_free(). Does this manually 
free the memory without ever calling del_named_trigger(), leaving a freed 
node on the global named_triggers list?

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

  reply	other threads:[~2026-09-07  9:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  9:14 [PATCH] tracing: hist: set the trace clock before registering the trigger Donggeun Yoo
2026-09-07  9:29 ` sashiko-bot [this message]
2026-09-07 12:44   ` 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=20260907092944.3950E1F00A3D@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