Skip to contentSkip to conversation

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

PATCH Applied Jakub Kicinski 3 participants 3 messages May 19, 2022 – May 20, 2022

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: ipa: don't proceed to out-of-bound write

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];
| ^~~~~~~

---
CC: [email protected]

---
 drivers/net/ipa/ipa_interrupt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ipa/ipa_interrupt.c +4 -2
index b35170a93b0f..307bed2ee707 100644
@@ -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);
Signature · 1 line
2.34.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jakub Kicinski

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]

Quoted 7 lines
   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];
       |                           ^~~~~~~

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.

Quoted 30 lines

---
CC: [email protected]

---
  drivers/net/ipa/ipa_interrupt.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ipa/ipa_interrupt.c +4 -2
index b35170a93b0f..307bed2ee707 100644
@@ -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);
#2 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 5 lines · 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]

Quoted 7 lines
  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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html