[PATCHES v8 0/2] perf c2c hardening
Arnaldo Carvalho de Melo <[email protected]> Wed, 5 Aug 2026 12:10:41 -0300
| Newsgroups | org.kernel.vger.linux-perf-users,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
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 ([email protected]): 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 ([email protected]): 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 ([email protected]): - The second v5 patch didn't go through, resending the same contents as v5. Changes since v4 ([email protected]): - Replace %m with str_error_r(-ret) as suggested by sashiko. Changes since v3 ([email protected]): - 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 ([email protected]): - 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 ([email protected]): - 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