]> git.itanic.dy.fi Git - linux-stable/commitdiff
perf dlfilter: Avoid leak in v0 API test use of resolve_address()
authorAdrian Hunter <adrian.hunter@intel.com>
Wed, 30 Aug 2023 09:05:39 +0000 (12:05 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 31 Aug 2023 02:03:03 +0000 (23:03 -0300)
The introduction of reference counting causes the v0 API
perf_dlfilter_fns.resolve_address() to leak.

v2 API introduced perf_dlfilter_fns.al_cleanup() to prevent that.

For the v0 API, avoid the leak by exiting the addr_location immediately,
since the documentation makes it clear that pointers obtained via
perf_dlfilter_fns are not necessarily valid (dereferenceable) after
'filter_event' and 'filter_event_early' return.

Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Closes: https://lore.kernel.org/oe-lkp/202308232146.94d82cb4-oliver.sang@intel.com
Link: http://lore.kernel.org/lkml/20230830090539.68206-1-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/dlfilter.c

index e0f822ebb9b97964886c4692802dd78b72e6328a..1dbf27822ee28f385d4ba93a116eb3117e26cd43 100644 (file)
@@ -187,6 +187,8 @@ static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlf
 
        if (has_priv(d_al_p))
                d_al_p->priv = memdup(&al, sizeof(al));
+       else /* Avoid leak for v0 API */
+               addr_location__exit(&al);
 
        return 0;
 }