diff mbox series

[net-next] net: ipa: don't proceed to out-of-bound write

Message ID 20220519004417.2109886-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit 1172aa6e4a195aaf5941ae89a93068cb9dd07b47
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: ipa: don't proceed to out-of-bound write | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jakub Kicinski May 19, 2022, 12:44 a.m. UTC
GCC 12 seems upset that we check ipa_irq against array bound
but then proceed, anyway:

drivers/net/ipa/ipa_interrupt.c: In function ‘ipa_interrupt_add’:
drivers/net/ipa/ipa_interrupt.c:196:27: warning: array subscript 30 is above array bounds of ‘void (*[30])(struct ipa *, enum ipa_irq_id)’ [-Warray-bounds]
  196 |         interrupt->handler[ipa_irq] = handler;
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~
drivers/net/ipa/ipa_interrupt.c:42:27: note: while referencing ‘handler’
   42 |         ipa_irq_handler_t handler[IPA_IRQ_COUNT];
      |                           ^~~~~~~

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: elder@kernel.org
---
 drivers/net/ipa/ipa_interrupt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Alex Elder May 19, 2022, 1:22 a.m. UTC | #1
On 5/18/22 7:44 PM, Jakub Kicinski wrote:
> GCC 12 seems upset that we check ipa_irq against array bound
> but then proceed, anyway:
> 
> drivers/net/ipa/ipa_interrupt.c: In function ‘ipa_interrupt_add’:
> drivers/net/ipa/ipa_interrupt.c:196:27: warning: array subscript 30 is above array bounds of ‘void (*[30])(struct ipa *, enum ipa_irq_id)’ [-Warray-bounds]
>    196 |         interrupt->handler[ipa_irq] = handler;
>        |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~
> drivers/net/ipa/ipa_interrupt.c:42:27: note: while referencing ‘handler’
>     42 |         ipa_irq_handler_t handler[IPA_IRQ_COUNT];
>        |                           ^~~~~~~
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Well, that's a reasonable thing to complain about.  I think when
I switched to using these WARN*() calls Leon said testing the
return value was unusual in the networking code.

In any case, this is a good fix.  The problem won't happen
anyway, so silencing the error this way is just fine.

Reviewed-by: Alex Elder <elder@linaro.org>

> ---
> CC: elder@kernel.org
> ---
>   drivers/net/ipa/ipa_interrupt.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ipa/ipa_interrupt.c b/drivers/net/ipa/ipa_interrupt.c
> index b35170a93b0f..307bed2ee707 100644
> --- a/drivers/net/ipa/ipa_interrupt.c
> +++ b/drivers/net/ipa/ipa_interrupt.c
> @@ -191,7 +191,8 @@ void ipa_interrupt_add(struct ipa_interrupt *interrupt,
>   	struct ipa *ipa = interrupt->ipa;
>   	u32 offset;
>   
> -	WARN_ON(ipa_irq >= IPA_IRQ_COUNT);
> +	if (WARN_ON(ipa_irq >= IPA_IRQ_COUNT))
> +		return;
>   
>   	interrupt->handler[ipa_irq] = handler;
>   
> @@ -208,7 +209,8 @@ ipa_interrupt_remove(struct ipa_interrupt *interrupt, enum ipa_irq_id ipa_irq)
>   	struct ipa *ipa = interrupt->ipa;
>   	u32 offset;
>   
> -	WARN_ON(ipa_irq >= IPA_IRQ_COUNT);
> +	if (WARN_ON(ipa_irq >= IPA_IRQ_COUNT))
> +		return;
>   
>   	/* Update the IPA interrupt mask to disable it */
>   	interrupt->enabled &= ~BIT(ipa_irq);
patchwork-bot+netdevbpf@kernel.org May 20, 2022, 1:50 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 18 May 2022 17:44:17 -0700 you wrote:
> GCC 12 seems upset that we check ipa_irq against array bound
> but then proceed, anyway:
> 
> drivers/net/ipa/ipa_interrupt.c: In function ‘ipa_interrupt_add’:
> drivers/net/ipa/ipa_interrupt.c:196:27: warning: array subscript 30 is above array bounds of ‘void (*[30])(struct ipa *, enum ipa_irq_id)’ [-Warray-bounds]
>   196 |         interrupt->handler[ipa_irq] = handler;
>       |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~
> drivers/net/ipa/ipa_interrupt.c:42:27: note: while referencing ‘handler’
>    42 |         ipa_irq_handler_t handler[IPA_IRQ_COUNT];
>       |                           ^~~~~~~
> 
> [...]

Here is the summary with links:
  - [net-next] net: ipa: don't proceed to out-of-bound write
    https://git.kernel.org/netdev/net-next/c/1172aa6e4a19

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ipa/ipa_interrupt.c b/drivers/net/ipa/ipa_interrupt.c
index b35170a93b0f..307bed2ee707 100644
--- a/drivers/net/ipa/ipa_interrupt.c
+++ b/drivers/net/ipa/ipa_interrupt.c
@@ -191,7 +191,8 @@  void ipa_interrupt_add(struct ipa_interrupt *interrupt,
 	struct ipa *ipa = interrupt->ipa;
 	u32 offset;
 
-	WARN_ON(ipa_irq >= IPA_IRQ_COUNT);
+	if (WARN_ON(ipa_irq >= IPA_IRQ_COUNT))
+		return;
 
 	interrupt->handler[ipa_irq] = handler;
 
@@ -208,7 +209,8 @@  ipa_interrupt_remove(struct ipa_interrupt *interrupt, enum ipa_irq_id ipa_irq)
 	struct ipa *ipa = interrupt->ipa;
 	u32 offset;
 
-	WARN_ON(ipa_irq >= IPA_IRQ_COUNT);
+	if (WARN_ON(ipa_irq >= IPA_IRQ_COUNT))
+		return;
 
 	/* Update the IPA interrupt mask to disable it */
 	interrupt->enabled &= ~BIT(ipa_irq);