* [PATCH] perf bench numa: add NULL check after calloc()
@ 2026-09-02 7:09 longlong yan
2026-09-25 14:27 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 2+ messages in thread
From: longlong yan @ 2026-09-02 7:09 UTC (permalink / raw)
To: acme
Cc: namhyung, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, james.clark, linux-perf-users, linux-kernel,
longlong yan
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] perf bench numa: add NULL check after calloc()
2026-09-02 7:09 [PATCH] perf bench numa: add NULL check after calloc() longlong yan
@ 2026-09-25 14:27 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-09-25 14:27 UTC (permalink / raw)
To: longlong yan
Cc: namhyung, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, james.clark, linux-perf-users, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-25 14:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-02 7:09 [PATCH] perf bench numa: add NULL check after calloc() longlong yan
2026-09-25 14:27 ` Arnaldo Carvalho de Melo
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®