]> www.infradead.org Git - users/jedix/linux-maple.git/commit
perf python: Check if there is space to copy all the event
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 12 Mar 2025 20:31:41 +0000 (17:31 -0300)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 18 Mar 2025 23:08:45 +0000 (16:08 -0700)
commit89aaeaf84231157288035b366cb6300c1c6cac64
tree5ef1ecaf363779db5e149332200e69a230e4618e
parentf3fed3ae34d606819d87a63d970cc3092a5be7ab
perf python: Check if there is space to copy all the event

The pyrf_event__new() method copies the event obtained from the perf
ring buffer to a structure that will then be turned into a python object
for further consumption, so it copies perf_event.header.size bytes to
its 'event' member:

  $ pahole -C pyrf_event /tmp/build/perf-tools-next/python/perf.cpython-312-x86_64-linux-gnu.so
  struct pyrf_event {
   PyObject                   ob_base;              /*     0    16 */
   struct evsel *             evsel;                /*    16     8 */
   struct perf_sample         sample;               /*    24   312 */

   /* XXX last struct has 7 bytes of padding, 2 holes */

   /* --- cacheline 5 boundary (320 bytes) was 16 bytes ago --- */
   union perf_event           event;                /*   336  4168 */

   /* size: 4504, cachelines: 71, members: 4 */
   /* member types with holes: 1, total: 2 */
   /* paddings: 1, sum paddings: 7 */
   /* last cacheline: 24 bytes */
  };

  $

It was doing so without checking if the event just obtained has more
than that space, fix it.

This isn't a proper, final solution, as we need to support larger
events, but for the time being we at least bounds check and document it.

Fixes: 877108e42b1b9ba6 ("perf tools: Initial python binding")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250312203141.285263-7-acme@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/python.c