cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
Subsystems (3)
PATCH v3 1/1 cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
Allocate extra space for terminating element at:
drivers/cpufreq/brcmstb-avs-cpufreq.c:
449 table[i].frequency = CPUFREQ_TABLE_END;
and add code comment to make this clear.
This fixes the following -Warray-bounds warning seen after building
ARM with multi_v7_defconfig (GCC 13):
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -Warray-bounds.
---
Changes in v3:
- Allocate extra space for a terminating element. (Kees Cook)
- Update changelog text.
Changes in v2:
- Update changelog text. Add more details.
- Link: https://lore.kernel.org/linux-hardening/202307311610.B1EB796684@keescook/
v1:
- Link: https://lore.kernel.org/linux-hardening/ZMgfWEA0GAN%2FRog8@work/
drivers/cpufreq/brcmstb-avs-cpufreq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/cpufreq/brcmstb-avs-cpufreq.c +5 -1
@@ -434,7 +434,11 @@ brcm_avs_get_freq_table(struct device *dev, struct private_data *priv)if (ret)return ERR_PTR (ret); - table =devm_kcalloc (dev,AVS_PSTATE_MAX +1 ,sizeof (*table), +/* +* We allocate space for the 5 different P-STATES AVS, +* plus extra space for a terminating element. +*/ + table =devm_kcalloc (dev,AVS_PSTATE_MAX +1 +1 ,sizeof (*table),GFP_KERNEL );if (!table)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.34.1
Quoted 25 lines · Gustavo A. R. Silva
Allocate extra space for terminating element at:
drivers/cpufreq/brcmstb-avs-cpufreq.c:
449 table[i].frequency =CPUFREQ_TABLE_END;and add code comment to make this clear.
This fixes the following -Warray-bounds warning seen after building
ARM withmulti_v7_defconfig(GCC 13):
In function 'brcm_avs_get_freq_table',
inlined from 'brcm_avs_cpufreq_init' atdrivers/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 frominclude/linux/node.h:18,
frominclude/linux/cpu.h:17,
frominclude/linux/cpufreq.h:12,
fromdrivers/cpufreq/brcmstb-avs-cpufreq.c:44:
In function 'devm_kmalloc_array',
inlined from 'devm_kcalloc' atinclude/linux/device.h:328:9,
inlined from 'brcm_avs_get_freq_table' atdrivers/cpufreq/brcmstb-avs-cpufreq.c:437:10,
inlined from 'brcm_avs_cpufreq_init' atdrivers/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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 8 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -Warray-bounds.Fixes de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")Signed-off-by Gustavo A. R. Silva <[email protected]>
Signature · 1 line
Florian
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 30 lines · Florian Fainelli
Quoted 29 lines · Gustavo A. R. Silva
Allocate extra space for terminating element at:
drivers/cpufreq/brcmstb-avs-cpufreq.c:
449 table[i].frequency =CPUFREQ_TABLE_END;and add code comment to make this clear.
This fixes the following -Warray-bounds warning seen after building
ARM withmulti_v7_defconfig(GCC 13):
In function 'brcm_avs_get_freq_table',
inlined from 'brcm_avs_cpufreq_init' atdrivers/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 frominclude/linux/node.h:18,
frominclude/linux/cpu.h:17,
frominclude/linux/cpufreq.h:12,
fromdrivers/cpufreq/brcmstb-avs-cpufreq.c:44:
In function 'devm_kmalloc_array',
inlined from 'devm_kcalloc' atinclude/linux/device.h:328:9,
inlined from 'brcm_avs_get_freq_table' atdrivers/cpufreq/brcmstb-avs-cpufreq.c:437:10,
inlined from 'brcm_avs_cpufreq_init' atdrivers/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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -Warray-bounds.
Quoted 6 lines
Quoted 4 lines
Fixes de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Applied. Thanks.
Signature · 1 line
viresh
Quoted 3 lines · Viresh Kumar
Applied. Thanks.
Great. :)
Thank you
--
Gustavo
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel