From nobody Mon May 4 13:04:19 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 A96BE313546 for ; Mon, 4 May 2026 08:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882357; cv=none; b=KXgkj1cNb8nK1OBo90+lRQJRI7UnAj1hhWZnw9GmP2NfnazfEHixu1QjpHTyCVSZkHZEH3Q3Pit9Qc9FvhGdnDPez847+lvGnKubWBqpd8i2tHC3FMyzxzr5Amri2URVQUuVEUu3bJzdZPhywBxP+/+GMpqvQAs9xtJ/9UTaru0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882357; c=relaxed/simple; bh=5S4ftJhHFEh1+pRNFqbdm9P+7JMRGdcHcrazpcFSIH4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o7pjxCqZyuOdnvoYDI5xUm5RnPEF5J0DK1R66x3LwxVRW+D7DGqQAIxm61eQ1VjwHVPQBIPF2TYPM4L5SQHCiUp4r7CrgghYAUOORbkAnt8TP8DS+3Iwbn+6ltTrwSOpaOwhjp5BJ74MJBAkQuHcuqwPMgCKqw0C9165jpLXeeU= 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=LqS3Pi9t; arc=none smtp.client-ip=74.125.82.73 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="LqS3Pi9t" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12dfe12d285so4857521c88.0 for ; Mon, 04 May 2026 01:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882355; x=1778487155; 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=UHBWWeBIGUlnWgiBEv8UalMVR2CPIvNqegyFZXfMREk=; b=LqS3Pi9tChCFHcmChyml9OEVhYmqmCjotkZ96AkJDimbg//KaNir2QTyZRCTeWNWpi INsUuA/sWJ3UgYdNPyeKYanlhDDgcqfvefpxP0FAE1QymhSRB++tpMiSFf28L4xlL8xR kEyyY0KY3Vh8iAXuEJecZVRcJRD3XtiJcegmFRmaf9r9aCtMLVZFbK73NiUaQHPtI1ix pV9p768nBQxgTJ5lBscZiborHL2ietIgMLLEZSGKOPnI/Lw60kP3o6nkL0LQfxwC06Jz K/CHPuZNehhczZWFaUfGJPPtDSFhJciSw+7QZmEV70y8z20OUTPGzv/+87n9LY9OzqUw tI0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882355; x=1778487155; 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=UHBWWeBIGUlnWgiBEv8UalMVR2CPIvNqegyFZXfMREk=; b=SJWCWKIxlJrCylHW72cQRo+Kw+FHDEXsGidyleDJz8vlEjqabCAp1kpciqFWpFjTQJ ecYimFTxoBYtaIegWi+2ZQqAkd1UgrNvOZiwufqOE/DkTAfIDrhpwwj6Fm+2ZQKhYPrm /1Xlz+49wpW/TA+Yp+HdxNmHNNnmNhngstNb1TBT2XgLvmY10MBr3+375uhGSIRJl4sq iKl8qy1L91xJ4zv63MiGX0P0LtKUa3H2Nk9904Xv3WQQ1tLZTyaY+H/mFON5l4ydBiAw W1+RB7xuOM9gQzJ/gPev8J/X7XoUqIGD4s5wT4j+Q2nhoy2v3iVlBiWoKZlsZbgpstjl 2LDA== X-Forwarded-Encrypted: i=1; AFNElJ+BvAKSi/hJ15ZeQe0gzFGoRlPisMBTKg/a6G4uGMcZwZStSrknhJVV0SAIoKp2w2ooGjxfAsdMipvr0AY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6NsHEittGv+YlisL0mAAEAyUU4PhkRAILFzKfFgcE5Nx8lzV0 SU4ElfirV3cfTH9g6X5nos5JsUYncBGyC8/K+SO3g4wmXDWg68sKBTJh/gIA9Y2WZfSpFGFyZ5M NF96I1yZ0xQ== X-Received: from dlb14.prod.google.com ([2002:a05:7022:60e:b0:12d:f5ca:970e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6286:b0:128:dbbf:fd35 with SMTP id a92af1059eb24-12dfd824f81mr4009724c88.28.1777882354591; Mon, 04 May 2026 01:12:34 -0700 (PDT) Date: Mon, 4 May 2026 01:12:19 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-2-irogers@google.com> Subject: [PATCH v5 1/9] 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-Transfer-Encoding: quoted-printable 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(...) <=3D 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 Acked-by: Namhyung Kim Signed-off-by: Ian Rogers --- v5: - Added Acked-by tag. --- tools/perf/util/dwarf-aux.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 92db2fccc788..109a166a6d19 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, } =20 return ret; - } =20 /** @@ -620,7 +619,7 @@ Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_A= ddr addr, ad.addr =3D addr; ad.die_mem =3D 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) <=3D 0) return NULL; else return die_mem; @@ -659,7 +658,7 @@ Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_A= ddr addr, ad.addr =3D addr; ad.die_mem =3D 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) <=3D 0) return NULL; else return die_mem; --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (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 A9E4A31717D for ; Mon, 4 May 2026 08:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882359; cv=none; b=D/L4gxHC7l/SQrTovhIrFm4/1p78jzxCKV4dAn8kKheBTn//OTMQ0n4TNIhKMcFyNcbWMEPuypHKV06ML/dET8vm9ajqb/YBY8Dd0tsPK8h+NWrU9QytOcO5MUYiOiGl2F+cMXuFUmSqrwq+MBFuHsVj1ScFX165KfPacSO7i5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882359; c=relaxed/simple; bh=ezr8slRwH9n2ZV1JvOOFyTaI1PUIDpT5biKxWiOeQak=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GJ8U1Qc7Vq4gyzgkj9frSSv19zYG6fpPf3XdjxbWdgaysGvQ3gvY2GM3kka0MKzR+S+xFT1ZshUa5UJEEU7cvqsHmwGb8J7m75FR7VuKFg6n3guxlT2i9+jSGu4xi/hE0rBb1pa53WNCcp49qqxadkdVW7BBu8nQadYqOC8cbaA= 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=T7fRFx8x; arc=none smtp.client-ip=74.125.82.201 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="T7fRFx8x" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2cc75e79b97so6483143eec.1 for ; Mon, 04 May 2026 01:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882356; x=1778487156; 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=rAfUSIRolAH4G9771FLWXZbdPKkv4l0+2rHJCOKFAXw=; b=T7fRFx8xmJ4OqV6aYvmPw/0fVmDLkgOATqoy40OLol1/TUxbl7oJTj15vi75Eu+G6X ihCojoFVLQ4DYQiZsFIBdcHW0GpRA+R7Ge4Wmuo0AaECno3AoI4+zsK4UjY/YlZVK1SA qNM2IMojBNkaniJD+bIwHjFg6zUYtUuDk7PynO+QXWiikqKhn/PQ0j2HTP0D4Bv7AUAK Q+dNoIAU/mv3Tp7xOkkMJf3iGr697Rwz3/3Bvx1aTs5NI/71S+hVtb/Oj3FXaDAmby6A 6Tnrg1YEvLez53rfH7BORjptl9tBzyP2Qmi+sIVHq0NTlQUhaU4wgzVx8JLyxL+ufekW vRng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882356; x=1778487156; 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=rAfUSIRolAH4G9771FLWXZbdPKkv4l0+2rHJCOKFAXw=; b=X2oCI1XVbtu+g8TZ553ishBImibsx+h0K3CNGRq8b1aN3sMPq9ikbDvXCfCCIQUBSv 24pNBd2M278nWAQ0zeXN2gn1XEcFZ1opwLURPy+2NtkTHGHK8iq0TGRF4YPQVHBOXsMI byJkM88I2iidpXhniZVqXYOp9w90GBc6sIQGO4ZrVhzGUR3ApI6qSk0kgP35v3HS0Hsx 9fgmB5iRXAV5XBvzIrIXbzH1cOCYGEHuLxJn12qbMA+gJgbi8flfc9a9jRZ13hX09Tiy BLuPKjvq6aEMoadQYxK/F4t5x9XPJHirnOOjXM/Io7zweLtHzLFhITqAoA7FsDBr7Us5 +dRQ== X-Forwarded-Encrypted: i=1; AFNElJ/ZrJFOVxiHiofqRbIXXbMmDzirUlVVl2jmcdcDx6AaVhAfCoKrF1ixNed8ZjP4WUw2C75zxMe6rI2koEU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc3tfP9QRHOWzqGw8GtM5nb2c3zdKv44FIZOZV0hQf7bGUs+mv ekTQxnbVFuGOLwSSXfE/BsShXI5+HcrN+/WN9TjwmSuDn0Zi/LYmicL5kldtA3mmPl7ytdhMymQ mj9A4WcpaqA== X-Received: from dyx13.prod.google.com ([2002:a05:693c:820d:b0:2ed:b77f:b02a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:2b08:b0:2dd:c066:bf7 with SMTP id 5a478bee46e88-2efb80c0c41mr3580658eec.11.1777882356366; Mon, 04 May 2026 01:12:36 -0700 (PDT) Date: Mon, 4 May 2026 01:12:20 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-3-irogers@google.com> Subject: [PATCH v5 2/9] perf dwarf-aux: Fix libdw API contract violations 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check return values of `dwarf_decl_line` (where non-optional), `dwarf_getfuncs`, and `dwarf_lineaddr` to prevent using uninitialized stack variables or incorrectly reporting success on failure. For the root DIE in `die_walk_lines()`, `dwarf_decl_line` and `die_get_decl_file` are optional and their failures are handled gracefully to avoid breaking line walking on valid functions. Specifically, remove the strict `!decf` (declared file) check that would prematurely abort line walking on generated or artificial functions lacking this optional attribute. Additionally: - Add NULL pointer protection for `strcmp()` in `die_walk_lines()` when `inf` or `decf` are NULL to prevent crashes on generated code. - Use `dwarf_attr_integrate` in `die_get_data_member_location` to correctly resolve inherited member locations (e.g. via abstract origin or specification). Fixes: 57f95bf5f882 ("perf probe: Show correct statement line number by per= f probe -l") Fixes: 3f4460a28fb2 ("perf probe: Filter out redundant inline-instances") Fixes: 75186a9b09e4 ("perf probe: Fix to show lines of sys_ functions corre= ctly") Fixes: e0d153c69040 ("perf-probe: Move dwarf library routines to dwarf-aux.= {c, h}") Fixes: 6243b9dc4c99 ("perf probe: Move dwarf specific functions to dwarf-au= x.c") Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers --- v5: - Updated commit message to explain optional DWARF attributes and decf che= ck removal. v4: - Fix strcmp(NULL) risk and inherited member location fallbacks in dwarf-a= ux.c. --- tools/perf/util/dwarf-aux.c | 34 +++++++++++++++++----------------- tools/perf/util/dwarf-aux.h | 5 +++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 109a166a6d19..d7160f87ac7d 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -125,7 +125,8 @@ int cu_find_lineinfo(Dwarf_Die *cu_die, Dwarf_Addr addr, && die_entrypc(&die_mem, &faddr) =3D=3D 0 && faddr =3D=3D addr) { *fname =3D die_get_decl_file(&die_mem); - dwarf_decl_line(&die_mem, lineno); + if (dwarf_decl_line(&die_mem, lineno) !=3D 0) + return -ENOENT; goto out; } =20 @@ -459,7 +460,7 @@ int die_get_data_member_location(Dwarf_Die *mb_die, Dwa= rf_Word *offs) size_t nexpr; int ret; =20 - if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) =3D=3D NULL) + if (dwarf_attr_integrate(mb_die, DW_AT_data_member_location, &attr) =3D= =3D NULL) return -ENOENT; =20 if (dwarf_formudata(&attr, offs) !=3D 0) { @@ -795,8 +796,7 @@ static int __die_walk_instances_cb(Dwarf_Die *inst, voi= d *data) =20 /* Ignore redundant instances */ if (dwarf_tag(inst) =3D=3D DW_TAG_inlined_subroutine) { - dwarf_decl_line(origin, &tmp); - if (die_get_call_lineno(inst) =3D=3D tmp) { + if (dwarf_decl_line(origin, &tmp) =3D=3D 0 && die_get_call_lineno(inst) = =3D=3D tmp) { tmp =3D die_get_decl_fileno(origin); if (die_get_call_fileno(inst) =3D=3D tmp) return DIE_FIND_CB_CONTINUE; @@ -950,11 +950,6 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callba= ck_t callback, void *data) cu_die =3D dwarf_diecu(rt_die, &die_mem, NULL, NULL); dwarf_decl_line(rt_die, &decl); decf =3D die_get_decl_file(rt_die); - if (!decf) { - pr_debug2("Failed to get the declared file name of %s\n", - dwarf_diename(rt_die)); - return -EINVAL; - } } else cu_die =3D rt_die; if (!cu_die) { @@ -998,11 +993,12 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_callb= ack_t callback, void *data) if (die_find_inlinefunc(rt_die, addr, &die_mem)) { /* Call-site check */ inf =3D die_get_call_file(&die_mem); - if ((inf && !strcmp(inf, decf)) && + if ((inf =3D=3D decf || (inf && decf && !strcmp(inf, decf))) && die_get_call_lineno(&die_mem) =3D=3D lineno) goto found; =20 - dwarf_decl_line(&die_mem, &inl); + if (dwarf_decl_line(&die_mem, &inl) !=3D 0) + inl =3D 0; if (inl !=3D decl || decf !=3D die_get_decl_file(&die_mem)) continue; @@ -1034,8 +1030,10 @@ int die_walk_lines(Dwarf_Die *rt_die, line_walk_call= back_t callback, void *data) .data =3D data, .retval =3D 0, }; - dwarf_getfuncs(cu_die, __die_walk_culines_cb, ¶m, 0); - ret =3D param.retval; + if (dwarf_getfuncs(cu_die, __die_walk_culines_cb, ¶m, 0) < 0) + ret =3D -EINVAL; + else + ret =3D param.retval; } =20 return ret; @@ -1939,10 +1937,12 @@ static bool die_get_postprologue_addr(unsigned long= entrypc_idx, break; } =20 - dwarf_lineaddr(line, postprologue_addr); - if (*postprologue_addr >=3D highpc) - dwarf_lineaddr(dwarf_onesrcline(lines, i - 1), - postprologue_addr); + if (dwarf_lineaddr(line, postprologue_addr) !=3D 0) + return false; + if (*postprologue_addr >=3D highpc) { + if (dwarf_lineaddr(dwarf_onesrcline(lines, i - 1), postprologue_addr) != =3D 0) + return false; + } =20 return true; } diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h index a79968a2e573..161f0bf980b6 100644 --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -10,6 +10,11 @@ #include #include =20 +static inline const char *die_name(Dwarf_Die *die) +{ + return dwarf_diename(die) ?: ""; +} + struct strbuf; =20 /* Find the realpath of the target file */ --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 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 274C53191CE for ; Mon, 4 May 2026 08:12:39 +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=1777882360; cv=none; b=HP2FJ8HByhEUd4aK8d++1AIsLUAzjUr19svWNHeb7rpE6TMqUiUjgALjXTJhG2h/Vu1ht2pElcp1sQH+nYCnnbBfH8jiQs2diLk22NivErvovMXVKUEgszcv4Uwur1Cj5hTL22/Szybtcc0gIy2vncwK6CqQg2uHcZcTIxXtK0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882360; c=relaxed/simple; bh=2xd40pG/HaU0jYGvWRoxt8l7PoBOLNqGg/PcgsLxwto=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MwykD2kwmbDx/OGgwaM5bIasGB6vpGZq3bpACGEgqOBHM5FBK6aJwsfuYHictkfNZErW1ZfS2zKnt2+2vrrdaTI2jVYB4u85KaGFmKDSA71JT5u7+Y19EQChSOlV46VQuSIpvtHBT5nqxNBy6o0naE0eOXP80ZnP8iefFpE+5Kk= 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=vrRShKJB; 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="vrRShKJB" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso5905547eec.0 for ; Mon, 04 May 2026 01:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882358; x=1778487158; 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=xMBI5RZgAEel/veWskGaZ9afVt4imTDF2xTiQxdH38Q=; b=vrRShKJBC6jO9QF4F5dvgIAfF4gdeDBAu8rvYz9OqUNUTUVsdG5gIfNnDs21lyg30x O1Wz/5efJW62OOvB+g4TAWh6/GXLDrfpEFOCPHP1STZ6I46Jqawzux0qrQaC1hTQxd3/ u09LHLZyK2LBIANLcLyR4uWEhKgIHVdm7rHEinEkWYK0oQdOvJ/nVcSFTYYkOe1lS/Iz w1iOHrjWVQczVToSHP7zfVdf2G4Wv1X68Xt4tSaloL0AjgtG/RfpqsrfkU8RAqe5xtEH lc6N67I6bOL9UEc6/6I1zGELfiULLl3IqunP581oqe2ni6UrcasX8KDpt5MwKEbP4O/u WjzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882358; x=1778487158; 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=xMBI5RZgAEel/veWskGaZ9afVt4imTDF2xTiQxdH38Q=; b=BF6YGZtzqjVz1bBLHRetrL05NewruNvxcvdK0oS2X56na/CWbGMwcvfQ5OK6LPxSvK 7HsXig26NIpqEZM9luRLr3pE1mk6rU1R3EFb2+HQ7xS+M+S0w3SB+OPPjTrnUWzJ6owM CHaMIbY/VPu7xBQnY9SajStvJ+mnhtmgzK03ei7kEdiysBkZTUxDB5AnH8MC7U78q9yw lBIQyKCFl5X0med4vzAfhFSNpRdooq6A1/GIlJx3aEY0FkPPpR888UxQdVmLxGiFAOby u2bgO6+2jDfWZAa+qJfehJcMudoOZNSBYXNyWU6k7cZ88+/8ooD9o2NrxSP0Ks3zro1S 0WRw== X-Forwarded-Encrypted: i=1; AFNElJ/Jy7D01001MkwL21ipVAg5vJWU9yQ1gqEPAPniKR5N3UHTRyyATJ8rm30NGdMfIjBhni1VJOuvWKOF+pY=@vger.kernel.org X-Gm-Message-State: AOJu0YwcpWo5k9IIszrMh4/mxp7lITqwpJ3eF2GqZCWCe+KAqDGzoULu hVWL7o5xjU/wWW6ykttQhOX6f9WlqT5LemMC9E/J4KLnogFFNcokEu7IAUehjCVOoyjGb7Zv9LA rzuHZFgGpWw== X-Received: from dlii2.prod.google.com ([2002:a05:7022:4182:b0:12a:7dc7:7b04]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:61a:b0:12d:ce34:3fa0 with SMTP id a92af1059eb24-12dfd856b43mr3879918c88.32.1777882358198; Mon, 04 May 2026 01:12:38 -0700 (PDT) Date: Mon, 4 May 2026 01:12:21 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-4-irogers@google.com> Subject: [PATCH v5 3/9] perf srcline: Introduce inline_node__clear_frames() 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce inline_node__clear_frames() to clean up partial allocations. This is a prerequisite for error handling in libdw inline unwinding. Signed-off-by: Ian Rogers --- v5: - Split from original Patch 3/6 into its own commit. --- tools/perf/util/srcline.c | 9 ++++++++- tools/perf/util/srcline.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index db164d258163..62884428fb5a 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -429,10 +429,13 @@ struct inline_node *dso__parse_addr_inlines(struct ds= o *dso, u64 addr, return addr2inlines(dso_name, addr, dso, sym); } =20 -void inline_node__delete(struct inline_node *node) +void inline_node__clear_frames(struct inline_node *node) { struct inline_list *ilist, *tmp; =20 + if (node =3D=3D NULL) + return; + list_for_each_entry_safe(ilist, tmp, &node->val, list) { list_del_init(&ilist->list); zfree_srcline(&ilist->srcline); @@ -441,7 +444,11 @@ void inline_node__delete(struct inline_node *node) symbol__delete(ilist->symbol); free(ilist); } +} =20 +void inline_node__delete(struct inline_node *node) +{ + inline_node__clear_frames(node); free(node); } =20 diff --git a/tools/perf/util/srcline.h b/tools/perf/util/srcline.h index 7c37b3bf9ce7..1018cbc886d6 100644 --- a/tools/perf/util/srcline.h +++ b/tools/perf/util/srcline.h @@ -47,6 +47,7 @@ struct inline_node *dso__parse_addr_inlines(struct dso *d= so, u64 addr, struct symbol *sym); /* free resources associated to the inline node list */ void inline_node__delete(struct inline_node *node); +void inline_node__clear_frames(struct inline_node *node); =20 /* insert the inline node list into the DSO, which will take ownership */ void inlines__tree_insert(struct rb_root_cached *tree, --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 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 2C0A931A053 for ; Mon, 4 May 2026 08:12:41 +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=1777882362; cv=none; b=CqWhUFxhvO7vED9l3zYxIfWDR5oPoYFgn17m66NTZbOxg1cJpXRONKkY6Rkvw5D/cJME5fAkFKlAYVGkdHR1oRGZSjRQy5tW/TdHl36+ePFiCB/1OXtZf82jCLvIfPhzP985/ezGoT5yCPzutb+LqIFv+alEw2icQ6tRyyrVNuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882362; c=relaxed/simple; bh=Gmuxp4WqFA97QBknE838BCE9Wm1G7NAZG6fKiarOItM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FodkpilzuW2mhClIVDes2MIntQO6+DEzJq9oBCm5IvPmG2LKpPbh6z0Lf94ddH9QqpMTz5FofkCTdaDwNQf1bXbFZ0UrJAZEhx41z+l8D9Esxm5IdJyn7yoNMtnvWvgdnxXZB2Rab2BZjYJFRkbEtQ3ZsRPrT58/GpoDKjHe7BY= 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=gwxfeqrE; 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="gwxfeqrE" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12e683ca86bso7090188c88.1 for ; Mon, 04 May 2026 01:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882360; x=1778487160; 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=AgADkEc29AeokmXkoizx0BWcSRq7zf6UjkidjmJFVco=; b=gwxfeqrECNQ6tNdPC3gXG9SeWpGETmO/n+QKbWeFzEqCipdBiMve9UPlJhIj6RrKmy FlPrQrWaTC6P9DO/7lE/hWqm260eDIihq41mw6vAiXABbE/U/7aHMNB66Z9Oiv38NMm6 RmGIrIYC2a65a8kkBmlLQNst7HTJ6Df/iUp1gG0SpchF5x5rCVz9nBivaR8HijMWWZr2 6oI4/ZL3za5I3XKtOPNqRligRE2u85k4U9gg4B9foKKv8x2VpWJ4XOKKCOp9B4DF4pNC v69wVTDMn4UxbMwXJlQMgGbi7Ydm5VD7FVt84U2Kn2VHd/WUYEunQq+QDbHpdv8zuURL IPbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882360; x=1778487160; 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=AgADkEc29AeokmXkoizx0BWcSRq7zf6UjkidjmJFVco=; b=Rxilg6Qt+QMeXBMU/zPNx0PidD1CYPdZuCIggkaHeTo2TZ1KzsHuVXfKHUz3hKhO+w Ummq3s99Q7tOndnVZ9Vygjx6mSEJHzMI8lJUm3w2yg+A1HJRxxRwe/5zo7yucQYJc1/X 3FO3J+yrqk1diTWiGP+sp+V2VmIXqdlleFGD3whVHjhuh9uavdU4iWIGet8txE6W+46V 1fgVE8vL7f1gxr7qCEpvrSyfLHbKhRqxdD3+CjUz0cAxtmAGNaEZWnRJjEljGAs/fKxR YKzBmj5XtOEI5yhs0bomvkTrWJuh1umE3lCzlRB4gdob+9VErj5aGCXvcFVWfDxAhe98 qmBw== X-Forwarded-Encrypted: i=1; AFNElJ/u9XMy5WfJik1Bd1BR6VuDbqCYsGHMQAMjY1xeVht/52Nywy/dm9RPxtjXJP+WPAwHh3wzB5K5E62SRvw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx47G54cXtNb4qPP5aEUrwGQ1efqtXR8DtZYIu17YsQQ6kYA+TG ugMgvbb9kvpp/sQqJ2vu+kD5666J2QWpjjG/X9IUVYlilVnvQgbfII/P9ESVvr74TVlzWCtjm3p 5YCys9qpw/Q== X-Received: from dlii2.prod.google.com ([2002:a05:7022:4182:b0:12d:b65b:1fb3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:427:b0:12d:de3e:86a7 with SMTP id a92af1059eb24-12dfd8621a2mr4592641c88.37.1777882360268; Mon, 04 May 2026 01:12:40 -0700 (PDT) Date: Mon, 4 May 2026 01:12:22 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-5-irogers@google.com> Subject: [PATCH v5 4/9] perf libdw: Fix callchain parent update in ORDER_CALLER mode 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix the parent srcline lookup in `libdw_a2l_cb()` to target the correct parent node depending on the callchain order (ORDER_CALLER/ORDER_CALLEE). This ensures inline callchains are not corrupted when nest depth > 2. Signed-off-by: Ian Rogers --- v5: - Split from original Patch 3/6 into its own commit. - Fixed bisectability failure by removing unused `ilist` variable declarat= ion. --- tools/perf/util/libdw.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c index 216977884103..301642084c69 100644 --- a/tools/perf/util/libdw.c +++ b/tools/perf/util/libdw.c @@ -4,6 +4,7 @@ #include "srcline.h" #include "symbol.h" #include "dwarf-aux.h" +#include "callchain.h" #include #include #include @@ -80,7 +81,6 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args) struct symbol *inline_sym =3D new_inline_sym(args->dso, args->sym, dwarf_= diename(die)); const char *call_fname =3D die_get_call_file(die); char *call_srcline =3D srcline__unknown; - struct inline_list *ilist; =20 if (!inline_sym) return -ENOMEM; @@ -89,14 +89,20 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args) if (call_fname) call_srcline =3D srcline_from_fileline(call_fname, die_get_call_lineno(d= ie)); =20 - list_for_each_entry(ilist, &args->node->val, list) { - if (args->leaf_srcline =3D=3D ilist->srcline) + if (!list_empty(&args->node->val)) { + struct inline_list *parent; + + if (callchain_param.order =3D=3D ORDER_CALLEE) + parent =3D list_first_entry(&args->node->val, struct inline_list, list); + else + parent =3D list_last_entry(&args->node->val, struct inline_list, list); + + if (args->leaf_srcline =3D=3D parent->srcline) args->leaf_srcline_used =3D false; - else if (ilist->srcline !=3D srcline__unknown) - free(ilist->srcline); - ilist->srcline =3D call_srcline; + else if (parent->srcline !=3D srcline__unknown) + free(parent->srcline); + parent->srcline =3D call_srcline; call_srcline =3D NULL; - break; } if (call_srcline && call_srcline !=3D srcline__unknown) free(call_srcline); --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (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 6716231DDBB for ; Mon, 4 May 2026 08:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882364; cv=none; b=gB7J+s8DoJvRnNl64DuqK40ktj01U+CbABFeQ84vva06su5tHBKZA+FczFIM1pP3ngCtdggi4E1+Tx2A5pA9n6o277ElIzmOWLp2aeIpWuiCZZ18ILunmaI4BlISqcMOm2KIcBCJQr9IZ7fsIMz13iQRSR843U8QU+k5GUHoIgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882364; c=relaxed/simple; bh=hM/dU06r3H2iof1UEM9SSbD+8fZxFpUGbqpf7lbtA9Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VSVzBUQKYqIrEzUryuKUvW1fsRD5IlCsKrV/kzhW8E+T5dbjcthuH/6OEtzhlU2k8RSv/Nw6JhRO9M2VuoqDhodmmQuc8UXi70PG2vb4r9KQegyIbLjUHJ2z8BPX/1wiGwnOvl6v0rvCKxglw6bVQ4ieWoJjf1qzYEah+iGbdts= 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=amsNcr5Y; arc=none smtp.client-ip=74.125.82.201 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="amsNcr5Y" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2ee1da7a13fso3523364eec.1 for ; Mon, 04 May 2026 01:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882363; x=1778487163; 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=gXZ9tzHv3saf8ZzOj6+EMxtC6tufF+eRQYpgvcGXfn4=; b=amsNcr5YM9ZfYLPWg0arpDNBD8UPN21CMwElbusdKoqkDNph4cHR8TGdlIZQd8bDCh Pd4V4Invv49Bc7V6efSOy0PUSRnbtAjPHDO/ns0U8uCyenSJi04UK01rBB4XZDTqYIoO +CDIZAoclVfUJrK5q+yh48e1w17scoTcGYNnHs5vaa7YW4Fm09ktyp3EZ1xEQR8v3TJE EyNxZQRcSW7BVvfhX6dVWYoLaeaY3k6AvChzJERCovjzg2pX1JM+W7sSwXquEoakxWfK D6zDP3jKZVxW2gzUh0hJgJsTqa4Jvyt75ZLwnMoujB7YTAXUVtiXLrgOFQek/WMvBIF5 I28g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882363; x=1778487163; 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=gXZ9tzHv3saf8ZzOj6+EMxtC6tufF+eRQYpgvcGXfn4=; b=GJKqAMQA40StDHMV/ybTCTebDgJULf64+UzA69henqlMIMDAzC/tp/QpVNXBMpzZQ8 7UkpKh8cF356W3wZ0zbIJ4rhxfQV6mjVekMdzyrT5uS6DW2YV1UkqHzI4RsqqLDYSyYQ +yTaM6ycn0NV9AoueQgpLbtcJd7AMCZ6VOhqV3hMpLQ50qFjNIND3KzSBeFJ4wFurIqC q+6Jh6iqpbD6sdb6tMc0tb6eWXO9hBvFglTyFNXXSsGk3JEG1+MRGOXZVVVvt6bdILxx 6H9/zooKYrXKdQ3jM5JRVKX4Z0s8YthPwZzi2Y2fI8wC14/aebssSNsz72uiHdAwhkNP 2bNA== X-Forwarded-Encrypted: i=1; AFNElJ+co6A5EeIdBC5FdAX5EjkAwMEwiKHap4yAj8FfLJwxd2XzSDIDOB+yWDcJBylhr6RsIx5hDFuQ6Bp2tTA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzyjt9oSXcDzUR7hv/Au9J4d3gExw95tvxJQe/gMm0FQ4HOXCmF PUMt1jU57hMQ0NRmckDfpxtZA16PEDY0KPaWSIWB7vNv/t3QkDKucysbXHg2wIbU5o2E+ih/mrN IWpi4WLBUxw== X-Received: from dycou19.prod.google.com ([2002:a05:7300:dc93:b0:2ee:996c:6f28]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:cd8e:b0:2d2:96e8:1bf5 with SMTP id 5a478bee46e88-2efb7bdc5bamr3624015eec.3.1777882362411; Mon, 04 May 2026 01:12:42 -0700 (PDT) Date: Mon, 4 May 2026 01:12:23 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-6-irogers@google.com> Subject: [PATCH v5 5/9] perf libdw: Support DWARF line 0 in inline list 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow DWARF line 0 in `libdw_a2l_cb()`, as it is a valid reference for compiler-generated code. Filter `die_get_call_lineno` error codes (negative values), but fallback to line 0 if `call_fname` is present to preserve the caller's filename instead of discarding it entirely. Signed-off-by: Ian Rogers --- v5: - Split from original Patch 3/6 into its own commit. - Fixed fallback logic for missing call lines to preserve filename by defa= ulting to line 0. --- tools/perf/util/libdw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c index 301642084c69..196b9cdf51b2 100644 --- a/tools/perf/util/libdw.c +++ b/tools/perf/util/libdw.c @@ -80,6 +80,7 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args) struct libdw_a2l_cb_args *args =3D _args; struct symbol *inline_sym =3D new_inline_sym(args->dso, args->sym, dwarf_= diename(die)); const char *call_fname =3D die_get_call_file(die); + int call_lineno =3D die_get_call_lineno(die); char *call_srcline =3D srcline__unknown; =20 if (!inline_sym) @@ -87,7 +88,7 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args) =20 /* Assign caller information to the parent. */ if (call_fname) - call_srcline =3D srcline_from_fileline(call_fname, die_get_call_lineno(d= ie)); + call_srcline =3D srcline_from_fileline(call_fname, call_lineno >=3D 0 ? = call_lineno : 0); =20 if (!list_empty(&args->node->val)) { struct inline_list *parent; --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 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 77ADD31E840 for ; Mon, 4 May 2026 08:12:45 +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=1777882366; cv=none; b=UedwzssfM03qpHk+pW4orEXS3VI9quoosXmToSRO0wQ3iluaV2lf35p5lJzdAzmTJ/3yoCohR0+VEwI8s3Gsa/HKqkm99uy7I+0ssbaQM2kJVbZDhtNkE1tk1fbmHD7CoDU9fqggB6ioFkBmxeKsqP+yY+qnnajlo4AJLmYFdCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882366; c=relaxed/simple; bh=LVk6twmghpuDkUyDpm8DZAKE6+luijBzQniUpl0JTIU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tMmj38E5t3loXVWHdBQAi7uOtT9RJZthyXHb8X92YumGYWXmWS6tx3cS5Wa6sD2jD/MOyc0oxz2TzTPAgx4zHWHUcP2Dm64ULXLQhMadLwgPD3kdHYc5sHi+FLUWU4yadBNntN1dnCcFTjsP/zQu88cHRlta75+JkZAw6QwIGAY= 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=A9SO2lyW; 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="A9SO2lyW" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12dfe06b670so8544394c88.0 for ; Mon, 04 May 2026 01:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882365; x=1778487165; 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=zG8T7jcDk3Qtd0yaMJTbUTNg1lGwQI504olJ183FCNM=; b=A9SO2lyWPaLJrTEIYVYeO6gxAGGApa3wicN56cEcN3Fda1XZ9dxOak2Q4xV+Lio55X C+Dj6yCwGiNHZJbO6BzlV7OuwJ1pT/ADxW322X4lcNRnF+yoDfjzFTucIrFxAd/iw+k1 Zoz8HNGKjo/RrhyIBmkVTs1YMQ8n6h4BoJVVqeS+hmD/tD3fZ/CwWOLrx4WMy+QDmY4U MBmhziwvgSTZ03K9LzqRFHIGtOyKGm/QmMnHQVE+UC805yjrCfKmm0KDcZ7w8rmuU99U pVkvWvCAjRKXO0yWlMqif9DD5USgFvnRQBfMy53NnWDylLFybOz1iKAH9X7dWBXinlGg j1tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882365; x=1778487165; 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=zG8T7jcDk3Qtd0yaMJTbUTNg1lGwQI504olJ183FCNM=; b=eydtg1RGkx5LKRgGhtHvd+4K9aLRHhxZXlDqaFm+3jeOH+Ce8xA4GRzhgh2wGJDND5 Cy5t5LGPxTkpfyFI00BfD0JsAOceJ+FXaZN5OAT6e7GFPlJPqxPhJIjQ5/0bJqKhZj5N FKpBGzAR0KbaDeXib13MWmOsKytTaO9hQv3eJXt0j/ipAJKTtF6VCukR03oiUweS9gD/ CysV6BVz+yk0gzVo8CdV2kwIqT5B9sTXrkZ8wy0Rq3P+gPFot0/XpcyjxBv/gtvZXuNl C8L6s5+GXfRnCibTX8QyfC/f3wPZ3YFQkdCvADizjdzNFgijN9XtB3wuPP+AEWO1M4iw 76NQ== X-Forwarded-Encrypted: i=1; AFNElJ+KqPlTVZg9dT5NExUehQ0A1K3j3RN6JPLAEccgOjs9/OdubN4t1KEWSR0geZyqYljGQ9mksg/8esk6gO4=@vger.kernel.org X-Gm-Message-State: AOJu0YxqwTv2GvT1ghNHGqFjEaH446iiY+E9z1V/tcMsg70oDZPjVVhG mOxOsKBCuTyt4YHzJhDhg3Jo5BUl9vAfL8o0WLUK2+eANqzpPwGfV+hY8D53nIcsQcCxtdoD773 Cne7RTsHw6w== X-Received: from dlea9-n1.prod.google.com ([2002:a05:701b:4209:10b0:12d:bcd0:59a4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b9f:b0:12d:de3f:d840 with SMTP id a92af1059eb24-12dfd86125dmr3675395c88.35.1777882364250; Mon, 04 May 2026 01:12:44 -0700 (PDT) Date: Mon, 4 May 2026 01:12:24 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-7-irogers@google.com> Subject: [PATCH v5 6/9] perf libdw: Fix libdw API contract violations and memory leaks 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check return values of `dwfl_report_end` and `dwfl_module_addrdie` to prevent using uninitialized stack variables or reporting success on failure. Additionally: - Ensure `*file` is freed and inline frames are cleared on error in `libdw__addr2line()` to prevent memory leaks and duplicated callchains when falling back to other unwinders. - Use `die_name()` safe wrapper inside the inline function unwinding callback (`libdw_a2l_cb`). - Refactor `libdw_a2l_cb`'s repeated memory error handling/cleanup paths using a cleaner goto control flow. Fixes: b7a2b011e962 ("perf powerpc: Unify the skip-callchain-idx libdw with= that for addr2line") Fixes: 88c51002d06f ("perf addr2line: Add a libdw implementation") Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers --- v5: - Split from original Patch 3/6. Refactored libdw_a2l_cb error handling wi= th goto. --- tools/perf/util/libdw.c | 49 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c index 196b9cdf51b2..84713b2a7ad5 100644 --- a/tools/perf/util/libdw.c +++ b/tools/perf/util/libdw.c @@ -61,7 +61,10 @@ struct Dwfl *dso__libdw_dwfl(struct dso *dso) return NULL; } =20 - dwfl_report_end(dwfl, /*removed=3D*/NULL, /*arg=3D*/NULL); + if (dwfl_report_end(dwfl, /*removed=3D*/NULL, /*arg=3D*/NULL) !=3D 0) { + dwfl_end(dwfl); + return NULL; + } dso__set_libdw(dso, dwfl); =20 return dwfl; @@ -73,18 +76,19 @@ struct libdw_a2l_cb_args { struct inline_node *node; char *leaf_srcline; bool leaf_srcline_used; + int err; }; =20 static int libdw_a2l_cb(Dwarf_Die *die, void *_args) { struct libdw_a2l_cb_args *args =3D _args; - struct symbol *inline_sym =3D new_inline_sym(args->dso, args->sym, dwarf_= diename(die)); + struct symbol *inline_sym =3D new_inline_sym(args->dso, args->sym, die_na= me(die)); const char *call_fname =3D die_get_call_file(die); int call_lineno =3D die_get_call_lineno(die); char *call_srcline =3D srcline__unknown; =20 if (!inline_sym) - return -ENOMEM; + goto abort_enomem; =20 /* Assign caller information to the parent. */ if (call_fname) @@ -110,12 +114,27 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args) =20 /* Add this symbol to the chain as the leaf. */ if (!args->leaf_srcline_used) { - inline_list__append_tail(inline_sym, args->leaf_srcline, args->node); + if (inline_list__append_tail(inline_sym, args->leaf_srcline, args->node)= !=3D 0) + goto abort_delete_sym; args->leaf_srcline_used =3D true; } else { - inline_list__append_tail(inline_sym, strdup(args->leaf_srcline), args->n= ode); + char *srcline =3D strdup(args->leaf_srcline); + + if (!srcline) + goto abort_delete_sym; + if (inline_list__append_tail(inline_sym, srcline, args->node) !=3D 0) { + free(srcline); + goto abort_delete_sym; + } } return 0; + +abort_delete_sym: + if (inline_sym->inlined) + symbol__delete(inline_sym); +abort_enomem: + args->err =3D -ENOMEM; + return DWARF_CB_ABORT; } =20 int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr, @@ -169,11 +188,29 @@ int libdw__addr2line(u64 addr, char **file, unsigned = int *line_nr, .leaf_srcline =3D srcline_from_fileline(src ?: "", lineno), }; =20 + if (!args.leaf_srcline) { + if (file && *file) { + free(*file); + *file =3D NULL; + } + return 0; + } + /* Walk from the parent down to the leaf. */ - cu_walk_functions_at(cudie, addr, libdw_a2l_cb, &args); + if (cudie) + cu_walk_functions_at(cudie, addr, libdw_a2l_cb, &args); =20 if (!args.leaf_srcline_used) free(args.leaf_srcline); + + if (args.err) { + if (file && *file) { + free(*file); + *file =3D NULL; + } + inline_node__clear_frames(node); + return 0; + } } return 1; } --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 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 4DE74319617 for ; Mon, 4 May 2026 08:12:47 +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=1777882369; cv=none; b=QU2Re/5VZ8l5i3QH4GYGRy6wkKOQU+Muo7P6HgHVDp4VMcxj4XSUQhJoJ/jNKeik5jAaO3uFcwGpop8wTaFI+gl3Mumn8xGvMz5dzYAq5TRyizX6U23WHlYjh47jUmmCcQlm+x8XrI2qjZrl3Nc5hcJTHwGQoDr5AVruHW3oErg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882369; c=relaxed/simple; bh=oielX4PbYhjCmH6smFUC5nve0e/HpaISRO/bEQwq2pU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eNnR0QFVo8n41MmZ4w962FCEvp/VWC6TGQyMkZLkghATcvUwTBBVdEFUTfcLjs5T3ZjfTVg66OXZKpQx6RN8TQwUleFqanhVgWTvaO9m0PnZOBWeLwAkL6qyGj5qesVKuZuhdGRMTkjgFDBXB1SpHQmeApa/GW7qrtiRwL/HLDA= 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=RXOF3A5Q; 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="RXOF3A5Q" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso5905663eec.0 for ; Mon, 04 May 2026 01:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882366; x=1778487166; 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=vCNRFFQ8ERXtj2oynby6LJQXEzZwoPz5UzHeXMMtzhg=; b=RXOF3A5QE85tXbooFHKALrqsF8u+QrbuPQICAgQztd8Lei8Z5Ln0h2ni5I9lyPsDuP GMvuiaRAr/757AfOUcO8hojbBZpIS6MmatSSALYc019seHqazVGv4Z5at6nGz4aYqaKU bvuBm7BGYskS5OvcedjZuCKDm4j4d7NcbewHniUYD/d/God4soTHWnce7PXklqCV5odp uD5fzws/1noOi+1/ZGqOy7OyKYg9l7p5EpjCMsGK5gczyekS57ulCkwAJXplo1igsliD EsBUzhVvWXsY1CzFTyXD7AvrpVPVxv1X5TE+bzCt7LucB7Pfcxe/R7VmtS/HCRBl/iqw hXyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882366; x=1778487166; 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=vCNRFFQ8ERXtj2oynby6LJQXEzZwoPz5UzHeXMMtzhg=; b=dc4tXTe+i/hNPm+aGMaB05qN4SqQp2x0SzZBUdTqD0qoRyXObPJdCWZdm8Mklrq96Z un1ONbiGQWY3Rqe81adGIQLxMLUFGCxYub0QuDctmYSzPafV573bwAjCib+yDJccB1e1 wTHFL6meQnglSOdUWdBO7v3l3CCSlH3H5owu7q4chXw2xoTbVcTeC91b/S20iv+dtCD/ 8sOLo0lVmo03Ebmq1hOoPrmN6SM1j02ppfGjGGsHg/QpK/DN61wp6CbtLiLiXrDlrr2d wtzao8/UPPDrRxq7AxEEgOLwG4IdonlG1Wsx2Xu1m4ZUNxPcFqlKVpGa6FRFwNjdlfuN u2Zg== X-Forwarded-Encrypted: i=1; AFNElJ+oESfHQjusocVjNYhxSI4e51kZ65PR9bVJcp+fu1uF07N0308b8ADdyFepbtNePkJsU9l9k1/GlT6mRpo=@vger.kernel.org X-Gm-Message-State: AOJu0YyauZlI2aSOJ3apWuNMYeflsLLURTj/FcwS0sh2KT6cGlgTOPBx PXJgZ30qKYlkCnmW6PEl+MuyNnc+3M7peQj9SKZxnWo3bE158aA3rcCPVwOddP3ctUmYXtmJwBV M4Kd/PjgJZw== X-Received: from dlbuu10.prod.google.com ([2002:a05:7022:7e8a:b0:12c:87ba:191d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6187:b0:12d:f0b1:75de with SMTP id a92af1059eb24-12dfd843065mr3830682c88.22.1777882366190; Mon, 04 May 2026 01:12:46 -0700 (PDT) Date: Mon, 4 May 2026 01:12:25 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-8-irogers@google.com> Subject: [PATCH v5 7/9] perf probe-finder: Fix libdw API contract violations 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check return values of `dwarf_formsdata`, `dwarf_entrypc`, `dwarf_highpc`, `dwarf_bytesize`, `dwarf_attr`, `dwarf_decl_line`, `dwarf_getfuncs`, and `dwarf_formref_die`. Validate `dwarf_diename` and `dwarf_diecu` results to prevent potential crashes. Fix C90 mixed declarations. Additionally: - Avoid vfprintf undefined behavior with NULL strings by using the `die_name()` helper for `dwarf_diename()` in `pr_*` calls, including when warning about tail calls. - Prevent NULL pointer dereference in `convert_variable_fields()` when processing array elements for variables in registers. - Fallback to offset 0 in `line_range_search_cb()` instead of skipping functions without `DW_AT_decl_line`. - Relax `dwarf_getfuncs` error checking in `find_probe_point_by_func()` and `find_line_range_by_func()` to prevent premature CU search aborts, ensuring robustness against corrupted CUs. Fixes: 66f69b219716 ("perf probe: Support DW_AT_const_value constant value") Fixes: 3d918a12a1b3 ("perf probe: Find fentry mcount fuzzed parameter locat= ion") Fixes: bcfc082150c6 ("perf probe: Remove redundant dwarf functions") Fixes: 221d061182b8 ("perf probe: Fix to search local variables in appropri= ate scope") Fixes: b55a87ade383 ("perf probe: Remove die() from probe-finder code") Fixes: 4c859351226c ("perf probe: Support glob wildcards for function name") Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers --- v5: - Safe DWARF name printing using die_name(). - Corrected CU DIE propagation. - Standardized comment style to /* ... */. v4: - Safe DWARF name printing with die_name() to avoid NULL formatting crashe= s. - Fix NULL dereference in register variable array lookups. - Fix robust CU search loops by continuing on getfuncs errors. --- tools/perf/util/probe-finder.c | 102 +++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 64328abeef8b..f3f9a1573502 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -79,7 +79,7 @@ static int convert_variable_location(Dwarf_Die *vr_die, D= warf_Addr addr, unsigned int regn; Dwarf_Word offs =3D 0; bool ref =3D false; - const char *regs; + const char *regs, *name; int ret, ret2 =3D 0; =20 if (dwarf_attr(vr_die, DW_AT_external, &attr) !=3D NULL) @@ -93,7 +93,8 @@ static int convert_variable_location(Dwarf_Die *vr_die, D= warf_Addr addr, if (!tvar) return 0; =20 - dwarf_formsdata(&attr, &snum); + if (dwarf_formsdata(&attr, &snum) !=3D 0) + return -ENOENT; ret =3D asprintf(&tvar->value, "\\%ld", (long)snum); =20 return ret < 0 ? -ENOMEM : 0; @@ -103,8 +104,7 @@ static int convert_variable_location(Dwarf_Die *vr_die,= Dwarf_Addr addr, if (dwarf_attr(vr_die, DW_AT_location, &attr) =3D=3D NULL) return -EINVAL; /* Broken DIE ? */ if (dwarf_getlocation_addr(&attr, addr, &op, &nops, 1) <=3D 0) { - ret =3D dwarf_entrypc(sp_die, &tmp); - if (ret) + if (dwarf_entrypc(sp_die, &tmp) !=3D 0) return -ENOENT; =20 if (probe_conf.show_location_range && @@ -115,8 +115,7 @@ static int convert_variable_location(Dwarf_Die *vr_die,= Dwarf_Addr addr, return -ENOENT; } =20 - ret =3D dwarf_highpc(sp_die, &tmp); - if (ret) + if (dwarf_highpc(sp_die, &tmp) !=3D 0) return -ENOENT; /* * This is fuzzed by fentry mcount. We try to find the @@ -138,12 +137,16 @@ static int convert_variable_location(Dwarf_Die *vr_di= e, Dwarf_Addr addr, static_var: if (!tvar) return ret2; + /* Static variables on memory (not stack), make @varname */ - ret =3D strlen(dwarf_diename(vr_die)); + name =3D dwarf_diename(vr_die); + if (!name) + return -ENOENT; + ret =3D strlen(name); tvar->value =3D zalloc(ret + 2); if (tvar->value =3D=3D NULL) return -ENOMEM; - snprintf(tvar->value, ret + 2, "@%s", dwarf_diename(vr_die)); + snprintf(tvar->value, ret + 2, "@%s", name); tvar->ref =3D alloc_trace_arg_ref((long)offs); if (tvar->ref =3D=3D NULL) return -ENOMEM; @@ -234,13 +237,14 @@ static int convert_variable_type(Dwarf_Die *vr_die, } =20 if (die_get_real_type(vr_die, &type) =3D=3D NULL) { - pr_warning("Failed to get a type information of %s.\n", - dwarf_diename(vr_die)); + const char *name =3D dwarf_diename(vr_die); + + pr_warning("Failed to get a type information of %s.\n", name ?: ""); return -ENOENT; } =20 pr_debug("%s type is %s.\n", - dwarf_diename(vr_die), dwarf_diename(&type)); + die_name(vr_die), die_name(&type)); =20 if (cast && (!strcmp(cast, "string") || !strcmp(cast, "ustring"))) { /* String type */ @@ -249,7 +253,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, ret !=3D DW_TAG_array_type) { pr_warning("Failed to cast into string: " "%s(%s) is not a pointer nor array.\n", - dwarf_diename(vr_die), dwarf_diename(&type)); + die_name(vr_die), die_name(&type)); return -EINVAL; } if (die_get_real_type(&type, &type) =3D=3D NULL) { @@ -272,7 +276,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, !die_compare_name(&type, "unsigned char")) { pr_warning("Failed to cast into string: " "%s is not (unsigned) char *.\n", - dwarf_diename(vr_die)); + die_name(vr_die)); return -EINVAL; } tvar->type =3D strdup(cast); @@ -299,7 +303,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, /* Check the bitwidth */ if (ret > MAX_BASIC_TYPE_BITS) { pr_info("%s exceeds max-bitwidth. Cut down to %d bits.\n", - dwarf_diename(&type), MAX_BASIC_TYPE_BITS); + die_name(&type), MAX_BASIC_TYPE_BITS); ret =3D MAX_BASIC_TYPE_BITS; } ret =3D snprintf(buf, 16, "%c%d", prefix, ret); @@ -333,12 +337,14 @@ static int convert_variable_fields(Dwarf_Die *vr_die,= const char *varname, pr_warning("Failed to get the type of %s.\n", varname); return -ENOENT; } - pr_debug2("Var real type: %s (%x)\n", dwarf_diename(&type), + pr_debug2("Var real type: %s (%x)\n", die_name(&type), (unsigned)dwarf_dieoffset(&type)); tag =3D dwarf_tag(&type); =20 if (field->name[0] =3D=3D '[' && (tag =3D=3D DW_TAG_array_type || tag =3D=3D DW_TAG_pointer_type)) { + int bsize; + /* Save original type for next field or type */ memcpy(die_mem, &type, sizeof(*die_mem)); /* Get the type of this array */ @@ -346,7 +352,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, c= onst char *varname, pr_warning("Failed to get the type of %s.\n", varname); return -ENOENT; } - pr_debug2("Array real type: %s (%x)\n", dwarf_diename(&type), + pr_debug2("Array real type: %s (%x)\n", die_name(&type), (unsigned)dwarf_dieoffset(&type)); if (tag =3D=3D DW_TAG_pointer_type) { ref =3D zalloc(sizeof(struct probe_trace_arg_ref)); @@ -357,7 +363,15 @@ static int convert_variable_fields(Dwarf_Die *vr_die, = const char *varname, else *ref_ptr =3D ref; } - ref->offset +=3D dwarf_bytesize(&type) * field->index; + bsize =3D dwarf_bytesize(&type); + + if (bsize < 0) + return -EINVAL; + if (!ref) { + pr_warning("Array indexing not supported for variables in registers.\n"= ); + return -ENOTSUP; + } + ref->offset +=3D bsize * field->index; ref->user_access =3D user_access; goto next; } else if (tag =3D=3D DW_TAG_pointer_type) { @@ -414,7 +428,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, c= onst char *varname, =20 if (die_find_member(&type, field->name, die_mem) =3D=3D NULL) { pr_warning("%s(type:%s) has no member %s.\n", varname, - dwarf_diename(&type), field->name); + die_name(&type), field->name); return -EINVAL; } =20 @@ -461,7 +475,7 @@ static int convert_variable(Dwarf_Die *vr_die, struct p= robe_finder *pf) int ret; =20 pr_debug("Converting variable %s into trace event.\n", - dwarf_diename(vr_die)); + die_name(vr_die)); =20 ret =3D convert_variable_location(vr_die, pf->addr, pf->fb_ops, &pf->sp_die, pf, pf->tvar); @@ -542,7 +556,7 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dw= fl_Module *mod, /* Verify the address is correct */ if (!dwarf_haspc(sp_die, paddr)) { pr_warning("Specified offset is out of %s\n", - dwarf_diename(sp_die)); + die_name(sp_die)); return -EINVAL; } =20 @@ -599,7 +613,7 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct = probe_finder *pf) if (!die_find_realfunc(&pf->cu_die, pf->addr, &pf->sp_die)) { if (die_find_tailfunc(&pf->cu_die, pf->addr, &pf->sp_die)) { pr_warning("Ignoring tail call from %s\n", - dwarf_diename(&pf->sp_die)); + die_name(&pf->sp_die)); return 0; } else { pr_warning("Failed to find probe point in any " @@ -611,10 +625,16 @@ static int call_probe_finder(Dwarf_Die *sc_die, struc= t probe_finder *pf) memcpy(&pf->sp_die, sc_die, sizeof(Dwarf_Die)); =20 /* Get the frame base attribute/ops from subprogram */ - dwarf_attr(&pf->sp_die, DW_AT_frame_base, &fb_attr); - ret =3D dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); - if (ret <=3D 0 || nops =3D=3D 0) { + if (dwarf_attr(&pf->sp_die, DW_AT_frame_base, &fb_attr) =3D=3D NULL) { pf->fb_ops =3D NULL; + } else { + ret =3D dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1= ); + if (ret <=3D 0 || nops =3D=3D 0) + pf->fb_ops =3D NULL; + } + + if (pf->fb_ops =3D=3D NULL) { + /* Not supported */ } else if (nops =3D=3D 1 && pf->fb_ops[0].atom =3D=3D DW_OP_call_frame_cf= a && (pf->cfi_eh !=3D NULL || pf->cfi_dbg !=3D NULL)) { if ((dwarf_cfi_addrframe(pf->cfi_eh, pf->addr, &frame) !=3D 0 && @@ -667,8 +687,8 @@ static int find_best_scope_cb(Dwarf_Die *fn_die, void *= data) } } else { /* With the line number, find the nearest declared DIE */ - dwarf_decl_line(fn_die, &lno); - if (lno < fsp->line && fsp->diff > fsp->line - lno) { + if (dwarf_decl_line(fn_die, &lno) =3D=3D 0 && lno < fsp->line && + fsp->diff > fsp->line - lno) { /* Keep a candidate and continue */ fsp->diff =3D fsp->line - lno; memcpy(fsp->die_mem, fn_die, sizeof(Dwarf_Die)); @@ -924,12 +944,12 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, v= oid *data) /* Get probe address */ if (die_entrypc(in_die, &addr) !=3D 0) { pr_warning("Failed to get entry address of %s.\n", - dwarf_diename(in_die)); + die_name(in_die)); return -ENOENT; } if (addr =3D=3D 0) { pr_debug("%s has no valid entry address. skipped.\n", - dwarf_diename(in_die)); + die_name(in_die)); return -ENOENT; } pf->addr =3D addr; @@ -971,12 +991,13 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, v= oid *data) if (pp->file && fname && strtailcmp(pp->file, fname)) return DWARF_CB_OK; =20 - pr_debug("Matched function: %s [%lx]\n", dwarf_diename(sp_die), + pr_debug("Matched function: %s [%lx]\n", die_name(sp_die), (unsigned long)dwarf_dieoffset(sp_die)); pf->fname =3D fname; pf->abstrace_dieoffset =3D dwarf_dieoffset(sp_die); if (pp->line) { /* Function relative line */ - dwarf_decl_line(sp_die, &pf->lno); + if (dwarf_decl_line(sp_die, &pf->lno) !=3D 0) + return DWARF_CB_OK; pf->lno +=3D pp->line; param->retval =3D find_probe_point_by_line(pf); } else if (die_is_func_instance(sp_die)) { @@ -985,7 +1006,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, vo= id *data) /* But in some case the entry address is 0 */ if (pf->addr =3D=3D 0) { pr_debug("%s has no entry PC. Skipped\n", - dwarf_diename(sp_die)); + die_name(sp_die)); param->retval =3D 0; /* Real function */ } else if (pp->lazy_line) @@ -1018,7 +1039,8 @@ static int find_probe_point_by_func(struct probe_find= er *pf) { struct dwarf_callback_param _param =3D {.data =3D (void *)pf, .retval =3D 0}; - dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0); + if (dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0) < 0) + pr_debug("Failed to get functions from CU\n"); return _param.retval; } =20 @@ -1207,7 +1229,8 @@ static int copy_variables_cb(Dwarf_Die *die_mem, void= *data) * points to correct die. */ if (dwarf_attr(die_mem, DW_AT_abstract_origin, &attr)) { - dwarf_formref_die(&attr, &var_die); + if (dwarf_formref_die(&attr, &var_die) =3D=3D NULL) + goto out; if (pf->abstrace_dieoffset !=3D dwarf_dieoffset(&var_die)) goto out; } @@ -1293,13 +1316,16 @@ static int add_probe_trace_event(Dwarf_Die *sc_die,= struct probe_finder *pf) if (ret < 0) goto end; =20 - tev->point.realname =3D strdup(dwarf_diename(sc_die)); + tev->point.realname =3D strdup(die_name(sc_die)); if (!tev->point.realname) { ret =3D -ENOMEM; goto end; } =20 - tev->lang =3D dwarf_srclang(dwarf_diecu(sc_die, &pf->cu_die, NULL, NULL)); + if (dwarf_diecu(sc_die, &pf->cu_die, NULL, NULL) !=3D NULL) + tev->lang =3D dwarf_srclang(&pf->cu_die); + else + tev->lang =3D DW_LANG_C; /* Fallback */ =20 pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, tev->point.offset); @@ -1794,7 +1820,8 @@ static int line_range_search_cb(Dwarf_Die *sp_die, vo= id *data) =20 if (die_match_name(sp_die, lr->function) && die_is_func_def(sp_die)) { lf->fname =3D die_get_decl_file(sp_die); - dwarf_decl_line(sp_die, &lr->offset); + if (dwarf_decl_line(sp_die, &lr->offset) !=3D 0) + lr->offset =3D 0; /* Fallback if no line info */ pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset); lf->lno_s =3D lr->offset + lr->start; if (lf->lno_s < 0) /* Overflow */ @@ -1818,7 +1845,8 @@ static int line_range_search_cb(Dwarf_Die *sp_die, vo= id *data) static int find_line_range_by_func(struct line_finder *lf) { struct dwarf_callback_param param =3D {.data =3D (void *)lf, .retval =3D = 0}; - dwarf_getfuncs(&lf->cu_die, line_range_search_cb, ¶m, 0); + if (dwarf_getfuncs(&lf->cu_die, line_range_search_cb, ¶m, 0) < 0) + pr_debug("Failed to get functions from CU\n"); return param.retval; } =20 --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 149E931F989 for ; Mon, 4 May 2026 08:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882370; cv=none; b=B4U6Q3aS5pVzPS28offCj2vVUWJvLK6cBLNYpwrQ71Tf2BzcG4bS1z0Yrr8M+oFvmqKhuxbGaODTfELZbYw9U1Vc7UaC5mDc7Ewkz9c4JoNC2hWEC4ra2zA1uQuNE1WsAC/12I86vULFCSXkyqrVDy5UNqze52pKItN/0jtZRpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882370; c=relaxed/simple; bh=fagq5Pyf6RSPqzFK13KNcLSeUW6HQRUiBptJVsrfrGs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=phN3zwexRd1SbfG1tyNQDDlnY8Hr2UYo7vMQW1Bdr2SzFq9WPUZzBZj8kbhzfVzu86smgu/qEkcLPpZwVo7bCOOFeMm1TxtErOKz/aH8S3YN8p5AVmYJSkAdjE6jeLUwRPTI7xXyh0MlFADvjaMIciNK+xWJpXxjgOPzgfl8blo= 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=b2qSs4M0; arc=none smtp.client-ip=74.125.82.73 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="b2qSs4M0" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12c726f4019so5272219c88.1 for ; Mon, 04 May 2026 01:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882368; x=1778487168; 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=SicvtagepMuI70fWYyc1s4K5eI0fAPBxQSJZnUvBoVQ=; b=b2qSs4M0K+HUHZ4cGmylNCH8ZY221CqfM8d92hzq1HHO66Bi3MzLbhv5CA7uXRX9hC 53T71h6L+FyAOlNcMrqBD+ap21Ho8jr9ja8lN7voFp0gBS3cseNi3vdfwyAEZyAdKoIs ru4IK6zBdFLYHS4jYd+GIn45BzyYr52O220oXz8jHBiksc1mP9ZHQTLWPw4mItCrBzNu tcObtVkSeHW2D1vmE7bnZhbWijkyKmmqwfNJ+2DMrXbMQ4wa/ChqLRHcJwFO4KVbaVKb TRmeqKLbd0q5aDNS8rR3EqTyfUOesU/PWx49fG93Lm+wzvGX0IRBFTjEW9XHGURhlFaY d8FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882368; x=1778487168; 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=SicvtagepMuI70fWYyc1s4K5eI0fAPBxQSJZnUvBoVQ=; b=K+aK2XFebWtotd/i87BeaiKBHO/zaf6Vowcwz39GbztXb5GoyV3aLHF9QnULPZiZ4/ c/J8efqxu4WMBfKmOx2nTG8q35474RpM0HlylVhTM1apWAX/sHnt76GZOmf0ktCvbnhf k8AREwafvwKj1lXBrU3ktGC1w0SEpx+8ar4X50jfA0o/sMeNMMh7c/ZlsT2nhC0p74+W mfOZvkHm9wp+8F7XdfCfRN7Q7c60DY0T+zjeYJZ+9RgHpvo/j9RHf9gskwNYGU3xFjgG 41f1y8yDE29Xz2eOPf6v/NFZoEPNgAU42p3gMD8Bdky96cr3T+undJOfsHtaE3FyEJk2 IdWQ== X-Forwarded-Encrypted: i=1; AFNElJ8KUBdqEyk22irAsCAa86GxMawLNPvkLYHsyR1cPm1bOCR/Zw91XNry4WpJ9W4ZTWGH3/HAwL/bc949HuM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzh2msZ9HrVGIm7LFqkj25Pyp77fw3Y9UzYMRpKxY+oUa1squXY 2pvXlYA1L0TNbICQAlSIAUdebKbxPghF2yzC/gGQRa3IX3aYgh2xpYZFlhEYJ6So9pZek+VY3A1 S/vKnQNC72g== X-Received: from dlbps8.prod.google.com ([2002:a05:7023:888:b0:12d:b2ba:b551]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e98d:b0:11b:9b98:aa4b with SMTP id a92af1059eb24-12dfd7ae4ffmr3815325c88.6.1777882368044; Mon, 04 May 2026 01:12:48 -0700 (PDT) Date: Mon, 4 May 2026 01:12:26 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-9-irogers@google.com> Subject: [PATCH v5 8/9] perf annotate-data: Fix libdw API contract violations 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check return values of `dwarf_aggregate_size` and `dwarf_formudata`. Additionally: - Avoid `vfprintf` undefined behavior with `NULL` strings by using the `die_name()` helper for `dwarf_diename()` in `pr_*` calls. - Use `die_get_data_member_location()` (updated to use `dwarf_attr_integrate`) to correctly parse location expressions for inherited member locations in the fallback path when `dwarf_formudata()` fails. Fixes: 2bc3cf575a16 ("perf annotate-data: Improve debug message with locati= on info") Fixes: 4a111cadac85 ("perf annotate-data: Add member field in the data type= ") Fixes: 8b1042c425f6 ("perf annotate-data: Set bitfield member offset and si= ze properly") Fixes: fc044c53b99f ("perf annotate-data: Add dso->data_types tree") Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers --- v5: - Safe string duplication for member variable names. v4: - Safe DWARF name printing in annotate-data. - Fix fallback location expression parsing for inherited data members. --- tools/perf/util/annotate-data.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 1eff0a27237d..63e3c54fab42 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -74,7 +74,8 @@ void pr_debug_type_name(Dwarf_Die *die, enum type_state_k= ind kind) break; } =20 - dwarf_aggregate_size(die, &size); + if (dwarf_aggregate_size(die, &size) !=3D 0) + size =3D 0; =20 strbuf_init(&sb, 32); die_get_typename_from_type(die, &sb); @@ -146,9 +147,9 @@ static void pr_debug_scope(Dwarf_Die *scope_die) =20 tag =3D dwarf_tag(scope_die); if (tag =3D=3D DW_TAG_subprogram) - pr_info("[function] %s\n", dwarf_diename(scope_die)); + pr_info("[function] %s\n", die_name(scope_die)); else if (tag =3D=3D DW_TAG_inlined_subroutine) - pr_info("[inlined] %s\n", dwarf_diename(scope_die)); + pr_info("[inlined] %s\n", die_name(scope_die)); else if (tag =3D=3D DW_TAG_lexical_block) pr_info("[block]\n"); else @@ -250,9 +251,12 @@ static int __add_member_cb(Dwarf_Die *die, void *arg) if (dwarf_aggregate_size(&die_mem, &size) < 0) size =3D 0; =20 - if (dwarf_attr_integrate(die, DW_AT_data_member_location, &attr)) - dwarf_formudata(&attr, &loc); - else { + if (dwarf_attr_integrate(die, DW_AT_data_member_location, &attr)) { + if (dwarf_formudata(&attr, &loc) !=3D 0) { + if (die_get_data_member_location(die, &loc) !=3D 0) + loc =3D 0; + } + } else { /* bitfield member */ if (dwarf_attr_integrate(die, DW_AT_data_bit_offset, &attr) && dwarf_formudata(&attr, &loc) =3D=3D 0) @@ -273,7 +277,9 @@ static int __add_member_cb(Dwarf_Die *die, void *arg) dwarf_diename(die), (long)bit_size) < 0) member->var_name =3D NULL; } else { - member->var_name =3D strdup(dwarf_diename(die)); + const char *name =3D dwarf_diename(die); + + member->var_name =3D name ? strdup(name) : NULL; } =20 if (member->var_name =3D=3D NULL) { @@ -370,7 +376,8 @@ static struct annotated_data_type *dso__findnew_data_ty= pe(struct dso *dso, if (dwarf_tag(type_die) =3D=3D DW_TAG_typedef) die_get_real_type(type_die, type_die); =20 - dwarf_aggregate_size(type_die, &size); + if (dwarf_aggregate_size(type_die, &size) !=3D 0) + size =3D 0; =20 /* Check existing nodes in dso->data_types tree */ key.self.type_name =3D type_name; @@ -1569,7 +1576,7 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) offset =3D loc->offset; =20 pr_debug_dtp("CU for %s (die:%#lx)\n", - dwarf_diename(&cu_die), (long)dwarf_dieoffset(&cu_die)); + die_name(&cu_die), (long)dwarf_dieoffset(&cu_die)); =20 if (reg =3D=3D DWARF_REG_PC) { if (get_global_var_type(&cu_die, dloc, dloc->ip, dloc->var_addr, @@ -1636,7 +1643,7 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) } =20 pr_debug_dtp("found \"%s\" (die: %#lx) in scope=3D%d/%d (die: %#lx) ", - dwarf_diename(&var_die), (long)dwarf_dieoffset(&var_die), + die_name(&var_die), (long)dwarf_dieoffset(&var_die), i+1, nr_scopes, (long)dwarf_dieoffset(&scopes[i])); =20 if (reg =3D=3D DWARF_REG_PC) { --=20 2.54.0.545.g6539524ca2-goog From nobody Mon May 4 13:04:19 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (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 337C231B803 for ; Mon, 4 May 2026 08:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882373; cv=none; b=d6gv12puNO2ISKTSGgDrJ8yrvEt26xtgBeEbm4UgbwDiFq6YybXluZOH2MQXAhVmkJf0t15NtV9Bhoe7LYFJjJr2MFDfCdxIdEpeiwVAyNe8KdU71VF5avQa8E7a8IWxXCuKRcyDoAALQcgKIT1wYW9ymynsanXO0p0CkUjnBYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777882373; c=relaxed/simple; bh=86Fi8XgRbKLUoxAcrNtQ/NCYtxcmPhDpKOGB2wMyx9M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rbfOU4TtlEt9u3r4Pg26oroldlm8eq6TvRI7swk5tW+FmuVPl6C/vqGMVeHJq2v7mr/EE0/B84YrC3/ouM13+lLX7Pkk3HGgl2rH1DNrD99z11N/GPBZy7YE+/uTkl1TJq38ivGMqa3+cGMU+kohnotc1FL4ZWLThI0/4BUtwRk= 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=MUZuLnAA; arc=none smtp.client-ip=74.125.82.201 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="MUZuLnAA" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bda35eab74so3219521eec.0 for ; Mon, 04 May 2026 01:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777882370; x=1778487170; 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=ws2FlyxY3Py6KisW5mWMui419nDHfCw03Zt9ciWQIP4=; b=MUZuLnAAu/oOYxIZ1TQ/OUgzKDqIOirC+4mN1mJMyx6OQdWwYTPcHtyHWzfUYKlO15 78YWRDU5xyKye5g5BJhF+qG0pXCN/Yr5NgxFCGqgASBCZ5pF07IOmGQ7YpqcmF/QnQjb V5LrYmRboRJLDTFQGJmtTXGJ+S5ISndT1Z7QqjKXS7EjfXNZGToO4rbO06MHQcmW+wck NjLfWOKSYf3LMHNwf+VCwAXWa/SG7W9p10J3u7Xp7vJlQDA8Suk4WZd50SMLWF7lAqj6 +2xyDQuu6RpiiscBND9QhGd5DhcoolSpTt5p9GqyKBhhhkiHqWfOB0xsTUG1SNe4tA9J E4AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777882370; x=1778487170; 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=ws2FlyxY3Py6KisW5mWMui419nDHfCw03Zt9ciWQIP4=; b=kvzpYhm1Wxp2YUCw9Nx3Ydg9jA/zqeowT+r6RS0ghx4CXyAz1iFk+ymVIRdSH4YxzV C/SAcPrHcGaabJx9kio/jFYVuolqSzuT6SpiWATbnCuKS3L5oIw8eanduLO6BarNRrF6 ZHvj25rBE2HdQiTPQRdswY0jsVGmo47RB9dbddmPtmUFX+9XCTCRlBgiOoJcQ90jVlCk HRHBokvOx/4708QZChAkN8JFl52f/gyElKRfruebjUzgLeq3HXSKPtntHdfJnf/IznQ+ UqpxF1Sm0cbjPWECAlkMrljfS8XldWn9WSVfAQHRZn4jeQHoXAmZ2ZGO1lnvcMrZ/POH 09uA== X-Forwarded-Encrypted: i=1; AFNElJ+yte8Bqb09N4TfkHHLOeF50ddaXVLFvjd1jTi7ddfj9zJh43MrcXg9HvpZ91Tirj5+eVA0DaYHlk3toHs=@vger.kernel.org X-Gm-Message-State: AOJu0YzaIIUmv0ZbTJLdd08E83/Vjs5VsBolImvkUKwomABYx+VSL5+d fX4NwlIKE2IPFoHc9ah6gliX6bzzSVJ+8pDSNNBqP/hj0qQx3MMnM2cT9ADsh6jTuq52c+s/Yus 5zX1FfEBLiQ== X-Received: from dlbps10.prod.google.com ([2002:a05:7023:88a:b0:12d:d43c:4120]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:68a9:b0:12c:aae:7b43 with SMTP id a92af1059eb24-12dece4285bmr6819531c88.24.1777882370014; Mon, 04 May 2026 01:12:50 -0700 (PDT) Date: Mon, 4 May 2026 01:12:27 -0700 In-Reply-To: <20260504081227.2203848-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: <20260503171032.1559338-1-irogers@google.com> <20260504081227.2203848-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504081227.2203848-10-irogers@google.com> Subject: [PATCH v5 9/9] perf debuginfo: Fix libdw API contract violations 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check return value of `dwfl_report_end` during offline initialization. Validate `dwfl_module_relocation_info` result before passing to `strcmp` to avoid potential segmentation faults. Additionally: - Fix a file descriptor leak in `debuginfo__init_offline_dwarf()` when `dwfl_report_offline()` or subsequent setup calls fail. Fixes: 6f1b6291cf73 ("perf tools: Add util/debuginfo.[ch] files") Assisted-by: Gemini-CLI:Google Gemini 3 Acked-by: Namhyung Kim Signed-off-by: Ian Rogers --- v5: - Added Acked-by tag. v4: - Fix file descriptor leaks in debuginfo init paths. --- tools/perf/util/debuginfo.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c index 0e35c13abd04..84a78b30ceac 100644 --- a/tools/perf/util/debuginfo.c +++ b/tools/perf/util/debuginfo.c @@ -42,6 +42,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo= *dbg, { GElf_Addr dummy; int fd; + bool fd_consumed =3D false; =20 fd =3D open(path, O_RDONLY); if (fd < 0) @@ -55,6 +56,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo= *dbg, dbg->mod =3D dwfl_report_offline(dbg->dwfl, "", "", fd); if (!dbg->mod) goto error; + fd_consumed =3D true; =20 dbg->dbg =3D dwfl_module_getdwarf(dbg->mod, &dbg->bias); if (!dbg->dbg) @@ -62,13 +64,14 @@ static int debuginfo__init_offline_dwarf(struct debugin= fo *dbg, =20 dwfl_module_build_id(dbg->mod, &dbg->build_id, &dummy); =20 - dwfl_report_end(dbg->dwfl, NULL, NULL); + if (dwfl_report_end(dbg->dwfl, NULL, NULL) !=3D 0) + goto error; =20 return 0; error: if (dbg->dwfl) dwfl_end(dbg->dwfl); - else + if (!fd_consumed) close(fd); memset(dbg, 0, sizeof(*dbg)); =20 @@ -167,7 +170,7 @@ int debuginfo__get_text_offset(struct debuginfo *dbg, D= warf_Addr *offs, /* Search the relocation related .text section */ for (i =3D 0; i < n; i++) { p =3D dwfl_module_relocation_info(dbg->mod, i, &shndx); - if (strcmp(p, ".text") =3D=3D 0) { + if (p && strcmp(p, ".text") =3D=3D 0) { /* OK, get the section header */ scn =3D elf_getscn(elf, shndx); if (!scn) --=20 2.54.0.545.g6539524ca2-goog