x86_energy_perf_policy: Harden update_cpufreq_scaling_freq()

Protect update_cpufreq_scaling_freq() from buffer overflow
if somehow it was called with a huge CPU number.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Len Brown 2026-05-06 10:00:00 -04:00
parent 481006fbcb
commit 74bd795c99

View File

@ -1167,12 +1167,12 @@ int ratio_2_sysfs_khz(int ratio)
*/
void update_cpufreq_scaling_freq(int is_max, int cpu, unsigned int ratio)
{
char pathname[64];
char pathname[96];
FILE *fp;
int retval;
int khz;
sprintf(pathname, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq", cpu, is_max ? "max" : "min");
snprintf(pathname, sizeof(pathname), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq", cpu, is_max ? "max" : "min");
fp = fopen(pathname, "w");
if (!fp) {