netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] r8169: Potential divizion by zero in rtl_set_coalesce()
@ 2024-09-25 13:51 George Rurikov
  2024-09-25 15:39 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: George Rurikov @ 2024-09-25 13:51 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: George Rurikov, nic_swsd, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, stable

Variable 'scale', whose possible value set allows a zero value in a check
at r8169_main.c:2014, is used as a denominator at r8169_main.c:2040 and
r8169_main.c:2042.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 2815b30535a0 ("r8169: merge scale for tx and rx irq coalescing")
Cc: stable@vger.kernel.org
Signed-off-by: George Rurikov <g.ryurikov@securitycode.ru>
---
 drivers/net/ethernet/realtek/r8169_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 45ac8befba29..b97e68cfcfad 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -2011,7 +2011,7 @@ static int rtl_set_coalesce(struct net_device *dev,

        coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs);
        scale = rtl_coalesce_choose_scale(tp, coal_usec_max, &cp01);
-       if (scale < 0)
+       if (scale <= 0)
                return scale;

        /* Accept max_frames=1 we returned in rtl_get_coalesce. Accept it
--
2.34.1

Заявление о конфиденциальности

Данное электронное письмо и любые приложения к нему являются конфиденциальными и предназначены исключительно для адресата. Если Вы не являетесь адресатом данного письма, пожалуйста, уведомите немедленно отправителя, не раскрывайте содержание другим лицам, не используйте его в каких-либо целях, не храните и не копируйте информацию любым способом.

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

* Re: [PATCH] r8169: Potential divizion by zero in rtl_set_coalesce()
  2024-09-25 13:51 [PATCH] r8169: Potential divizion by zero in rtl_set_coalesce() George Rurikov
@ 2024-09-25 15:39 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2024-09-25 15:39 UTC (permalink / raw)
  To: George Rurikov
  Cc: Heiner Kallweit, nic_swsd, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, stable

On Wed, Sep 25, 2024 at 04:51:06PM +0300, George Rurikov wrote:
> Variable 'scale', whose possible value set allows a zero value in a check
> at r8169_main.c:2014, is used as a denominator at r8169_main.c:2040 and
> r8169_main.c:2042.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 2815b30535a0 ("r8169: merge scale for tx and rx irq coalescing")
> Cc: stable@vger.kernel.org
> Signed-off-by: George Rurikov <g.ryurikov@securitycode.ru>
> ---
>  drivers/net/ethernet/realtek/r8169_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index 45ac8befba29..b97e68cfcfad 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -2011,7 +2011,7 @@ static int rtl_set_coalesce(struct net_device *dev,
> 
>         coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs);
>         scale = rtl_coalesce_choose_scale(tp, coal_usec_max, &cp01);
> -       if (scale < 0)
> +       if (scale <= 0)
>                 return scale;

Please think about this. Say scale is 0, and you return it. It appears
the call has worked, but in fact it did nothing.

I much prefer a division by 0, causing a splat, than the silent bug
you just added.

Also, please could you explain the code path which results in scale
being 0.

    Andrew

---
pw-bot: cr

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

end of thread, other threads:[~2024-09-25 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25 13:51 [PATCH] r8169: Potential divizion by zero in rtl_set_coalesce() George Rurikov
2024-09-25 15:39 ` Andrew Lunn

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).