netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
@ 2024-06-20 12:23 Huai-Yuan Liu
  2024-06-21  5:11 ` Sunil Kovvuri Goutham
  0 siblings, 1 reply; 3+ messages in thread
From: Huai-Yuan Liu @ 2024-06-20 12:23 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>
---
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(+)

diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
index aa8f828a0ae7..6b0056ced922 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 >= 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,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
  2024-06-20 12:23 [PATCH V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit() Huai-Yuan Liu
@ 2024-06-21  5:11 ` Sunil Kovvuri Goutham
  2024-06-21 15:34   ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Sunil Kovvuri Goutham @ 2024-06-21  5:11 UTC (permalink / raw)
  To: Huai-Yuan Liu, 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

>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>
>---
>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(+)
>
>diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c index
>aa8f828a0ae7..6b0056ced922 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 >= 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()
  2024-06-21  5:11 ` Sunil Kovvuri Goutham
@ 2024-06-21 15:34   ` Jakub Kicinski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2024-06-21 15:34 UTC (permalink / raw)
  To: Sunil Kovvuri Goutham
  Cc: Huai-Yuan Liu, jes@trained-monkey.org, davem@davemloft.net,
	edumazet@google.com, pabeni@redhat.com, linux-hippi@sunsite.dk,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com

On Fri, 21 Jun 2024 05:11:41 +0000 Sunil Kovvuri Goutham wrote:
> >+	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.

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-21 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 12:23 [PATCH V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit() Huai-Yuan Liu
2024-06-21  5:11 ` Sunil Kovvuri Goutham
2024-06-21 15:34   ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).