linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org,
	Aditya Gupta <adityag@linux.ibm.com>
Subject: Re: [PATCH 1/2] perf script: Initialize buffer for regs_map()
Date: Fri, 23 Jun 2023 11:03:06 -0700	[thread overview]
Message-ID: <CAM9d7chdqpb5s8hqCJoDNHidGo5rrrdtOXf=FSv+XPU42MNzfw@mail.gmail.com> (raw)
In-Reply-To: <CAP-5=fVxz--VxTrHwgyY4VudhpqPqUUp=gdMA+t15EnrmTpsGg@mail.gmail.com>

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!

      reply	other threads:[~2023-06-23 18:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAM9d7chdqpb5s8hqCJoDNHidGo5rrrdtOXf=FSv+XPU42MNzfw@mail.gmail.com' \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adityag@linux.ibm.com \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).