2024-06-12 09:50:17

by Huai-Yuan Liu

[permalink] [raw]
Subject: [PATCH] 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.

Fixes: f33a7251c825 ("hippi: switch from 'pci_' to 'dma_' API")
Signed-off-by: Huai-Yuan Liu <[email protected]>
---
drivers/net/hippi/rrunner.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
index aa8f828a0ae7..184f0933bca0 100644
--- a/drivers/net/hippi/rrunner.c
+++ b/drivers/net/hippi/rrunner.c
@@ -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 < 0 || index >= TX_RING_ENTRIES) {
+ printk("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,
--
2.34.1



2024-06-12 17:20:56

by Sunil Kovvuri Goutham

[permalink] [raw]
Subject: RE: [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()



>-----Original Message-----
>From: Huai-Yuan Liu <[email protected]>
>Sent: Wednesday, June 12, 2024 3:02 PM
>To: [email protected]; [email protected]; [email protected];
>[email protected]; [email protected]
>Cc: [email protected]; [email protected]; [email protected];
>[email protected]; Huai-Yuan Liu <[email protected]>
>Subject: [EXTERNAL] [PATCH] 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
>
>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.
>
>Fixes: f33a7251c825 ("hippi: switch from 'pci_' to 'dma_' API")
>Signed-off-by: Huai-Yuan Liu <[email protected]>
>---

LGTM
Reviewed-by: Sunil Goutham <[email protected]>

2024-06-14 13:08:57

by Paolo Abeni

[permalink] [raw]
Subject: Re: [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()

On Wed, 2024-06-12 at 17:31 +0800, Huai-Yuan Liu wrote:
> 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.
>
> Fixes: f33a7251c825 ("hippi: switch from 'pci_' to 'dma_' API")
> Signed-off-by: Huai-Yuan Liu <[email protected]>
> ---
> drivers/net/hippi/rrunner.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
> index aa8f828a0ae7..184f0933bca0 100644
> --- a/drivers/net/hippi/rrunner.c
> +++ b/drivers/net/hippi/rrunner.c
> @@ -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 < 0 || index >= TX_RING_ENTRIES) {

'index' is u32, the first condition is not needed.

> + printk("invalid index value %02x\n", index);

please use netdev_err() instead.

Thanks,

Paolo