Re: [PATCH] cpupower: Avoid uninitialized reads in topology sorting
From: Shuah
Date: Mon Aug 03 2026 - 13:42:03 EST
On 7/29/26 20:07, Ali Ahmet Memis wrote:
get_cpu_topology() allocates core_info with malloc(). If a topology
attribute disappears while CPUs are being hotplugged, an error path can
leave core_cpu_list uninitialized. __compare_core_cpu_list() then passes
the field to strcmp() while sorting the array.
Use calloc() for the array and ignore entries without complete topology
data when counting cores. Besides avoiding the invalid read, this keeps an
incomplete entry from being counted as a physical core.
Fixes: f89cb9cba7a2 ("cpupower: Implement CPU physical core querying")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ali Ahmet Memis <ali@xxxxxxxxxxxxxx>
---
Tested with a two-CPU topology mock that makes the second CPU's sysfs
reads fail. Valgrind reports uninitialized reads before this patch and
no errors after it.
Build-tested with:
make -C tools/power/cpupower NLS=false CPUFREQ_BENCH=false
Sorry I am not taking this patch.
Please note that build test just verifies that the code build which
fall way short of testing the changed code.
thanks,
-- Shuah