Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: George Rurikov <g.ryurikov@securitycode.ru>
Cc: Heiner Kallweit <hkallweit1@gmail.com>,
	nic_swsd@realtek.com, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] r8169: Potential divizion by zero in rtl_set_coalesce()
Date: Wed, 25 Sep 2024 17:39:37 +0200	[thread overview]
Message-ID: <060a134b-63ea-4dc1-a5f3-980b2bb4334f@lunn.ch> (raw)
In-Reply-To: <20240925135106.2084111-1-g.ryurikov@securitycode.ru>

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

      reply	other threads:[~2024-09-25 15:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=060a134b-63ea-4dc1-a5f3-980b2bb4334f@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=g.ryurikov@securitycode.ru \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox