KSPP / linux

Linux kernel source tree (Kernel Self Protection Project)
https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project
Other
82 stars 5 forks source link

Address -Warray-bounds warning in drivers/cpufreq/brcmstb-avs-cpufreq.c #324

Closed GustavoARSilva closed 8 months ago

GustavoARSilva commented 1 year ago
In function 'brcm_avs_get_freq_table',
    inlined from 'brcm_avs_cpufreq_init' at drivers/cpufreq/brcmstb-avs-cpufreq.c:623:15:
drivers/cpufreq/brcmstb-avs-cpufreq.c:449:28: warning: array subscript 5 is outside array bounds of 'void[60]' [-Warray-bounds=]
  449 |         table[i].frequency = CPUFREQ_TABLE_END;
In file included from include/linux/node.h:18,
                 from include/linux/cpu.h:17,
                 from include/linux/cpufreq.h:12,
                 from drivers/cpufreq/brcmstb-avs-cpufreq.c:44:
In function 'devm_kmalloc_array',
    inlined from 'devm_kcalloc' at include/linux/device.h:328:9,
    inlined from 'brcm_avs_get_freq_table' at drivers/cpufreq/brcmstb-avs-cpufreq.c:437:10,
    inlined from 'brcm_avs_cpufreq_init' at drivers/cpufreq/brcmstb-avs-cpufreq.c:623:15:
include/linux/device.h:323:16: note: at offset 60 into object of size 60 allocated by 'devm_kmalloc'
  323 |         return devm_kmalloc(dev, bytes, flags);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Audit this piece of code:

437         table = devm_kcalloc(dev, AVS_PSTATE_MAX + 1, sizeof(*table),
438                              GFP_KERNEL);
439         if (!table)
440                 return ERR_PTR(-ENOMEM);
441 
442         for (i = AVS_PSTATE_P0; i <= AVS_PSTATE_MAX; i++) {
443                 ret = brcm_avs_set_pstate(priv, i);
444                 if (ret)
445                         return ERR_PTR(ret);
446                 table[i].frequency = brcm_avs_get_frequency(priv->base);
447                 table[i].driver_data = i;
448         }
449         table[i].frequency = CPUFREQ_TABLE_END;
kees commented 8 months ago

Fixed in commit e520d0b6be950ce3738cf4b9bd3b392be818f1dc.