From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E90A13AD05 for ; Sun, 3 May 2026 00:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777768558; cv=none; b=T1cLJ81drW6LR6tqDXjdZOJalIkK9sh9nL0Nq9IgGYugimWravXszj1gdrjk4rjNkjHTNw57up8AaxTMRLcW8iIb0WMqTaHXdcn0C7odQFkiLruSd4rPfh8hg3hbptuSvkDGgtAku7kuveY+NX10F9a3NLlAteAZ5ybr13O6nFM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777768558; c=relaxed/simple; bh=B6e/8lzag3KzqaiC7GT7z4a7HEGPmZOmsDn8H6Ini3g=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=SbA81EVPDbzFX5pBVRvbRAbRExJgVGin/7w4GrmSSvaVP+v0vLuj61yunwuUJey3R4DU+uQv88Md8XuHnCy10H1mOLy0Xuh0sMxcJbsxiRVB2iLRsAAq6tG4UQjezWUvFcXKT14Rbr5yQPA+yIo8LVQX+4ZKuJIpH+k7PYadIwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ta9VcYbM; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ta9VcYbM" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2de07c12745so3863903eec.1 for ; Sat, 02 May 2026 17:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777768557; x=1778373357; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Vt204hYM3o4ygDaCmNEs8mUBPZRuNEjzBJxT5Rc+5L4=; b=Ta9VcYbMsm4Ol21EvrlmBq6/OPSJ80QQF2Zvz0zsywgnPfDczxru1dKhibFwKbaiWb wxgPME8LUlHDP6wEZu7jRXHd43NG9IBgsSvjFs9su82zxlu+xbZGwUWz2qRqnD9pm2VR ehpMHHKPeRyDy8eNLR/fwzERyNkgWBxt3i4AkZvgmvgX8W7ZDJcr54JAkzJDziExU5eg UJmlOMn+FCJPxUsXXPy83hsN+0LmV8L/qqsw48DfovjbEw85vx5UrYrOM9dr0ClGzaqf bOjoc7E5YRcodFlnQJ512WqMt3RPpSFSXGdMp7EWv3oYjzrH2X06pMsZdt5Q4SGLIlbI NL0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777768557; x=1778373357; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Vt204hYM3o4ygDaCmNEs8mUBPZRuNEjzBJxT5Rc+5L4=; b=K5BngQqKrTjJ7lFkTvwaDNedkx375M3cm02vGlLW+JqF/hjXb9ulNkYgjsU48OV4Oi ZjmsHXto9y78xCgdvAXDxhMiTBKwlcNZg+GitjJd3iyduhupwEPETEhhyeWPEmBDMbdh kGiwEpfirWTBS7xZjxr2F3v3pRMRpzoVa68jc7KA67Hov5JPzz4fM/J9uAJW8+S3a8hP lMtSzzKBwBduOBrqrnwsZ1fiyd/aO3QWBugp7wUIWPkJQcKvD2XJzoz17553P+qnLHSZ DKwIJ0z/sNYve98NloBkyW3U1njoKpGT8VcOUgMhYN4FhWbpMsZ8eTuiB7RvI0G8mFue ecLg== X-Forwarded-Encrypted: i=1; AFNElJ9P/azTtcK/g2y0v41hWqx0lKKsI99BTi3MwqkdEOLcD4yiGkJG2UQ8FBMAPGxtm2xYbHdqSSE9piXo9EE=@vger.kernel.org X-Gm-Message-State: AOJu0YwCkMZaMs++7sXhuHGCZ1n/NPPuSWgxTPyuAgqXIU3bbyytXv1U QEkVHwR4tX7LMw4feH28zlRBLe5FKM4u4Mv0p1HjtD7errNcsnEv6LpZ0DNYUXYD6NVX+jhx5ro 2udL375zEbw== X-Received: from dll26.prod.google.com ([2002:a05:7022:21a:b0:12d:f46c:8f9d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:913:b0:12c:5e48:4c01 with SMTP id a92af1059eb24-12dfd7a0cfamr2238258c88.1.1777768556396; Sat, 02 May 2026 17:35:56 -0700 (PDT) Date: Sat, 2 May 2026 17:35:46 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503003552.1063540-1-irogers@google.com> Subject: [PATCH v3 0/6] perf DWARF: Fix libdw API contract violations and crashes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Adrian Hunter , James Clark , Zecheng Li , Masami Hiramatsu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" This patch series addresses a number of issues related to improper or incomplete error handling when interacting with the `libdw` and `libdwfl` APIs in the `perf` DWARF processing code. The first patch fixes a real segmentation fault observed in `perf kmem` (via `dwarf_child` and `dwarf_diename`) caused by `dwarf_getfuncs` returning `-1` on error, which was not caught by the previous `if (!dwarf_getfuncs(...))` check. This allowed uninitialized stack memory to be returned and later dereferenced. Following this discovery, a comprehensive audit of `libdw` API usage was performed across `tools/perf/`. The remaining patches proactively fix 28 additional instances of ignored return values or unchecked pointers that could lead to similar uninitialized memory propagation, crashes (e.g., via `strdup(NULL)` or `strcmp(NULL)`), or silent logic failures. v3: Minor formatting fixes. 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 | 17 ++++--- tools/perf/util/debuginfo.c | 5 +- tools/perf/util/dwarf-aux.c | 37 ++++++++------ tools/perf/util/libdw.c | 24 +++++++--- tools/perf/util/probe-finder.c | 85 ++++++++++++++++++++++----------- 5 files changed, 109 insertions(+), 59 deletions(-) -- 2.54.0.545.g6539524ca2-goog