hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
Subsystems (2)
PATCH 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 assigned to txctrl. However, txctrl->pi can be modified by malicious hardware at any time. Because txctrl->pi is assigned to index, buffer overflow may occur when the code "rrpriv->tx_skbuff[index]" is executed.
To address this issue, ensure index is 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.
V3:
* In patch V3, we stop the queue before return BUSY. Thanks to Jakub Kicinski for his advice.
V4:
* In patch V4, we revise the wording in the description. Thanks to Markus Elfring for pointing this out.
--- drivers/net/hippi/rrunner.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/hippi/rrunner.c +6 -0
@@ -1440,6 +1440,12 @@ 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); +netif_stop_queue (dev); +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 5 lines · Huai-Yuan Liu
The value
rrpriv->info->tx_ctrlis stored in DMA memory, and assigned to txctrl. However,txctrl->pican be modified by malicious hardware at any time. Becausetxctrl->piis assigned to index, buffer overflow may occur when the code "rrpriv->tx_skbuff[index]" is executed.
How txctrl->pi can be modified by malicious hardware ? This is host memory, not mapped to the device.
Quoted 4 lines
To address this issue, ensure index is checked.
Fixes f33a7251c825 ("hippi: switch from 'pci_' to 'dma_' API")
Is it just me or this Fixes: tag is not relevant ?
Quoted 21 lines
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.
V3:
* In patch V3, we stop the queue before return BUSY. Thanks to Jakub Kicinski for his advice.
V4:
* In patch V4, we revise the wording in the description. Thanks to Markus Elfring for pointing this out.--- drivers/net/hippi/rrunner.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/hippi/rrunner.c +0
-0
drivers/net/hippi/rrunner.c static netdev_tx_t rr_start_xmit(struct sk_buff *skb, · line 1448
Quoted 9 lines
drivers/net/hippi/rrunner.c +6
-0@@ -1440,6 +1440,12 @@ 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); +netif_stop_queue (dev); +spin_unlock_irqrestore (&rrpriv->lock, flags); +return NETDEV_TX_BUSY ; + }
When seeing this patch, my initial reaction was : array_index_nospec() is missing.
But then :
If a malicious hardware can control txctl->pi, then it will cause multiple UAF or skb leaks if txctrl->pi
is kept below TX_RING_ENTRIES.
This driver should keep a trusted copy of txctrl->pi field, only seen by itself, and not read it from the untrusted device.
Otherwise, this patch is only adding a lot of confusion.