[PATCHES v8 0/2] perf c2c hardening

Arnaldo Carvalho de Melo posted 2 patches 1 month, 3 weeks ago
tools/perf/builtin-c2c.c | 106 ++++++++++++++++++++++++++++-----------
tools/perf/util/sort.c   |  76 +++++++++++++++++++---------
2 files changed, 130 insertions(+), 52 deletions(-)
[PATCHES v8 0/2] perf c2c hardening
Posted by Arnaldo Carvalho de Melo 1 month, 3 weeks ago
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
Re: [PATCHES v8 0/2] perf c2c hardening
Posted by Namhyung Kim 1 month, 3 weeks ago
On Wed, 05 Aug 2026 12:10:41 -0300, Arnaldo Carvalho de Melo wrote:
> 	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.
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung
Re: [PATCHES v8 0/2] perf c2c hardening
Posted by Arnaldo Carvalho de Melo 1 month, 3 weeks ago
On Wed, Aug 05, 2026 at 12:10:41PM -0300, Arnaldo Carvalho de Melo wrote:
> Hi,
 
> 	Please consider merging,
 
> Two hardening fixes for perf c2c found by the sashiko-bot AI reviewer.

This short series is finally completely Sashiko clean:

https://sashiko.dev/#/patchset/20260805151043.237233-1-acme%40kernel.org

- Arnaldo
Re: [PATCHES v8 0/2] perf c2c hardening
Posted by Ian Rogers 1 month, 3 weeks ago
On Wed, Aug 5, 2026 at 9:33 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> On Wed, Aug 05, 2026 at 12:10:41PM -0300, Arnaldo Carvalho de Melo wrote:
> > Hi,
>
> >       Please consider merging,
>
> > Two hardening fixes for perf c2c found by the sashiko-bot AI reviewer.
>
> This short series is finally completely Sashiko clean:
>
> https://sashiko.dev/#/patchset/20260805151043.237233-1-acme%40kernel.org

With:
https://github.com/sashiko-dev/sashiko/pull/363
I thought we'd start getting positive emails. Perhaps we're waiting
for the server to rebuild or reboot.

Thanks,
Ian

> - Arnaldo
Re: [PATCHES v8 0/2] perf c2c hardening
Posted by Arnaldo Carvalho de Melo 1 month, 3 weeks ago
On Wed, Aug 05, 2026 at 04:58:37PM -0700, Ian Rogers wrote:
> On Wed, Aug 5, 2026 at 9:33 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > On Wed, Aug 05, 2026 at 12:10:41PM -0300, Arnaldo Carvalho de Melo wrote:
> > >       Please consider merging,

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

> > This short series is finally completely Sashiko clean:

> > https://sashiko.dev/#/patchset/20260805151043.237233-1-acme%40kernel.org

> With:
> https://github.com/sashiko-dev/sashiko/pull/363
> I thought we'd start getting positive emails. Perhaps we're waiting
> for the server to rebuild or reboot.

Roman is on PTO, there is a pile of requests that is getting mountain
sized 8-)

- Arnaldo