[PATCH] perf probe: fix missing references to maps and map in thread__find_map

Casey Chen posted 1 patch 1 year, 5 months ago
tools/perf/util/event.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] perf probe: fix missing references to maps and map in thread__find_map
Posted by Casey Chen 1 year, 5 months ago
With 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions"),
thread__find_map() would return with al->maps being NULL when cpumode is 3
(macro PERF_RECORD_MISC_HYPERVISOR), later dereferencing on it would crash.
Fix is to add back the reference to maps and map.
---
 tools/perf/util/event.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f32f9abf6344..259cb137e5bb 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -638,6 +638,8 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 			!perf_host)
 			al->filtered |= (1 << HIST_FILTER__HOST);
 
+	al->maps = maps__get(maps);
+	al->map = maps__find(maps, al->addr);
 		return NULL;
 	}
 	al->maps = maps__get(maps);
-- 
2.45.2
Re: [PATCH] perf probe: fix missing references to maps and map in thread__find_map
Posted by Namhyung Kim 1 year, 5 months ago
Hello,

I think the subject prefix should be "perf tool:" instead of "perf
probe:" as it's generic and not related to perf probe command.

On Thu, Jun 27, 2024 at 03:36:18PM -0600, Casey Chen wrote:
> With 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions"),
> thread__find_map() would return with al->maps being NULL when cpumode is 3
> (macro PERF_RECORD_MISC_HYPERVISOR), later dereferencing on it would crash.
> Fix is to add back the reference to maps and map.
> ---
>  tools/perf/util/event.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index f32f9abf6344..259cb137e5bb 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -638,6 +638,8 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
>  			!perf_host)
>  			al->filtered |= (1 << HIST_FILTER__HOST);
>  
> +	al->maps = maps__get(maps);
> +	al->map = maps__find(maps, al->addr);

First, can you pleas fix the indentation?

And I'm not sure if it's the right fix.  It returns NULL so I think we
should expect al->map and al->maps being NULL.  Maybe we need to fix the
caller to handle NULL map or maps properly..

Thanks,
Namhyung


>  		return NULL;
>  	}
>  	al->maps = maps__get(maps);
> -- 
> 2.45.2
>