[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAM9d7chdqpb5s8hqCJoDNHidGo5rrrdtOXf=FSv+XPU42MNzfw@mail.gmail.com>
Date: Fri, 23 Jun 2023 11:03:06 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
linux-perf-users@...r.kernel.org,
Aditya Gupta <adityag@...ux.ibm.com>
Subject: Re: [PATCH 1/2] perf script: Initialize buffer for regs_map()
On Thu, Jun 22, 2023 at 5:16 PM Ian Rogers <irogers@...gle.com> wrote:
>
> On Thu, Jun 22, 2023 at 4:54 PM Namhyung Kim <namhyung@...nel.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@...ry=0x7fffffffb870, evsel=evsel@...ry=0x555555efc370, al=al@...ry=0x7fffffffb2e0,
> > addr_al=addr_al@...ry=0x0, callchain=callchain@...ry=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@...ry=0x555555efb700, how=how@...ry=OE_FLUSH__FINAL, timestamp=timestamp@...ry=0)
> > at util/ordered-events.c:324
> > #10 0x00005555556bd06e in ordered_events__flush (oe=oe@...ry=0x555555efb700, how=how@...ry=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@...ry=0x555555ed8948 <commands+456>, argc=argc@...ry=4, argv=argv@...ry=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@...nel.org>
>
> Acked-by: Ian Rogers <irogers@...gle.com>
Applied both to perf-tools-next, thanks!
Powered by blists - more mailing lists