Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/2] perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure
Date: Tue, 04 Aug 2026 19:15:48 +0000	[thread overview]
Message-ID: <20260804191548.E36471F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804185830.228763-3-acme@kernel.org>

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

Pre-existing issues:
- [Medium] print_pareto() calls hpp_list__parse() on a local stack variable but never cleans it up, leaking dynamically allocated formats.
- [Medium] kvm_hists__init() and kvm_hists__reinit() suffer from identical partial-registration leaks when format parsing fails.
--

--- Patch [2]: [PATCH 2/2] perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure ---
commit 92165e1ae89bef5baeedb3dd8908e10cf564714e
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure

When c2c_hists__init() or c2c_hists__reinit() calls hpp_list__parse()
and it fails partway through, format structures registered are left on
the hpp_list. This commit adds cleanup inside both functions to protect
all callers from leaking partially registered entries.

> diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
> index 160b82694d391..1856cccbee278 100644
> --- a/tools/perf/builtin-c2c.c
> +++ b/tools/perf/builtin-c2c.c

[ ... ]

> @@ -2167,8 +2175,16 @@ static int c2c_hists__reinit(struct c2c_hists *c2c_hists,
>  			     const char *sort,
>  			     struct perf_env *env)
>  {
> +	int ret;
> +
>  	perf_hpp__reset_output_field(&c2c_hists->list);
> -	return hpp_list__parse(&c2c_hists->list, output, sort, env);
> +	ret = hpp_list__parse(&c2c_hists->list, output, sort, env);
> +
> +	/* Unregister any formats added before the failure point */
> +	if (ret)
> +		perf_hpp__reset_output_field(&c2c_hists->list);
> +
> +	return ret;
>  }

[Severity: Medium]
This isn't a bug introduced by this patch, but I noticed that print_pareto()
in the same file calls hpp_list__parse() on a local stack variable:

tools/perf/builtin-c2c.c:print_pareto() {
    ...
    ret = hpp_list__parse(&hpp_list, cl_output, /*evlist=*/NULL, env);
    ...
}

Because print_pareto() returns without ever calling 
perf_hpp__reset_output_field(), does it leak all allocated c2c_fmt structures 
on both the success and failure paths?

[Severity: Medium]
This is a pre-existing issue, but kvm_hists__init() and kvm_hists__reinit() in
tools/perf/builtin-kvm.c seem to suffer from identical partial-registration
leaks when format parsing fails:

tools/perf/builtin-kvm.c:kvm_hists__init() {
    ...
    return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name");
}

tools/perf/builtin-kvm.c:kvm_hists__reinit() {
    ...
    return kvm_hpp_list__parse(&kvm_hists.list, output, sort);
}

If parsing fails partway through these functions, will partially allocated
formats remain in the global list without cleanup, replicating the exact leak
pattern fixed here in c2c?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804185830.228763-1-acme@kernel.org?part=2

  reply	other threads:[~2026-08-04 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 18:58 [PATCHES v7 0/2] perf c2c hardening Arnaldo Carvalho de Melo
2026-08-04 18:58 ` [PATCH 1/2] perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse() Arnaldo Carvalho de Melo
2026-08-04 19:12   ` sashiko-bot
2026-08-04 18:58 ` [PATCH 2/2] perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure Arnaldo Carvalho de Melo
2026-08-04 19:15   ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-08-05 15:10 [PATCHES v8 0/2] perf c2c hardening Arnaldo Carvalho de Melo
2026-08-05 15:10 ` [PATCH 2/2] perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure Arnaldo Carvalho de Melo
2026-08-06  0:02   ` Ian Rogers

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=20260804191548.E36471F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.org \
    --cc=linux-perf-users@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