tools/perf/bench/numa.c | 2 ++ 1 file changed, 2 insertions(+)
Two calloc() calls in the numa benchmark lack NULL return checks,
leading to potential NULL pointer dereferences on allocation failure:
1. worker_process(): the allocated `pthreads` array is used in the
following for-loop via pthreads[t] without checking for NULL.
2. __bench_numa(): the allocated `pids` array is used in the following
for-loop via pids[i] without checking for NULL.
Add BUG_ON() checks after each calloc(), consistent with the existing
NULL check style used elsewhere in the same file (e.g., node_present
and nodes allocations).
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
tools/perf/bench/numa.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 42d7afc03f9b..371a74e3da1b 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -1419,6 +1419,7 @@ static void worker_process(int process_nr)
bind_to_cpumask(td->bind_cpumask);
pthreads = calloc(g->p.nr_threads, sizeof(pthread_t));
+ BUG_ON(!pthreads);
process_data = setup_private_data(g->p.bytes_process);
if (g->p.show_details >= 3) {
@@ -1625,6 +1626,7 @@ static int __bench_numa(const char *name)
return -1;
pids = calloc(g->p.nr_proc, sizeof(*pids));
+ BUG_ON(!pids);
pid = -1;
if (g->p.serialize_startup) {
--
2.43.0
On Wed, Sep 02, 2026 at 03:09:13PM +0800, longlong yan wrote: > Two calloc() calls in the numa benchmark lack NULL return checks, > leading to potential NULL pointer dereferences on allocation failure: > > 1. worker_process(): the allocated `pthreads` array is used in the > following for-loop via pthreads[t] without checking for NULL. > > 2. __bench_numa(): the allocated `pids` array is used in the following > for-loop via pids[i] without checking for NULL. > > Add BUG_ON() checks after each calloc(), consistent with the existing > NULL check style used elsewhere in the same file (e.g., node_present > and nodes allocations). Thanks, applied to perf-tools-next, for v7.4. - Arnaldo
© 2016 - 2026 Red Hat, Inc.