* [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch()
@ 2023-06-08 4:12 Gustavo A. R. Silva
2023-06-08 8:09 ` Ard Biesheuvel
2023-06-14 8:07 ` Tony Lindgren
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-06-08 4:12 UTC (permalink / raw)
To: Tony Lindgren, Russell King, Peter 'p2' De Schrijver,
Kevin Hilman
Cc: linux-omap, linux-arm-kernel, linux-kernel, Gustavo A. R. Silva,
linux-hardening
If function pwrdm_read_prev_pwrst() returns -EINVAL, we will end
up accessing array pwrdm->state_counter through negative index
-22. This is wrong and the compiler is legitimately warning us
about this potential problem.
Fix this by sanity checking the value stored in variable _prev_
before accessing array pwrdm->state_counter.
Address the following -Warray-bounds warning:
arch/arm/mach-omap2/powerdomain.c:178:45: warning: array subscript -22 is below array bounds of 'unsigned int[4]' [-Warray-bounds]
Link: https://github.com/KSPP/linux/issues/307
Fixes: ba20bb126940 ("OMAP: PM counter infrastructure.")
Cc: stable@vger.kernel.org
Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/20230607050639.LzbPn%25lkp@intel.com/
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
arch/arm/mach-omap2/powerdomain.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c
index 777f9f8e7cd8..5e05dd1324e7 100644
--- a/arch/arm/mach-omap2/powerdomain.c
+++ b/arch/arm/mach-omap2/powerdomain.c
@@ -174,7 +174,7 @@ static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
break;
case PWRDM_STATE_PREV:
prev = pwrdm_read_prev_pwrst(pwrdm);
- if (pwrdm->state != prev)
+ if (prev >= 0 && pwrdm->state != prev)
pwrdm->state_counter[prev]++;
if (prev == PWRDM_POWER_RET)
_update_logic_membank_counters(pwrdm);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch()
2023-06-08 4:12 [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch() Gustavo A. R. Silva
@ 2023-06-08 8:09 ` Ard Biesheuvel
2023-06-14 8:07 ` Tony Lindgren
1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2023-06-08 8:09 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Tony Lindgren, Russell King, Peter 'p2' De Schrijver,
Kevin Hilman, linux-omap, linux-arm-kernel, linux-kernel,
linux-hardening
On Thu, 8 Jun 2023 at 06:11, Gustavo A. R. Silva <gustavoars@kernel.org> wrote:
>
> If function pwrdm_read_prev_pwrst() returns -EINVAL, we will end
> up accessing array pwrdm->state_counter through negative index
> -22. This is wrong and the compiler is legitimately warning us
> about this potential problem.
>
> Fix this by sanity checking the value stored in variable _prev_
> before accessing array pwrdm->state_counter.
>
> Address the following -Warray-bounds warning:
> arch/arm/mach-omap2/powerdomain.c:178:45: warning: array subscript -22 is below array bounds of 'unsigned int[4]' [-Warray-bounds]
>
> Link: https://github.com/KSPP/linux/issues/307
> Fixes: ba20bb126940 ("OMAP: PM counter infrastructure.")
> Cc: stable@vger.kernel.org
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/lkml/20230607050639.LzbPn%25lkp@intel.com/
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Nice to see this work paying off.
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Does the error case need further handling here?
> ---
> arch/arm/mach-omap2/powerdomain.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c
> index 777f9f8e7cd8..5e05dd1324e7 100644
> --- a/arch/arm/mach-omap2/powerdomain.c
> +++ b/arch/arm/mach-omap2/powerdomain.c
> @@ -174,7 +174,7 @@ static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
> break;
> case PWRDM_STATE_PREV:
> prev = pwrdm_read_prev_pwrst(pwrdm);
> - if (pwrdm->state != prev)
> + if (prev >= 0 && pwrdm->state != prev)
> pwrdm->state_counter[prev]++;
> if (prev == PWRDM_POWER_RET)
> _update_logic_membank_counters(pwrdm);
> --
> 2.34.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch()
2023-06-08 4:12 [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch() Gustavo A. R. Silva
2023-06-08 8:09 ` Ard Biesheuvel
@ 2023-06-14 8:07 ` Tony Lindgren
1 sibling, 0 replies; 3+ messages in thread
From: Tony Lindgren @ 2023-06-14 8:07 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Russell King, Peter 'p2' De Schrijver, Kevin Hilman,
linux-omap, linux-arm-kernel, linux-kernel, linux-hardening
* Gustavo A. R. Silva <gustavoars@kernel.org> [230608 07:11]:
> If function pwrdm_read_prev_pwrst() returns -EINVAL, we will end
> up accessing array pwrdm->state_counter through negative index
> -22. This is wrong and the compiler is legitimately warning us
> about this potential problem.
>
> Fix this by sanity checking the value stored in variable _prev_
> before accessing array pwrdm->state_counter.
>
> Address the following -Warray-bounds warning:
> arch/arm/mach-omap2/powerdomain.c:178:45: warning: array subscript -22 is below array bounds of 'unsigned int[4]' [-Warray-bounds]
Thanks applying into omap-for-v6.5/cleanup, seems this can wait
for the merge window.
Regards,
Tony
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-14 8:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 4:12 [PATCH][next] ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch() Gustavo A. R. Silva
2023-06-08 8:09 ` Ard Biesheuvel
2023-06-14 8:07 ` Tony Lindgren
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).