diff mbox series

[V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit()

Message ID 20240620122311.424811-1-qq810974084@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [V2] hippi: fix possible buffer overflow caused by bad DMA value in rr_start_xmit() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 842 this patch: 842
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 1 blamed authors not CCed: christophe.jaillet@wanadoo.fr; 1 maintainers not CCed: christophe.jaillet@wanadoo.fr
netdev/build_clang success Errors and warnings before: 849 this patch: 849
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 849 this patch: 849
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-21--03-00 (tests: 659)

Commit Message

Huai-Yuan Liu June 20, 2024, 12:23 p.m. UTC
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(+)

Comments

Sunil Kovvuri Goutham June 21, 2024, 5:11 a.m. UTC | #1
>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.
Jakub Kicinski June 21, 2024, 3:34 p.m. UTC | #2
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.
diff mbox series

Patch

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,