[PATCH v4 0/6] perf DWARF: Fix libdw API contract violations and crashes

Ian Rogers
2026-05-03T17:10:44Z

This patch series addresses a number of DWARF/libdw error-handling
bugs and contract violations, preventing several real Userspace
segmentation faults and memory/FD leaks.

In v4, the series has been thoroughly hardened based on review
feedback for v3, fixing latent bugs and improving unwinding/search
robustness:

- **Memory/FD Leak Fixes**: Fixed file descriptor leaks in
`debuginfo` offline init paths, and memory leaks when `strdup` or
inlined list appends fail during callback walks.

- **Callchain Robustness**: Fixed `ORDER_CALLER` update bugs to
prevent inline callchain corruption when nest depth >
2. Re-implemented `die_get_data_member_location` helper with
`dwarf_attr_integrate` to safely parse location expression
offsets for inherited properties (specifications/origins).

- **Search Robustness**: Relaxed strict `dwarf_getfuncs` error aborts
in `probe-finder` and `line-range` loops to allow skipping
individual corrupted CUs instead of prematurely stopping searches
entirely. Added DWARF line 0 reference support.

- **Safe DWARF Printing**: Switched to the `die_name()` safe printing
helper globally to prevent `vfprintf(NULL)` undefined
behavior/crashes when DWARF entities (like anonymous structs or
tail calls) lack names.

v4:
- Localized and squashed robust error handling, memory/FD cleanup
paths, and safe DWARF printing.

v3:
- Minor formatting fixes.
https://lore.kernel.org/linux-perf-users/20260503003552.1063540-1-irogers@google.com/

v2:
https://lore.kernel.org/lkml/20260502155656.478642-1-irogers@google.com/

v1:
https://lore.kernel.org/linux-perf-users/20260502064839.282422-1-irogers@google.com/

Ian Rogers (6):
perf dwarf-aux: Fix libdw segmentation fault in cu_walk_functions_at
perf dwarf-aux: Fix libdw API contract violations
perf libdw: Fix libdw API contract violations
perf probe-finder: Fix libdw API contract violations
perf annotate-data: Fix libdw API contract violations
perf debuginfo: Fix libdw API contract violations

tools/perf/util/annotate-data.c | 27 +++++---
tools/perf/util/debuginfo.c | 9 ++-
tools/perf/util/dwarf-aux.c | 39 ++++++------
tools/perf/util/dwarf-aux.h | 5 ++
tools/perf/util/libdw.c | 84 ++++++++++++++++++++-----
tools/perf/util/probe-finder.c | 105 +++++++++++++++++++++-----------
tools/perf/util/srcline.c | 9 ++-
tools/perf/util/srcline.h | 1 +
8 files changed, 191 insertions(+), 88 deletions(-)

--
2.54.0.545.g6539524ca2-goog