linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
@ 2023-08-01  3:15 Gustavo A. R. Silva
  2023-08-01 17:05 ` Florian Fainelli
  0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-01  3:15 UTC (permalink / raw)
  To: Markus Mayer, Broadcom internal kernel review list,
	Rafael J. Wysocki, Viresh Kumar, Florian Fainelli
  Cc: linux-pm, linux-arm-kernel, linux-kernel, Gustavo A. R. Silva,
	linux-hardening, Kees Cook

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.

Link: https://github.com/KSPP/linux/issues/324
Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
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(-)

diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index ffea6402189d..3052949aebbc 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
  2023-08-01  3:15 [PATCH v3] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug Gustavo A. R. Silva
@ 2023-08-01 17:05 ` Florian Fainelli
  2023-08-03  5:56   ` Viresh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2023-08-01 17:05 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Markus Mayer,
	Broadcom internal kernel review list, Rafael J. Wysocki,
	Viresh Kumar, Florian Fainelli
  Cc: linux-pm, linux-arm-kernel, linux-kernel, linux-hardening, Kees Cook

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

On 7/31/23 20:15, Gustavo A. R. Silva wrote:
> 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.
> 
> Link: https://github.com/KSPP/linux/issues/324
> Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
  2023-08-01 17:05 ` Florian Fainelli
@ 2023-08-03  5:56   ` Viresh Kumar
  2023-08-03 20:01     ` Gustavo A. R. Silva
  0 siblings, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2023-08-03  5:56 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Gustavo A. R. Silva, Markus Mayer,
	Broadcom internal kernel review list, Rafael J. Wysocki,
	linux-pm, linux-arm-kernel, linux-kernel, linux-hardening,
	Kees Cook

On 01-08-23, 10:05, Florian Fainelli wrote:
> On 7/31/23 20:15, Gustavo A. R. Silva wrote:
> > 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.
> > 
> > Link: https://github.com/KSPP/linux/issues/324
> > Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
  2023-08-03  5:56   ` Viresh Kumar
@ 2023-08-03 20:01     ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-03 20:01 UTC (permalink / raw)
  To: Viresh Kumar, Florian Fainelli
  Cc: Gustavo A. R. Silva, Markus Mayer,
	Broadcom internal kernel review list, Rafael J. Wysocki,
	linux-pm, linux-arm-kernel, linux-kernel, linux-hardening,
	Kees Cook



On 8/2/23 23:56, Viresh Kumar wrote:

> 
> Applied. Thanks.
> 

Great. :)

Thank you
--
Gustavo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-04  2:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-01  3:15 [PATCH v3] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug Gustavo A. R. Silva
2023-08-01 17:05 ` Florian Fainelli
2023-08-03  5:56   ` Viresh Kumar
2023-08-03 20:01     ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).