Skip to contentSkip to conversation

wifi: b43: fix OOB read and infinite loop from hardware-reported values

PATCH In review Tristan Madani 3 participants 7 messages Apr 15 – Apr 16 B43 wireless driver

lore
Share & tools
lore
#0 lore raw

v2 cover wifi: b43: fix OOB read and infinite loop from hardware-reported values

From: Tristan Madani <[email protected]>

Hi Johannes,

Note: this is a v2 resubmission. The original was sent via Gmail which caused HTML rendering issues. This version uses git send-email for proper plain-text formatting.

Two issues in b43 where hardware-reported values are used without bounds checking:

Proposed fixes in the following patches.

Thanks,
Tristan

#1 lore raw

PATCH v2 1/2 wifi: b43: fix infinite loop from invalid hardware DMA RX slot

From: Tristan Madani <[email protected]>

b43_dma_rx() reads current_slot from hardware via get_current_rxslot(). If the value is >= ring->nr_slots, the B43_WARN_ON only warns but continues. The for loop then never terminates because next_slot() wraps modulo nr_slots and can never reach the out-of-range current_slot.

Replace the B43_WARN_ON with an explicit bounds check that returns early when the hardware reports an invalid slot index.

Fixes e4d6b7951812 ("[B43]: add mac80211-based driver for modern BCM43xx devices")

---
drivers/net/wireless/broadcom/b43/dma.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/dma.c +4 -2
index XXXXXXX..XXXXXXX 100644
@@ -1693,7 +1693,10 @@ void b43_dma_rx(struct b43_dmaring *ring)
 	B43_WARN_ON(ring->tx);
 	current_slot = ops->get_current_rxslot(ring);
-	B43_WARN_ON(!(current_slot >= 0 && current_slot < ring->nr_slots));
+	if (!(current_slot >= 0 && current_slot < ring->nr_slots)) {
+		B43_WARN_ON(1);
+		return;
+	}
 
 	slot = ring->current_slot;
 	for (; slot != current_slot; slot = next_slot(ring, slot)) {
--

2.43.0

#4 lore raw

PATCH v2 2/2 wifi: b43: fix OOB read from hardware key index in b43_rx()

In reply to Tristan Madani

From: Tristan Madani <[email protected]>

The firmware-controlled key index in b43_rx() can exceed the dev->key[] array size (58 entries). The existing B43_WARN_ON is non-enforcing in production builds, allowing an out-of-bounds read of 1 byte from struct b43_firmware. A non-zero OOB value causes RX_FLAG_DECRYPTED to be incorrectly set on un-decrypted frames.

Replace with an enforcing check that skips the key lookup for invalid indices.

Fixes e4d6b7951812 ("[B43]: add mac80211-based driver for modern BCM43xx devices")

---
drivers/net/wireless/broadcom/b43/xmit.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/xmit.c +4 -1
index XXXXXXX..XXXXXXX 100644
@@ -704,7 +704,10 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
 		 */
 		keyidx = b43_kidx_to_raw(dev, keyidx);
-		B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key));
+		if (keyidx >= ARRAY_SIZE(dev->key)) {
+			b43dbg(dev->wl, "RX: invalid key index %u\n", keyidx);
+			goto drop;
+		}
 
 		if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
 			wlhdr_len = ieee80211_hdrlen(fctl);
 
#2 lore raw

Re: [PATCH v2 1/2] wifi: b43: fix infinite loop from invalid hardware DMA RX slot

In reply to Tristan Madani

Hi,

Quoted 22 lines · Tristan Madani

From: Tristan Madani <[email protected]>

b43_dma_rx() reads current_slot from hardware via get_current_rxslot(). If the value is >= ring->nr_slots, the B43_WARN_ON only warns but continues. The for loop then never terminates because next_slot() wraps modulo nr_slots and can never reach the out-of-range current_slot.

Replace the B43_WARN_ON with an explicit bounds check that returns early when the hardware reports an invalid slot index.

Fixes e4d6b7951812 ("[B43]: add mac80211-based driver for modern BCM43xx devices")

---
drivers/net/wireless/broadcom/b43/dma.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/dma.c +0 -0
index XXXXXXX..XXXXXXX 100644

drivers/net/wireless/broadcom/b43/dma.c void b43_dma_rx(struct b43_dmaring *ring) · line 1698

Quoted 7 lines
drivers/net/wireless/broadcom/b43/dma.c +4 -1
@@ -1693,7 +1693,10 @@ void b43_dma_rx(struct b43_dmaring *ring)
        B43_WARN_ON(ring->tx);
        current_slot = ops->get_current_rxslot(ring);
