Skip to contentSkip to conversation

perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb()

PATCH In review Arnaldo Carvalho de Melo 3 participants 7 messages Jul 24, 2023 – Jul 31, 2023 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

PATCH 1/1 perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb()

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 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -0
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
Signature · 1 line
2.37.1
reviewer
#1 lore raw
Quoted 7 lines · Arnaldo Carvalho de Melo

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);

Normally there would be a addr_location__exit. It looks here like most values are copied in al_to_d_al, which copies reference counted values without doing appropriate gets. Perhaps add the gets in al_to_d_al and add the exit to make it clear there can't be addr_location related leaks here.

Thanks,
Ian

Quoted 31 lines
Fixes 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -1
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
--

2.37.1

author maintainer
#2 lore raw

Em Mon, Jul 24, 2023 at 02:16:05PM -0700, Ian Rogers escreveu:

Quoted 10 lines
Quoted 7 lines · Arnaldo Carvalho de Melo

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);
Quoted 5 lines

Normally there would be a addr_location__exit. It looks here like most values are copied in al_to_d_al, which copies reference counted values without doing appropriate gets. Perhaps add the gets in al_to_d_al and add the exit to make it clear there can't be addr_location related leaks here.

I'll do that as well and add the addr_location__exit() then send a V2.

- Arnaldo

Quoted 34 lines

Thanks,
Ian

Quoted 31 lines
Fixes 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -1
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
--

2.37.1

Signature · 1 line
- Arnaldo
reviewer
#3 lore raw
Quoted 11 lines · Arnaldo Carvalho de Melo

Em Mon, Jul 24, 2023 at 02:16:05PM -0700, Ian Rogers escreveu:

Quoted 10 lines
Quoted 7 lines · Arnaldo Carvalho de Melo

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);
Quoted 7 lines
Quoted 5 lines

Normally there would be a addr_location__exit. It looks here like most values are copied in al_to_d_al, which copies reference counted values without doing appropriate gets. Perhaps add the gets in al_to_d_al and add the exit to make it clear there can't be addr_location related leaks here.

I'll do that as well and add the addr_location__exit() then send a V2.

The data is not valid outside the context of ->filter_event() or ->filter_event_early(), so the reference counts should not be changed. That probably needs to be made clearer in the documentation.

Quoted 38 lines

- Arnaldo

Quoted 34 lines

Thanks,
Ian

Quoted 31 lines
Fixes 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -1
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
--

2.37.1

author maintainer
#4 lore raw

Em Tue, Jul 25, 2023 at 02:51:58PM +0300, Adrian Hunter escreveu:

Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Mon, Jul 24, 2023 at 02:16:05PM -0700, Ian Rogers escreveu:

Quoted 10 lines
Quoted 7 lines · Arnaldo Carvalho de Melo

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);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Normally there would be a addr_location__exit. It looks here like most values are copied in al_to_d_al, which copies reference counted values without doing appropriate gets. Perhaps add the gets in al_to_d_al and add the exit to make it clear there can't be addr_location related leaks here.

Or just make al_to_d_al use strdups for the strings it gets from reference counter structs.

That or make the caller of ->resolve_address() provide a initialized addr_location that it then exits.

- Arnaldo

Quoted 47 lines
Quoted 1 line

I'll do that as well and add the addr_location__exit() then send a V2.

The data is not valid outside the context of ->filter_event() or ->filter_event_early(), so the reference counts should not be changed. That probably needs to be made clearer in the documentation.

Quoted 38 lines

- Arnaldo

Quoted 34 lines

Thanks,
Ian

Quoted 31 lines
Fixes 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -1
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
--

2.37.1

Signature · 1 line
- Arnaldo
reviewer
#5 lore raw
Quoted 19 lines · Arnaldo Carvalho de Melo

Em Tue, Jul 25, 2023 at 02:51:58PM +0300, Adrian Hunter escreveu:

Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Mon, Jul 24, 2023 at 02:16:05PM -0700, Ian Rogers escreveu:

Quoted 10 lines
Quoted 7 lines · Arnaldo Carvalho de Melo

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);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Normally there would be a addr_location__exit. It looks here like most values are copied in al_to_d_al, which copies reference counted values without doing appropriate gets. Perhaps add the gets in al_to_d_al and add the exit to make it clear there can't be addr_location related leaks here.

Quoted 5 lines

Or just make al_to_d_al use strdups for the strings it gets from reference counter structs.

That or make the caller of ->resolve_address() provide a initialized addr_location that it then exits.

OK, I will send a patch.

Quoted 51 lines

- Arnaldo

Quoted 47 lines
Quoted 1 line

I'll do that as well and add the addr_location__exit() then send a V2.

The data is not valid outside the context of ->filter_event() or ->filter_event_early(), so the reference counts should not be changed. That probably needs to be made clearer in the documentation.

Quoted 38 lines

- Arnaldo

Quoted 34 lines

Thanks,
Ian

Quoted 31 lines
Fixes 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -1
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
--

2.37.1

reviewer
#6 lore raw
Quoted 20 lines · Adrian Hunter
Quoted 19 lines · Arnaldo Carvalho de Melo

Em Tue, Jul 25, 2023 at 02:51:58PM +0300, Adrian Hunter escreveu:

Quoted 17 lines · Arnaldo Carvalho de Melo
Quoted 16 lines

Em Mon, Jul 24, 2023 at 02:16:05PM -0700, Ian Rogers escreveu:

Quoted 15 lines
Quoted 7 lines · Arnaldo Carvalho de Melo

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);

Normally there would be a addr_location__exit. It looks here like most values are copied in al_to_d_al, which copies reference counted values without doing appropriate gets. Perhaps add the gets in al_to_d_al and add the exit to make it clear there can't be addr_location related leaks here.

Quoted 7 lines
Quoted 5 lines

Or just make al_to_d_al use strdups for the strings it gets from reference counter structs.

That or make the caller of ->resolve_address() provide a initialized addr_location that it then exits.

OK, I will send a patch.

2 patches plus yours:

https://lore.kernel.org/linux-perf-users/[email protected]/T/#t

Quoted 53 lines
Quoted 52 lines

- Arnaldo

Quoted 47 lines
Quoted 1 line

I'll do that as well and add the addr_location__exit() then send a V2.

The data is not valid outside the context of ->filter_event() or ->filter_event_early(), so the reference counts should not be changed. That probably needs to be made clearer in the documentation.

Quoted 38 lines

- Arnaldo

Quoted 34 lines

Thanks,
Ian

Quoted 31 lines
Fixes 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc Adrian Hunter <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Disha Goel <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/dlfilter.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dlfilter.c +1 -1
index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644
@@ -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);
--

2.37.1