mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf jevents: Fix segfault in perf_pmu__find_events_table
@ 2023-09-18  3:03 Yang Jihong
  2023-09-18 23:55 ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Jihong @ 2023-09-18  3:03 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, irogers, adrian.hunter, linux-perf-users, linux-kernel
  Cc: yangjihong1

Before caching the JSON events table, perf_pmu__find_events_table() need
to check whether table is empty.

For example, AuthenticAMD-15-6B-1 is used. The matching events table cannot
be found. As a result, a null pointer is accessed when caching JSON events
table, causing segfault.

Before:
  # perf record -vv true
  DEBUGINFOD_URLS=
  Using CPUID AuthenticAMD-15-6B-1
  Segmentation fault (core dumped)

After:
  # perf record -vv true
  DEBUGINFOD_URLS=
  Using CPUID AuthenticAMD-15-6B-1
  <SNIP>
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.005 MB perf.data ]

Fixes: 7c52f10c0d4d ("perf pmu: Cache JSON events table")
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
 tools/perf/pmu-events/jevents.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index a7e88332276d..72ba4a9239c6 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -991,7 +991,7 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu)
                 }
         }
         free(cpuid);
-        if (!pmu)
+        if (!pmu || !table)
                 return table;
 
         for (i = 0; i < table->num_pmus; i++) {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-19  1:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18  3:03 [PATCH] perf jevents: Fix segfault in perf_pmu__find_events_table Yang Jihong
2023-09-18 23:55 ` Namhyung Kim
2023-09-19  1:50   ` Yang Jihong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®