-       B43_WARN_ON(!(current_slot >= 0 && current_slot < ring->nr_slots));
+       if (!(current_slot >= 0 && current_slot < ring->nr_slots)) {
+               B43_WARN_ON(1);
+               return;
+       }

B43_WARN_ON() returns the condition's result, so you can shorten this to

if (B43_WARN_ON(!(current_slot >= 0 && current_slot < ring->nr_slots)))

        return;

Best regards,
Jonas

#5 lore raw

Re: [PATCH v2 2/2] wifi: b43: fix OOB read from hardware key index in b43_rx()

In reply to Tristan Madani

Hi,

Quoted 23 lines · Tristan Madani

From: Tristan Madani <[email protected]>

The firmware-controlled key index in b43_rx() can exceed the dev->key[] array size (58 entries). The existing B43_WARN_ON is non-enforcing in production builds, allowing an out-of-bounds read of 1 byte from struct b43_firmware. A non-zero OOB value causes RX_FLAG_DECRYPTED to be incorrectly set on un-decrypted frames.

Replace with an enforcing check that skips the key lookup for invalid indices.

Fixes e4d6b7951812 ("[B43]: add mac80211-based driver for modern BCM43xx devices")

---
drivers/net/wireless/broadcom/b43/xmit.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/xmit.c +0 -0
index XXXXXXX..XXXXXXX 100644

drivers/net/wireless/broadcom/b43/xmit.c void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) · line 709

Quoted 7 lines
drivers/net/wireless/broadcom/b43/xmit.c +4 -1
@@ -704,7 +704,10 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
                 */
                keyidx = b43_kidx_to_raw(dev, keyidx);
-               B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key));
+               if (keyidx >= ARRAY_SIZE(dev->key)) {
+                       b43dbg(dev->wl, "RX: invalid key index %u\n", keyidx);
+                       goto drop;
+               }

B43_WARN_ON() returns the condition's result, so if you keep it you can shorten this to

if (B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key)))

        goto drop;

Best regards,
Jonas

#3 lore raw

Re: [PATCH v2 1/2] wifi: b43: fix infinite loop from invalid hardware DMA RX slot

In reply to Jonas Gorski
Quoted 15 lines · On Thu, 16 Apr 2026 08:34:00 +0200 Jonas Gorski <[email protected]> wrote:

drivers/net/wireless/broadcom/b43/dma.c void b43_dma_rx(struct b43_dmaring *ring) · line 1698

Quoted 12 lines
drivers/net/wireless/broadcom/b43/dma.c +4 -1
index XXXXXXX..XXXXXXX 100644
@@ -1693,7 +1693,10 @@ void b43_dma_rx(struct b43_dmaring *ring)
        B43_WARN_ON(ring->tx);
        current_slot = ops->get_current_rxslot(ring);
-       B43_WARN_ON(!(current_slot >= 0 && current_slot < ring->nr_slots));
+       if (!(current_slot >= 0 && current_slot < ring->nr_slots)) {
+               B43_WARN_ON(1);
+               return;
+       }  

B43_WARN_ON() returns the condition's result, so you can shorten this to

Quoted 2 lines

if (B43_WARN_ON(!(current_slot >= 0 && current_slot < ring->nr_slots)))

        return;

Please also check the b43legacy driver. It may contain exactly the same code.

Signature · 2 lines
Michael Büsch
https://bues.ch/
#6 lore raw

Re: [PATCH v2 2/2] wifi: b43: fix OOB read from hardware key index in b43_rx()

In reply to Jonas Gorski
Quoted 16 lines · On Thu, 16 Apr 2026 08:34:11 +0200 Jonas Gorski <[email protected]> wrote:

drivers/net/wireless/broadcom/b43/xmit.c void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) · line 709

Quoted 12 lines
drivers/net/wireless/broadcom/b43/xmit.c +4 -1
index XXXXXXX..XXXXXXX 100644
@@ -704,7 +704,10 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
                 */
                keyidx = b43_kidx_to_raw(dev, keyidx);
-               B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key));
+               if (keyidx >= ARRAY_SIZE(dev->key)) {
+                       b43dbg(dev->wl, "RX: invalid key index %u\n", keyidx);
+                       goto drop;
+               }  

B43_WARN_ON() returns the condition's result, so if you keep it you can shorten this to

Quoted 2 lines

if (B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key)))

        goto drop;

Please also check the b43legacy driver. It may contain exactly the same code.

Signature · 2 lines
Michael Büsch
https://bues.ch/