* [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
@ 2024-06-25 7:52 Huai-Yuan Liu
2024-06-25 8:13 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Huai-Yuan Liu @ 2024-06-25 7:52 UTC (permalink / raw)
To: jes, davem, edumazet, kuba, pabeni
Cc: linux-hippi, netdev, linux-kernel, baijiaju1990, Huai-Yuan Liu
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.
Fixes: f33a7251c825 ("hippi: switch from 'pci_' to 'dma_' API")
Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
---
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(+)
diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
index aa8f828a0ae7..f4da342dd5cc 100644
--- a/drivers/net/hippi/rrunner.c
+++ b/drivers/net/hippi/rrunner.c
@@ -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,
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
2024-06-25 7:52 [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit() Huai-Yuan Liu
@ 2024-06-25 8:13 ` Eric Dumazet
0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2024-06-25 8:13 UTC (permalink / raw)
To: Huai-Yuan Liu
Cc: jes, davem, kuba, pabeni, linux-hippi, netdev, linux-kernel,
baijiaju1990
On Tue, Jun 25, 2024 at 9:52 AM Huai-Yuan Liu <qq810974084@gmail.com> wrote:
>
> 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.
How txctrl->pi can be modified by malicious hardware ? This is host
memory, not mapped to the device.
>
> 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 ?
> Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
> ---
> 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(+)
>
> diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
> index aa8f828a0ae7..f4da342dd5cc 100644
> --- a/drivers/net/hippi/rrunner.c
> +++ b/drivers/net/hippi/rrunner.c
> @@ -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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
2024-06-12 9:31 Huai-Yuan Liu
2024-06-12 17:20 ` Sunil Kovvuri Goutham
@ 2024-06-14 13:08 ` Paolo Abeni
1 sibling, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2024-06-14 13:08 UTC (permalink / raw)
To: Huai-Yuan Liu, jes, davem, edumazet, kuba
Cc: linux-hippi, netdev, linux-kernel, baijiaju1990
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 <qq810974084@gmail.com>
> ---
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
2024-06-12 9:31 Huai-Yuan Liu
@ 2024-06-12 17:20 ` Sunil Kovvuri Goutham
2024-06-14 13:08 ` Paolo Abeni
1 sibling, 0 replies; 5+ messages in thread
From: Sunil Kovvuri Goutham @ 2024-06-12 17:20 UTC (permalink / raw)
To: Huai-Yuan Liu, jes, davem, edumazet, kuba, pabeni
Cc: linux-hippi, netdev, linux-kernel, baijiaju1990
>-----Original Message-----
>From: Huai-Yuan Liu <qq810974084@gmail.com>
>Sent: Wednesday, June 12, 2024 3:02 PM
>To: jes@trained-monkey.org; davem@davemloft.net; edumazet@google.com;
>kuba@kernel.org; pabeni@redhat.com
>Cc: linux-hippi@sunsite.dk; netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
>baijiaju1990@gmail.com; Huai-Yuan Liu <qq810974084@gmail.com>
>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 <qq810974084@gmail.com>
>---
LGTM
Reviewed-by: Sunil Goutham <sgoutham@marvell.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
@ 2024-06-12 9:31 Huai-Yuan Liu
2024-06-12 17:20 ` Sunil Kovvuri Goutham
2024-06-14 13:08 ` Paolo Abeni
0 siblings, 2 replies; 5+ messages in thread
From: Huai-Yuan Liu @ 2024-06-12 9:31 UTC (permalink / raw)
To: jes, davem, edumazet, kuba, pabeni
Cc: linux-hippi, netdev, linux-kernel, baijiaju1990, Huai-Yuan Liu
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 <qq810974084@gmail.com>
---
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-25 8:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25 7:52 [PATCH] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit() Huai-Yuan Liu
2024-06-25 8:13 ` Eric Dumazet
-- strict thread matches above, loose matches on Subject: below --
2024-06-12 9:31 Huai-Yuan Liu
2024-06-12 17:20 ` Sunil Kovvuri Goutham
2024-06-14 13:08 ` Paolo Abeni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®