Linux Perf Users
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	James Clark <james.clark@linaro.org>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: [PATCHES v8 0/2] perf c2c hardening
Date: Wed,  5 Aug 2026 12:10:41 -0300	[thread overview]
Message-ID: <20260805151043.237233-1-acme@kernel.org> (raw)

Hi,

	Please consider merging,

Two hardening fixes for perf c2c found by the sashiko-bot AI reviewer.

Patch 1 fixes error masking, OOM, and unchecked caller errors in
hpp_list__parse(): the strdup() return values are now checked, PARSE_LIST
was turned into a function that bails out on any error returned by the
parsing callbacks (including -ENOMEM), and the two callers bailing out
with the newly propagated errors, setup_sort_list() and
setup_output_list(), now break out of their token loops and propagate the
error instead of silently overwriting it on the next iteration.

Patch 2 fixes a format list leak: when c2c_hists__[re]init() fails
partway through, entries registered via perf_hpp_list__column_register()
and perf_hpp_list__register_sort_field() are left on the hpp_list.  The
fix moves cleanup into c2c_hists__init()/c2c_hists__reinit() themselves
so all callers are protected.

This series was developed with AI assistance (Claude:Sonnet 4.6 and
Opencode:mimo-v2.5-free for the changes up to v7; the changes since v7,
including the setup_sort_list()/setup_output_list() -ENOMEM propagation
fix and the c2c_hists__reinit() cleanup amendment, with
Opencode:DeepSeek-V4-Flash-free).

- Arnaldo

Changes since v7 (20260804185830.228763-1-acme@kernel.org):

  Patch 1:
  - Addressed sashiko-bot [Medium] finding: with sort_dimension__add()
    and output_field_add() now propagating -ENOMEM (and other errors),
    the callers setup_sort_list() and setup_output_list() only checked
    for -EINVAL and -ESRCH, so an allocation failure was silently
    overwritten when the next loop iteration ran.  Both callers now break
    out of their token loops on any error and propagate it.

Changes since v6 (20260803180703.194916-1-acme@kernel.org):

  Patch 2:
  - c2c_hists__reinit() has the same leak: it clears the list then calls
    hpp_list__parse(), which can register formats before failing, and
    neither the function nor its callers clean up on failure.  Add the
    same cleanup-on-failure pattern to close this gap.

Changes since v5 (20260803180118.194519-1-acme@kernel.org):

  - The second v5 patch didn't go through, resending the same contents
    as v5.

Changes since v4 (20260803144119.185637-1-acme@kernel.org):

  - Replace %m with str_error_r(-ret) as suggested by sashiko.

Changes since v3 (20260803120452.181273-1-acme@kernel.org):

  - Use 'goto out' to break out from both the switch and the for loop in
    __hpp_list__parse() as noticed by sashiko.

Changes since v2 (20260803011140.179943-1-acme@kernel.org):

  - Added the string.h and stdlib.h missing headers.
  - Addressed sashiko comment on PARSE_LIST, turning it into a function
    and handling all errors returned from _fn().

Changes since v1 (20260802142313.154514-1-acme@kernel.org):

  - Addressed sashiko-bot [Medium] finding: the early exits added by v1
    skip perf_hpp__setup_output_field(), making undetected errors in the
    callers consequential.  Fixed by propagating the error through
    resort_cl_cb() and perf_c2c__report() (hists__iterate_cb() already
    propagated callback return values).
  - Dismissed sashiko-bot [Low] finding (missing string.h/stdlib.h):
    strdup() and free() were already used in this function before this
    patch; string2.h (included at the top of the file) pulls in string.h.
    No new library calls were introduced.
  - Subject updated to reflect the additional caller fixes.

Arnaldo Carvalho de Melo (2):
  perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()
  perf c2c: Clean up registered formats on c2c_hists__init() and c2c_hists__reinit() failure

 tools/perf/builtin-c2c.c | 105 ++++++++++++++++++++++++++++++----------
 tools/perf/util/sort.c   |  76 ++++++++++++++++++++++-------
 2 files changed, 130 insertions(+), 52 deletions(-)

---


Arnaldo Carvalho de Melo (2):
  perf c2c: Fix error masking, OOM, and unchecked caller errors in
    hpp_list__parse()
  perf c2c: Clean up registered formats on c2c_hists__init() and
    c2c_hists__reinit() failure

 tools/perf/builtin-c2c.c | 106 ++++++++++++++++++++++++++++-----------
 tools/perf/util/sort.c   |  76 +++++++++++++++++++---------
 2 files changed, 130 insertions(+), 52 deletions(-)

-- 
2.55.0


             reply	other threads:[~2026-08-05 15:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 15:10 Arnaldo Carvalho de Melo [this message]
2026-08-05 15:10 ` [PATCH 1/2] perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse() Arnaldo Carvalho de Melo
2026-08-06  0:00   ` Ian Rogers
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
2026-08-05 16:33 ` [PATCHES v8 0/2] perf c2c hardening Arnaldo Carvalho de Melo
2026-08-05 23:58   ` Ian Rogers
2026-08-06 16:17 ` Namhyung Kim

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=20260805151043.237233-1-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /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