hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
Subsystems (2)
PATCH v2 1/1 hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
The value rrpriv->info->tx_ctrl is stored in DMA memory, and it is assigned to txctrl, so txctrl->pi can be modified at any time by malicious hardware. Becausetxctrl->pi is assigned to index, buffer overflow may occur when the code "rrpriv->tx_skbuff[index]" is executed.
To address this issue, the index should be checked.
---
V2:
* In patch V2, we remove the first condition in if statement and use netdev_err() instead of printk().
Thanks Paolo Abeni for helpful advice.
--- drivers/net/hippi/rrunner.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/hippi/rrunner.c +5 -0
@@ -1440,6 +1440,11 @@ static netdev_tx_t rr_start_xmit(struct sk_buff *skb, txctrl = &rrpriv->info->tx_ctrl; index = txctrl->pi; +if (index >=TX_RING_ENTRIES ) { +netdev_err (dev,"invalid index value %02x\n" , index); +spin_unlock_irqrestore (&rrpriv->lock, flags); +return NETDEV_TX_BUSY ; + } rrpriv->tx_skbuff[index] = skb; set_rraddr(&rrpriv->tx_ring[index].addr,
Signature · 1 line
2.34.1
Quoted 23 lines
The value
rrpriv->info->tx_ctrlis stored in DMA memory, and it is assigned to txctrl, sotxctrl->pican be modified at any time by malicious hardware.Becausetxctrl->piis assigned to index, buffer overflow may occur when the code "rrpriv-Quoted 1 line
tx_skbuff[index]" is executed.
To address this issue, the index should be checked.
Fixes f33a7251c825 ("hippi: switch from 'pci_' to 'dma_' API")Signed-off-by Huai-Yuan Liu <[email protected]>---
V2:
* In patch V2, we remove the first condition in if statement and usenetdev_err()instead ofprintk().
Thanks Paolo Abeni for helpful advice.
---drivers/net/hippi/rrunner.c| 5 +++++1 file changed, 5 insertions(+)drivers/net/hippi/rrunner.c index renamed from drivers/net/hippi/rrunner.c +0
-0
aa8f828a0ae7..6b0056ced922100644
drivers/net/hippi/rrunner.c static netdev_tx_t rr_start_xmit(struct sk_buff *skb, · line 1444
Quoted 5 lines
drivers/net/hippi/rrunner.c +2
-0@@ -1440,6 +1440,11 @@ static netdev_tx_t rr_start_xmit(struct sk_buff *skb, txctrl = &rrpriv->info->tx_ctrl; index = txctrl->pi; +if (index >=TX_RING_ENTRIES ) { +netdev_err (dev,"invalid index value %02x\n" , index);
Much better would be to use netif_msg_tx_err which can be enabled/disabled instead of dumping on console, which would be annoying if there are many errors.
Thanks,
Sunil.
Jakub Kicinski
maintainerQuoted 6 lines · On Fri, 21 Jun 2024 05:11:41 +0000 Sunil Kovvuri Goutham wrote:
drivers/net/hippi/rrunner.c static netdev_tx_t rr_start_xmit(struct sk_buff *skb, · line 1444
Quoted 2 lines
drivers/net/hippi/rrunner.c +2
-0+if (index >=TX_RING_ENTRIES ) { +netdev_err (dev,"invalid index value %02x\n" , index);Much better would be to use
netif_msg_tx_errwhich can be enabled/disabled instead of dumping on console, which would be annoying if there are many errors.
Doesn't it require ethtool to be changed tho? This driver doesn't have any ethtool ops AFAICT. I'd go for netdev_err_once().
But more importantly, I think you should stop the queue before returning BUSY.