* [PATCH 1/2] perf script: Initialize buffer for regs_map()
@ 2023-06-22 23:53 Namhyung Kim
2023-06-22 23:53 ` [PATCH 2/2] perf test: Set PERF_EXEC_PATH for script execution Namhyung Kim
2023-06-23 0:16 ` [PATCH 1/2] perf script: Initialize buffer for regs_map() Ian Rogers
0 siblings, 2 replies; 5+ messages in thread
From: Namhyung Kim @ 2023-06-22 23:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Jiri Olsa, Ian Rogers
Cc: Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users, Aditya Gupta
The buffer is used to save register mapping in a sample. Normally
perf samples don't have any register so the string should be empty.
But it missed to initialize the buffer when the size is 0. And it's
passed to PyUnicode_FromString() with a garbage data.
So it returns NULL due to invalid input (instead of an empty unicode
string object) which causes a segfault like below:
Thread 2.1 "perf" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7c83780 (LWP 193775)]
0x00007ffff6dbca2e in PyDict_SetItem () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
(gdb) bt
#0 0x00007ffff6dbca2e in PyDict_SetItem () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
#1 0x00007ffff6dbf848 in PyDict_SetItemString () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
#2 0x000055555575824d in pydict_set_item_string_decref (val=0x0, key=0x5555557f96e3 "iregs", dict=0x7ffff5f7f780)
at util/scripting-engines/trace-event-python.c:145
#3 set_regs_in_dict (evsel=0x555555efc370, sample=0x7fffffffb870, dict=0x7ffff5f7f780)
at util/scripting-engines/trace-event-python.c:776
#4 get_perf_sample_dict (sample=sample@entry=0x7fffffffb870, evsel=evsel@entry=0x555555efc370, al=al@entry=0x7fffffffb2e0,
addr_al=addr_al@entry=0x0, callchain=callchain@entry=0x7ffff63ef440) at util/scripting-engines/trace-event-python.c:923
#5 0x0000555555758ec1 in python_process_tracepoint (sample=0x7fffffffb870, evsel=0x555555efc370, al=0x7fffffffb2e0, addr_al=0x0)
at util/scripting-engines/trace-event-python.c:1044
#6 0x00005555555c5db8 in process_sample_event (tool=<optimized out>, event=<optimized out>, sample=<optimized out>,
evsel=0x555555efc370, machine=0x555555ef4d68) at builtin-script.c:2421
#7 0x00005555556b7793 in perf_session__deliver_event (session=0x555555ef4b60, event=0x7ffff62ff7d0, tool=0x7fffffffc150,
file_offset=30672, file_path=0x555555efb8a0 "perf.data") at util/session.c:1639
#8 0x00005555556bc864 in do_flush (show_progress=true, oe=0x555555efb700) at util/ordered-events.c:245
#9 __ordered_events__flush (oe=oe@entry=0x555555efb700, how=how@entry=OE_FLUSH__FINAL, timestamp=timestamp@entry=0)
at util/ordered-events.c:324
#10 0x00005555556bd06e in ordered_events__flush (oe=oe@entry=0x555555efb700, how=how@entry=OE_FLUSH__FINAL)
at util/ordered-events.c:342
#11 0x00005555556b9d63 in __perf_session__process_events (session=0x555555ef4b60) at util/session.c:2465
#12 perf_session__process_events (session=0x555555ef4b60) at util/session.c:2627
#13 0x00005555555cb1d0 in __cmd_script (script=0x7fffffffc150) at builtin-script.c:2839
#14 cmd_script (argc=<optimized out>, argv=<optimized out>) at builtin-script.c:4365
#15 0x0000555555650811 in run_builtin (p=p@entry=0x555555ed8948 <commands+456>, argc=argc@entry=4, argv=argv@entry=0x7fffffffe240)
at perf.c:323
#16 0x0000555555597eb3 in handle_internal_command (argv=0x7fffffffe240, argc=4) at perf.c:377
#17 run_argv (argv=<synthetic pointer>, argcp=<synthetic pointer>) at perf.c:421
#18 main (argc=4, argv=0x7fffffffe240) at perf.c:537
Fixes: 51cfe7a3e87e ("perf python: Avoid 2 leak sanitizer issues")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 25fcd6630a4d..94312741443a 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -737,11 +737,11 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, ch
unsigned int i = 0, r;
int printed = 0;
+ bf[0] = 0;
+
if (size <= 0)
return;
- bf[0] = 0;
-
if (!regs || !regs->regs)
return;
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] perf test: Set PERF_EXEC_PATH for script execution
2023-06-22 23:53 [PATCH 1/2] perf script: Initialize buffer for regs_map() Namhyung Kim
@ 2023-06-22 23:53 ` Namhyung Kim
2023-06-23 0:17 ` Ian Rogers
2023-06-23 0:16 ` [PATCH 1/2] perf script: Initialize buffer for regs_map() Ian Rogers
1 sibling, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2023-06-22 23:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Jiri Olsa, Ian Rogers
Cc: Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users, Aditya Gupta, Petar Gligoric,
Hagen Paul Pfeifer
The task-analyzer.py script (actually every other scripts too) requires
PERF_EXEC_PATH env to find dependent libraries and scripts. For scripts
test to run correctly, it needs to set PERF_EXEC_PATH to the perf tool
source directory.
Instead of blindly update the env, let's check the directory structure
to make sure it points to the correct location.
Fixes: e8478b84d6ba ("perf test: add new task-analyzer tests")
Cc: Petar Gligoric <petar.gligoric@rohde-schwarz.com>
Cc: Hagen Paul Pfeifer <hagen@jauu.net>
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/tests/shell/test_task_analyzer.sh | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/perf/tests/shell/test_task_analyzer.sh b/tools/perf/tests/shell/test_task_analyzer.sh
index 59785dfc11f8..0095abbe20ca 100755
--- a/tools/perf/tests/shell/test_task_analyzer.sh
+++ b/tools/perf/tests/shell/test_task_analyzer.sh
@@ -5,6 +5,12 @@
tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX)
err=0
+# set PERF_EXEC_PATH to find scripts in the source directory
+perfdir=$(dirname "$0")/../..
+if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then
+ export PERF_EXEC_PATH=$perfdir
+fi
+
cleanup() {
rm -f perf.data
rm -f perf.data.old
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] perf script: Initialize buffer for regs_map()
2023-06-22 23:53 [PATCH 1/2] perf script: Initialize buffer for regs_map() Namhyung Kim
2023-06-22 23:53 ` [PATCH 2/2] perf test: Set PERF_EXEC_PATH for script execution Namhyung Kim
@ 2023-06-23 0:16 ` Ian Rogers
2023-06-23 18:03 ` Namhyung Kim
1 sibling, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2023-06-23 0:16 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users, Aditya Gupta
On Thu, Jun 22, 2023 at 4:54 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> The buffer is used to save register mapping in a sample. Normally
> perf samples don't have any register so the string should be empty.
> But it missed to initialize the buffer when the size is 0. And it's
> passed to PyUnicode_FromString() with a garbage data.
>
> So it returns NULL due to invalid input (instead of an empty unicode
> string object) which causes a segfault like below:
>
> Thread 2.1 "perf" received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7ffff7c83780 (LWP 193775)]
> 0x00007ffff6dbca2e in PyDict_SetItem () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
> (gdb) bt
> #0 0x00007ffff6dbca2e in PyDict_SetItem () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
> #1 0x00007ffff6dbf848 in PyDict_SetItemString () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
> #2 0x000055555575824d in pydict_set_item_string_decref (val=0x0, key=0x5555557f96e3 "iregs", dict=0x7ffff5f7f780)
> at util/scripting-engines/trace-event-python.c:145
> #3 set_regs_in_dict (evsel=0x555555efc370, sample=0x7fffffffb870, dict=0x7ffff5f7f780)
> at util/scripting-engines/trace-event-python.c:776
> #4 get_perf_sample_dict (sample=sample@entry=0x7fffffffb870, evsel=evsel@entry=0x555555efc370, al=al@entry=0x7fffffffb2e0,
> addr_al=addr_al@entry=0x0, callchain=callchain@entry=0x7ffff63ef440) at util/scripting-engines/trace-event-python.c:923
> #5 0x0000555555758ec1 in python_process_tracepoint (sample=0x7fffffffb870, evsel=0x555555efc370, al=0x7fffffffb2e0, addr_al=0x0)
> at util/scripting-engines/trace-event-python.c:1044
> #6 0x00005555555c5db8 in process_sample_event (tool=<optimized out>, event=<optimized out>, sample=<optimized out>,
> evsel=0x555555efc370, machine=0x555555ef4d68) at builtin-script.c:2421
> #7 0x00005555556b7793 in perf_session__deliver_event (session=0x555555ef4b60, event=0x7ffff62ff7d0, tool=0x7fffffffc150,
> file_offset=30672, file_path=0x555555efb8a0 "perf.data") at util/session.c:1639
> #8 0x00005555556bc864 in do_flush (show_progress=true, oe=0x555555efb700) at util/ordered-events.c:245
> #9 __ordered_events__flush (oe=oe@entry=0x555555efb700, how=how@entry=OE_FLUSH__FINAL, timestamp=timestamp@entry=0)
> at util/ordered-events.c:324
> #10 0x00005555556bd06e in ordered_events__flush (oe=oe@entry=0x555555efb700, how=how@entry=OE_FLUSH__FINAL)
> at util/ordered-events.c:342
> #11 0x00005555556b9d63 in __perf_session__process_events (session=0x555555ef4b60) at util/session.c:2465
> #12 perf_session__process_events (session=0x555555ef4b60) at util/session.c:2627
> #13 0x00005555555cb1d0 in __cmd_script (script=0x7fffffffc150) at builtin-script.c:2839
> #14 cmd_script (argc=<optimized out>, argv=<optimized out>) at builtin-script.c:4365
> #15 0x0000555555650811 in run_builtin (p=p@entry=0x555555ed8948 <commands+456>, argc=argc@entry=4, argv=argv@entry=0x7fffffffe240)
> at perf.c:323
> #16 0x0000555555597eb3 in handle_internal_command (argv=0x7fffffffe240, argc=4) at perf.c:377
> #17 run_argv (argv=<synthetic pointer>, argcp=<synthetic pointer>) at perf.c:421
> #18 main (argc=4, argv=0x7fffffffe240) at perf.c:537
>
> Fixes: 51cfe7a3e87e ("perf python: Avoid 2 leak sanitizer issues")
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index 25fcd6630a4d..94312741443a 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -737,11 +737,11 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, ch
> unsigned int i = 0, r;
> int printed = 0;
>
> + bf[0] = 0;
> +
> if (size <= 0)
> return;
>
> - bf[0] = 0;
> -
> if (!regs || !regs->regs)
> return;
>
> --
> 2.41.0.162.gfafddb0af9-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] perf test: Set PERF_EXEC_PATH for script execution
2023-06-22 23:53 ` [PATCH 2/2] perf test: Set PERF_EXEC_PATH for script execution Namhyung Kim
@ 2023-06-23 0:17 ` Ian Rogers
0 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2023-06-23 0:17 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users, Aditya Gupta,
Petar Gligoric, Hagen Paul Pfeifer
On Thu, Jun 22, 2023 at 4:54 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> The task-analyzer.py script (actually every other scripts too) requires
> PERF_EXEC_PATH env to find dependent libraries and scripts. For scripts
> test to run correctly, it needs to set PERF_EXEC_PATH to the perf tool
> source directory.
>
> Instead of blindly update the env, let's check the directory structure
> to make sure it points to the correct location.
>
> Fixes: e8478b84d6ba ("perf test: add new task-analyzer tests")
> Cc: Petar Gligoric <petar.gligoric@rohde-schwarz.com>
> Cc: Hagen Paul Pfeifer <hagen@jauu.net>
> Cc: Aditya Gupta <adityag@linux.ibm.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> tools/perf/tests/shell/test_task_analyzer.sh | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/perf/tests/shell/test_task_analyzer.sh b/tools/perf/tests/shell/test_task_analyzer.sh
> index 59785dfc11f8..0095abbe20ca 100755
> --- a/tools/perf/tests/shell/test_task_analyzer.sh
> +++ b/tools/perf/tests/shell/test_task_analyzer.sh
> @@ -5,6 +5,12 @@
> tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX)
> err=0
>
> +# set PERF_EXEC_PATH to find scripts in the source directory
> +perfdir=$(dirname "$0")/../..
> +if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then
> + export PERF_EXEC_PATH=$perfdir
> +fi
> +
> cleanup() {
> rm -f perf.data
> rm -f perf.data.old
> --
> 2.41.0.162.gfafddb0af9-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] perf script: Initialize buffer for regs_map()
2023-06-23 0:16 ` [PATCH 1/2] perf script: Initialize buffer for regs_map() Ian Rogers
@ 2023-06-23 18:03 ` Namhyung Kim
0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2023-06-23 18:03 UTC (permalink / raw)
To: Ian Rogers
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users, Aditya Gupta
On Thu, Jun 22, 2023 at 5:16 PM Ian Rogers <irogers@google.com> wrote:
>
> On Thu, Jun 22, 2023 at 4:54 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > The buffer is used to save register mapping in a sample. Normally
> > perf samples don't have any register so the string should be empty.
> > But it missed to initialize the buffer when the size is 0. And it's
> > passed to PyUnicode_FromString() with a garbage data.
> >
> > So it returns NULL due to invalid input (instead of an empty unicode
> > string object) which causes a segfault like below:
> >
> > Thread 2.1 "perf" received signal SIGSEGV, Segmentation fault.
> > [Switching to Thread 0x7ffff7c83780 (LWP 193775)]
> > 0x00007ffff6dbca2e in PyDict_SetItem () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
> > (gdb) bt
> > #0 0x00007ffff6dbca2e in PyDict_SetItem () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
> > #1 0x00007ffff6dbf848 in PyDict_SetItemString () from /lib/x86_64-linux-gnu/libpython3.11.so.1.0
> > #2 0x000055555575824d in pydict_set_item_string_decref (val=0x0, key=0x5555557f96e3 "iregs", dict=0x7ffff5f7f780)
> > at util/scripting-engines/trace-event-python.c:145
> > #3 set_regs_in_dict (evsel=0x555555efc370, sample=0x7fffffffb870, dict=0x7ffff5f7f780)
> > at util/scripting-engines/trace-event-python.c:776
> > #4 get_perf_sample_dict (sample=sample@entry=0x7fffffffb870, evsel=evsel@entry=0x555555efc370, al=al@entry=0x7fffffffb2e0,
> > addr_al=addr_al@entry=0x0, callchain=callchain@entry=0x7ffff63ef440) at util/scripting-engines/trace-event-python.c:923
> > #5 0x0000555555758ec1 in python_process_tracepoint (sample=0x7fffffffb870, evsel=0x555555efc370, al=0x7fffffffb2e0, addr_al=0x0)
> > at util/scripting-engines/trace-event-python.c:1044
> > #6 0x00005555555c5db8 in process_sample_event (tool=<optimized out>, event=<optimized out>, sample=<optimized out>,
> > evsel=0x555555efc370, machine=0x555555ef4d68) at builtin-script.c:2421
> > #7 0x00005555556b7793 in perf_session__deliver_event (session=0x555555ef4b60, event=0x7ffff62ff7d0, tool=0x7fffffffc150,
> > file_offset=30672, file_path=0x555555efb8a0 "perf.data") at util/session.c:1639
> > #8 0x00005555556bc864 in do_flush (show_progress=true, oe=0x555555efb700) at util/ordered-events.c:245
> > #9 __ordered_events__flush (oe=oe@entry=0x555555efb700, how=how@entry=OE_FLUSH__FINAL, timestamp=timestamp@entry=0)
> > at util/ordered-events.c:324
> > #10 0x00005555556bd06e in ordered_events__flush (oe=oe@entry=0x555555efb700, how=how@entry=OE_FLUSH__FINAL)
> > at util/ordered-events.c:342
> > #11 0x00005555556b9d63 in __perf_session__process_events (session=0x555555ef4b60) at util/session.c:2465
> > #12 perf_session__process_events (session=0x555555ef4b60) at util/session.c:2627
> > #13 0x00005555555cb1d0 in __cmd_script (script=0x7fffffffc150) at builtin-script.c:2839
> > #14 cmd_script (argc=<optimized out>, argv=<optimized out>) at builtin-script.c:4365
> > #15 0x0000555555650811 in run_builtin (p=p@entry=0x555555ed8948 <commands+456>, argc=argc@entry=4, argv=argv@entry=0x7fffffffe240)
> > at perf.c:323
> > #16 0x0000555555597eb3 in handle_internal_command (argv=0x7fffffffe240, argc=4) at perf.c:377
> > #17 run_argv (argv=<synthetic pointer>, argcp=<synthetic pointer>) at perf.c:421
> > #18 main (argc=4, argv=0x7fffffffe240) at perf.c:537
> >
> > Fixes: 51cfe7a3e87e ("perf python: Avoid 2 leak sanitizer issues")
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>
> Acked-by: Ian Rogers <irogers@google.com>
Applied both to perf-tools-next, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-23 18:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-22 23:53 [PATCH 1/2] perf script: Initialize buffer for regs_map() Namhyung Kim
2023-06-22 23:53 ` [PATCH 2/2] perf test: Set PERF_EXEC_PATH for script execution Namhyung Kim
2023-06-23 0:17 ` Ian Rogers
2023-06-23 0:16 ` [PATCH 1/2] perf script: Initialize buffer for regs_map() Ian Rogers
2023-06-23 18:03 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).