[2/3] perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb()

Message ID 20230731091857.10681-2-adrian.hunter@intel.com
State New
Headers
Series [1/3] perf dlfilter: Add a test for resolve_address() |

Commit Message

Adrian Hunter July 31, 2023, 9:18 a.m. UTC
  From: Arnaldo Carvalho de Melo <acme@kernel.org>

As thread__find_symbol_fb() will end up calling thread__find_map() and
it in turn will call these on uninitialized memory:

        maps__zput(al->maps);
        map__zput(al->map);
        thread__zput(al->thread);

Fixes: 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions")
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/
Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Adrian Hunter July 31, 2023, 9:30 a.m. UTC | #1
On 31/07/23 12:18, Adrian Hunter wrote:
> From: Arnaldo Carvalho de Melo <acme@kernel.org>

Or should that and below be acme@redhat.com

> 
> As thread__find_symbol_fb() will end up calling thread__find_map() and
> it in turn will call these on uninitialized memory:
> 
>         maps__zput(al->maps);
>         map__zput(al->map);
>         thread__zput(al->thread);
> 
> Fixes: 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions")
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Kajol Jain <kjain@linux.ibm.com>
> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Link: https://lore.kernel.org/lkml/
> Signed-off-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> ---
>  tools/perf/util/dlfilter.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
> index 46f74b2344db..798a53d7e6c9 100644
> --- a/tools/perf/util/dlfilter.c
> +++ b/tools/perf/util/dlfilter.c
> @@ -166,6 +166,7 @@ static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlf
>  	if (!thread)
>  		return -1;
>  
> +	addr_location__init(&al);
>  	thread__find_symbol_fb(thread, d->sample->cpumode, address, &al);
>  
>  	al_to_d_al(&al, &d_al);
  

Patch

diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
index 46f74b2344db..798a53d7e6c9 100644
--- a/tools/perf/util/dlfilter.c
+++ b/tools/perf/util/dlfilter.c
@@ -166,6 +166,7 @@  static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlf
 	if (!thread)
 		return -1;
 
+	addr_location__init(&al);
 	thread__find_symbol_fb(thread, d->sample->cpumode, address, &al);
 
 	al_to_d_al(&al, &d_al);