From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 70CBA19DF4F for ; Sun, 3 May 2026 00:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777768560; cv=none; b=ISyh8kVW5jGegOVbbVa9WJXvhJSiNGZyv/MdlrLqYakm625jAeSsIfwGOz3sXyJBmG/BNr2nLzD4r8jptaeKT7W5bJWq1tg/eH9TnVJ+gZp39G641QlXupeka3bXrHb/s3/OlB6zp0aURLjpNU8zt8eYmY04fdl1ffeT0mECJkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777768560; c=relaxed/simple; bh=8JZDj9FsSiFtZTgJv9NSa3FaiaAa+RxFIzAHyFIkhq8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PhfYGG4Qa6dW/BVAnBp2LT0LaAvSJjjtaSj9boEGO8+8YTPnKFY21Nnj6604jhhGgS9DFcQ9NsCFdy+ya+1qtnyA14Zhjp9ynwZdoDQbYZiEvMeMVA2yzjs/8rFOu4rOyQPTYH+7cImil4kjwj71At1DJKpFNBWfJ9hRE7BoHVU= 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=ueSIZYsY; arc=none smtp.client-ip=74.125.82.74 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="ueSIZYsY" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12dba1e866dso3091622c88.1 for ; Sat, 02 May 2026 17:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777768559; x=1778373359; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nVHNOFHXHM4bgQvRUpFKg8gW6bF51M9wm8EnPDqQV18=; b=ueSIZYsYJqDz/N2WRQ4oS2d8thnHQp+s2gVS5jLm530DtlZjEXlPHEYDsLU6NRJ7SC ENDwQV57M7Keo5XLNynWHuAcLSyUDQeAWd0kz7UzWPu2L7ar8lmdgyyd0OTStRIjpzDo iwLjaEsjxszKBZJklaaT9Ny8KtZe5wVcnirDNEnIaK+otRgad6kveHlq4VFffr+I0kur 2YLCOl9tpbk1xdzCEeGw4fpr1d499gIdRsnT0YGQMxpBVjTksUaX7wBTUAmSqWpHKdJ0 uJz0qNcbmJSz7B610tSMBoRxoMedfBvjdLWdsl19LoDotm0QSF7ilI+p9IZ+dejkhw4F gzLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777768559; x=1778373359; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nVHNOFHXHM4bgQvRUpFKg8gW6bF51M9wm8EnPDqQV18=; b=hndnhDihCwfonDUVNEzihjIS/dnlXu/WAVAVrM9dwC4WYr/tXY9lSY4R+YNQ2pcQH4 /CF4jYqsrV7jmV0Gk3NbHuyXitdd3f9E9sIsAOTBXFUkvxUGSqzpHfGwVMsXx4JODJJ3 BJiDGU3k3faZLSKHUmYJlrdS0cgw/3sLmRr7KU5ZzRv9/nhsAlGrUV+n0u5Yfo8LPANU psAqhTCulBPedG/IuTYGDqS7gMcasy00n62v+mGmu9FLhor61OCFnBndf8m8l//zicIS cyTPwVkUdng54PXavG3LtD4ras7wvdzSwLSvPjhzE3rjxIY3S1Q0GhtgkB3mTVvq1Y7/ oT+g== X-Forwarded-Encrypted: i=1; AFNElJ8oPWqK4mJIw3US/n8vKLrIsrD/RGr21sTtkiXwS5eAlGWAgjvwpdhWk/weZUxGHiwMhmU/86YzLLUBaH8=@vger.kernel.org X-Gm-Message-State: AOJu0Yys1fOtqzVE53jhYATpUwmvQXuFglXXHCpoUmu34g4HMksxvdOO YTR6XsMcD6St2UjAE1+nsBt3octGQkHhY5APq39Ntp/i6Ni8YDil9Tnr1ktX9VJS28zROss9Pd5 F31yk+ZTcpw== X-Received: from dlbcm1.prod.google.com ([2002:a05:7022:6881:b0:12c:177a:ac1d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f416:b0:123:3301:a718 with SMTP id a92af1059eb24-12dfd51fe0cmr1791428c88.1.1777768558425; Sat, 02 May 2026 17:35:58 -0700 (PDT) Date: Sat, 2 May 2026 17:35:47 -0700 In-Reply-To: <20260503003552.1063540-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260503003552.1063540-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503003552.1063540-2-irogers@google.com> Subject: [PATCH v3 1/6] perf dwarf-aux: Fix libdw segmentation fault in cu_walk_functions_at 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" A segmentation fault was observed in `libdw` when running `perf kmem` with `--page stat` on some workloads. The crash occurred deep inside `libdw` (specifically in `dwarf_child` and `dwarf_diename`) when processing DWARF information. The root cause was improper error handling of `dwarf_getfuncs` in `die_find_realfunc` and `die_find_tailfunc`. `dwarf_getfuncs` returns: - `0` on success (when all functions have been processed). - A positive offset if the callback aborts early (e.g., via `DWARF_CB_ABORT` when a match is found). - `-1` on error. The original code used `if (!dwarf_getfuncs(...)) return NULL;`. On error (`-1`), `!-1` evaluates to `0` (false), bypassing the error check. Execution then proceeded as if a match was found, returning uninitialized stack memory (`die_mem`) to the caller (`cu_walk_functions_at`). When `cu_walk_functions_at` passed this uninitialized memory to `libdw` via `dwarf_diename`, it caused a segmentation fault. Fix this by correcting the error check to `if (dwarf_getfuncs(...) <= 0)`. Fixes: e0d153c69040 ("perf-probe: Move dwarf library routines to dwarf-aux.{c, h}") Fixes: d4c537e6bf86 ("perf probe: Ignore tail calls to probed functions") Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers --- tools/perf/util/dwarf-aux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 92db2fccc788..8e83cb2d565e 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -171,7 +171,6 @@ int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr, } return ret; - } /** @@ -620,7 +619,7 @@ Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, ad.addr = addr; ad.die_mem = die_mem; /* dwarf_getscopes can't find subprogram. */ - if (!dwarf_getfuncs(cu_die, __die_search_func_tail_cb, &ad, 0)) + if (dwarf_getfuncs(cu_die, __die_search_func_tail_cb, &ad, 0) <= 0) return NULL; else return die_mem; @@ -647,6 +646,7 @@ static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) * die_find_realfunc - Search a non-inlined function at given address * @cu_die: a CU DIE which including @addr * @addr: target address + * @dbg: Dwarf session * @die_mem: a buffer for result DIE * * Search a non-inlined function DIE which includes @addr. Stores the @@ -659,7 +659,7 @@ Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, ad.addr = addr; ad.die_mem = die_mem; /* dwarf_getscopes can't find subprogram. */ - if (!dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0)) + if (dwarf_getfuncs(cu_die, __die_search_func_cb, &ad, 0) <= 0) return NULL; else return die_mem; -- 2.54.0.545.g6539524ca2-goog