]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf probe: Fix libdw memory leak
authorIan Rogers <irogers@google.com>
Wed, 16 Oct 2024 23:56:22 +0000 (16:56 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:53:47 +0000 (13:53 +0100)
[ Upstream commit 4585038b8e186252141ef86e9f0d8e97f11dce8d ]

Add missing dwarf_cfi_end to free memory associated with probe_finder
cfi_eh which is allocated and owned via a call to
dwarf_getcfi_elf. Confusingly cfi_dbg shouldn't be freed as its memory
is owned by the passed in debuginfo struct. Add comments to highlight
this.

This addresses leak sanitizer issues seen in:
tools/perf/tests/shell/test_uprobe_from_different_cu.sh

Fixes: 270bde1e76f4 ("perf probe: Search both .eh_frame and .debug_frame sections for probe location")
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Link: https://lore.kernel.org/r/20241016235622.52166-3-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/perf/util/probe-finder.c
tools/perf/util/probe-finder.h

index 630e16c54ed5cb91b6b73769e40a1c30f8133e90..d6b902899940ba5a5618185100930f2320d9d9ef 100644 (file)
@@ -1379,6 +1379,10 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
        if (ret >= 0 && tf.pf.skip_empty_arg)
                ret = fill_empty_trace_arg(pev, tf.tevs, tf.ntevs);
 
+#if _ELFUTILS_PREREQ(0, 142)
+       dwarf_cfi_end(tf.pf.cfi_eh);
+#endif
+
        if (ret < 0 || tf.ntevs == 0) {
                for (i = 0; i < tf.ntevs; i++)
                        clear_probe_trace_event(&tf.tevs[i]);
index 3add5ff516e12de544b38cf5e48a45f922b0dee2..724db829b49e028c11e893af62f58734a524dcb1 100644 (file)
@@ -64,9 +64,9 @@ struct probe_finder {
 
        /* For variable searching */
 #if _ELFUTILS_PREREQ(0, 142)
-       /* Call Frame Information from .eh_frame */
+       /* Call Frame Information from .eh_frame. Owned by this struct. */
        Dwarf_CFI               *cfi_eh;
-       /* Call Frame Information from .debug_frame */
+       /* Call Frame Information from .debug_frame. Not owned. */
        Dwarf_CFI               *cfi_dbg;
 #endif
        Dwarf_Op                *fb_ops;        /* Frame base attribute */