Skip to contentSkip to conversation

: Fix panic in bnx2_tx_int().

PATCH Applied Michael Chan 2 participants 2 messages Dec 14, 2006 – Dec 15, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 : Fix panic in bnx2_tx_int().

[BNX2]: Fix panic in bnx2_tx_int().

There was an off-by-one bug in bnx2_tx_avail(). If the tx ring is completely full, the producer and consumer indices may be apart by 256 even though the ring size is only 255. One entry in the ring is unused and must be properly accounted for when calculating the number of available entries. The bug caused the tx ring entries to be reused by mistake, overwriting active entries, and ultimately causing it to crash.

This bug rarely occurs because the tx ring is rarely completely full. We always stop when there is less than MAX_SKB_FRAGS entries available in the ring.

Thanks to Corey Kovacs <[email protected]> and Andy Gospodarek <[email protected]> for reporting the problem and helping to collect debug information.

drivers/net/bnx2.c +10 -3
index 7d824cf..f296c37 100644
@@ -217,9 +217,16 @@ static inline u32 bnx2_tx_avail(struct b
 	u32 diff;
 
 	smp_mb();
-	diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
-	if (diff > MAX_TX_DESC_CNT)
-		diff = (diff & MAX_TX_DESC_CNT) - 1;
+
+	/* The ring uses 256 indices for 255 entries, one of them
+	 * needs to be skipped.
+	 */
+	diff = bp->tx_prod - bp->tx_cons;
+	if (unlikely(diff >= TX_DESC_CNT)) {
+		diff &= 0xffff;
+		if (diff == TX_DESC_CNT)
+			diff = MAX_TX_DESC_CNT;
+	}
 	return (bp->tx_ring_size - diff);
 }
 
maintainer Applied
#1 lore raw

From: "Michael Chan" <[email protected]>
Date: Wed, 13 Dec 2006 18:30:33 -0800

Quoted 14 lines

[BNX2]: Fix panic in bnx2_tx_int().

There was an off-by-one bug in bnx2_tx_avail(). If the tx ring is completely full, the producer and consumer indices may be apart by 256 even though the ring size is only 255. One entry in the ring is unused and must be properly accounted for when calculating the number of available entries. The bug caused the tx ring entries to be reused by mistake, overwriting active entries, and ultimately causing it to crash.

This bug rarely occurs because the tx ring is rarely completely full. We always stop when there is less than MAX_SKB_FRAGS entries available in the ring.

Quoted 5 lines

Thanks to Corey Kovacs <[email protected]> and Andy Gospodarek <[email protected]> for reporting the problem and helping to collect debug information.

Applied, thanks.