[PATCH] perf synthetic-events: Check schedstat domain allocation failure
From: Hui Su
Date: Fri Sep 11 2026 - 23:12:25 EST
__synthesize_schedstat_domain() uses event after zalloc() without
checking for allocation failure, unlike __synthesize_schedstat_cpu().
If zalloc() fails and returns NULL, dereferencing ds->header.type
immediately crashes with a segmentation fault:
Program received signal SIGSEGV, Segmentation fault.
0x00005555558aed8a in __synthesize_schedstat_domain ()
#0 0x00005555558aed8a in __synthesize_schedstat_domain ()
#1 0x00005555558b889a in perf_event__synthesize_schedstat ()
#2 0x000055555563c397 in cmd_sched ()
#3 0x00005555556583a1 in handle_internal_command ()
#4 0x00005555555bf739 in main ()
perf_event__synthesize_schedstat() already treats a NULL event as an
error and cleans up, so return NULL when the allocation fails.
After this fix, an allocation failure returns NULL safely, allowing
the caller to exit gracefully without crashing:
[ perf sched stats: Failed !! ]
Fixes: c3030995f23b ("perf sched stats: Add record and rawdump support")
Signed-off-by: Hui Su <sh_def@xxxxxxx>
---
tools/perf/util/synthetic-events.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index 0c150193cca8..24559691b88e 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -2776,6 +2776,8 @@ static union perf_event *__synthesize_schedstat_domain(struct io *io, __u16 vers
size = sizeof(*ds);
size = PERF_ALIGN(size, sizeof(u64));
event = zalloc(size);
+ if (!event)
+ return NULL;
ds = &event->schedstat_domain;
ds->header.type = PERF_RECORD_SCHEDSTAT_DOMAIN;
--
2.55.0