All of lore.kernel.org
 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 1/2] tracing: hist: take the reference before publishing the named trigger
Date: Mon, 07 Sep 2026 12:59:33 +0000	[thread overview]
Message-ID: <20260907125934.5C6261F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260907124420.607097-2-donggeunyoo.kernel@gmail.com>

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

Pre-existing issues:
- [High] The patch leaves an identical Use-After-Free and memory leak if trigger registration fails after `.init()` succeeds.
- [Medium] Ignored return value from `save_named_trigger()` causes silent failure and breaks histogram sharing.
--

commit 540a72d9b730e99f5331add357da7f87a7bcb997
Author: Donggeun Yoo <donggeunyoo.kernel@gmail.com>

tracing: hist: take the reference before publishing the named trigger

This commit delays the publication of a named trigger to the global list
until after its initialization succeeds. This prevents a failed
initialization from leaving a dangling pointer in the named_triggers list
and fixes a use-after-free bug.

Link: 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 963e0d6b61fdf..c6c04926bdf0c 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -6383,17 +6383,18 @@ static int event_hist_trigger_named_init(struct event_trigger_data *data)
>  {
>  	int ret;
>  
> -	data->ref++;
> -
> -	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;
>  	}
>  
> -	return ret;
> +	data->ref++;
> +
> +	save_named_trigger(data->named_data->name, data);

[Severity: Medium]
This is a pre-existing issue, but does ignoring the return value of
save_named_trigger() break histogram sharing?

save_named_trigger() uses kstrdup() to allocate the name string, which can
fail and return -ENOMEM. If this happens, the trigger is not added to the
named_triggers list, but the function continues as if it succeeded.

Could this lead to a state where the trigger exists but cannot be found by
functions like pause_named_trigger()? Does this silently break histogram
sharing semantics (causing subsequent triggers with the same name to create
independent maps instead of sharing them) and group pause/unpause logic?

This same return value is also ignored in event_hist_trigger_init():

kernel/trace/trace_events_hist.c:event_hist_trigger_init() {
    ...
    if (!data->ref && hist_data->attrs->name)
        save_named_trigger(hist_data->attrs->name, data);
    ...
}

> +
> +	return 0;

[Severity: High]
This isn't a bug introduced by this patch, but does this fix leave another
identical use-after-free and memory leak reachable from tracefs?

If trigger registration fails in hist_register_trigger() after this .init()
function succeeds, the error propagates up without undoing it:

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() then catches this error and blindly
frees the trigger data:

kernel/trace/trace_events_hist.c:event_hist_trigger_parse() {
    ...
 out_free:
    remove_hist_vars(hist_data);
    trigger_data_free(trigger_data);
    ...
}

Because trigger_data_free() does not invoke cmd_ops->free(), does this leave
the newly freed trigger linked in the global named_triggers list and leak
data->cmd_ops, leading to the exact same KASAN slab-use-after-free this patch
was intended to fix?

>  }

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

  reply	other threads:[~2026-09-07 12:59 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 [this message]
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
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=20260907125934.5C6261F00A3E@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 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.