Skip to contentSkip to conversation

perf jevents: Fix segfault in perf_pmu__find_events_table

PATCH In review Yang Jihong 2 participants 3 messages Sep 18, 2023 – Sep 19, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf jevents: Fix segfault in perf_pmu__find_events_table

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")
---
 tools/perf/pmu-events/jevents.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/pmu-events/jevents.py +1 -1
index a7e88332276d..72ba4a9239c6 100755
@@ -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++) {
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hello,

Quoted 22 lines · Yang Jihong

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 ]
Quoted 2 lines
Fixes 7c52f10c0d4d ("perf pmu: Cache JSON events table")

Thanks for the fix but please see

https://lore.kernel.org/all/[email protected]/

Thanks,
Namhyung

Quoted 20 lines
---
 tools/perf/pmu-events/jevents.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/pmu-events/jevents.py +1 -2
index a7e88332276d..72ba4a9239c6 100755
@@ -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

#2 lore raw

Hello,

Quoted 25 lines · Namhyung Kim

Hello,

Quoted 22 lines · Yang Jihong

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 ]
Quoted 7 lines
Quoted 2 lines
Fixes 7c52f10c0d4d ("perf pmu: Cache JSON events table")

Thanks for the fix but please see

https://lore.kernel.org/all/[email protected]/

Uh.. no notice that there is already a fix, please ignore it.

Thanks,
Yang