net: ethernet: mtk_eth_soc: fix off by one check of ARRAY_SIZE
Subsystems (4)
PATCH 1/1 net: ethernet: mtk_eth_soc: fix off by one check of ARRAY_SIZE
In mtk_wed_tx_ring_setup(.., int idx, ..), idx is used as an index here
struct mtk_wed_ring *ring = &dev->tx_ring[idx];
The bounds of idx are checked here
BUG_ON(idx > ARRAY_SIZE(dev->tx_ring));
If idx is the size of the array, it will pass this check and overflow. So change the check to >= .
--- drivers/net/ethernet/mediatek/mtk_wed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +1 -1
@@ -651,7 +651,7 @@ mtk_wed_tx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs)* WDMA RX. */ -BUG_ON (idx >ARRAY_SIZE (dev->tx_ring)); +BUG_ON (idx >=ARRAY_SIZE (dev->tx_ring));if (mtk_wed_ring_alloc (dev, ring,MTK_WED_TX_RING_SIZE ))return -ENOMEM ;
Signature · 1 line
2.27.0
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Sat, 16 Jul 2022 17:46:54 -0400 you wrote:
In
mtk_wed_tx_ring_setup(.., int idx, ..), idx is used as an index here
structmtk_wed_ring*ring = &dev->tx_ring[idx];The bounds of idx are checked here
BUG_ON(idx > ARRAY_SIZE(dev->tx_ring));If idx is the size of the array, it will pass this check and overflow. So change the check to >= .
[...]
Here is the summary with links:
- net: ethernet: mtk_eth_soc: fix off by one check of ARRAY_SIZE
https://git.kernel.org/netdev/net/c/3696c952da07
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html