]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/power turbostat: Fix illegal memory access when SMT is present and disabled
authorZhang Rui <rui.zhang@intel.com>
Wed, 4 Mar 2026 00:30:12 +0000 (08:30 +0800)
committerLen Brown <len.brown@intel.com>
Tue, 10 Mar 2026 18:58:50 +0000 (14:58 -0400)
When SMT is present and disabled, turbostat may under-size
the thread_data array.  This can corrupt results or
cause turbostat to exit with a segmentation fault.

[lenb: commit message]
Fixes: a2b4d0f8bf07 ("tools/power turbostat: Favor cpu# over core#")
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
tools/power/x86/turbostat/turbostat.c

index 1a2671c28209e436fd70e925051c44a84f4e7d41..ae827485950d89923cf293bcbc0a07f5d55b362e 100644 (file)
@@ -9702,13 +9702,12 @@ void allocate_counters(struct counters *counters)
 {
        int i;
        int num_cores = topo.cores_per_node * topo.nodes_per_pkg * topo.num_packages;
-       int num_threads = topo.threads_per_core * num_cores;
 
-       counters->threads = calloc(num_threads, sizeof(struct thread_data));
+       counters->threads = calloc(topo.max_cpu_num + 1, sizeof(struct thread_data));
        if (counters->threads == NULL)
                goto error;
 
-       for (i = 0; i < num_threads; i++)
+       for (i = 0; i < topo.max_cpu_num + 1; i++)
                (counters->threads)[i].cpu_id = -1;
 
        counters->cores = calloc(num_cores, sizeof(struct core_data));