mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Eric Dumazet <edumazet@google.com>
Cc: netdev@vger.kernel.org, Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Stephen Hemminger <stephen@networkplumber.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 3/3] tcp_cubic: fix divide by zero and endless loop on bad module params
Date: Wed, 30 Sep 2026 22:03:33 +0800	[thread overview]
Message-ID: <79fda08f-46e5-4f98-8051-92dbebb1de73@linux.dev> (raw)
In-Reply-To: <CANn89iLwivMvNWC0oDgmQgTcKjrj_Ar8deh7Bc2jqyRXwv52tQ@mail.gmail.com>


On 9/30/26 7:21 PM, Eric Dumazet wrote:
> On Wed, Sep 30, 2026 at 12:10 PM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>> beta_scale and cube_factor are computed once at module init, and they
>> need 1024 - beta and bic_scale * 10 to be positive: beta == 1024 or
>> bic_scale == 0 crash right there, beta > 1024 or a negative bic_scale
>> gives garbage or wraps to 0. Negative beta can also make beta_scale 0.
>> Reject them.
>>
>> A small beta also gives a small beta_scale, and (cwnd * scale) >> 3
>> truncates to 0 for a tiny cwnd (e.g. 2), so the TCP friendliness loop
>> never ends. Clamp delta to 1.
>>
>> Fixes: df3271f3361b ("[TCP] BIC: CUBIC window growth (2.0)")
>> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
>> ---
>> Target net-next since it is not a big problem.
>> ---
>>   net/ipv4/tcp_cubic.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
>> index 119bf8cbb007c..2f04dca5be095 100644
>> --- a/net/ipv4/tcp_cubic.c
>> +++ b/net/ipv4/tcp_cubic.c
>> @@ -298,7 +298,7 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd, u32 acked)
>>          if (tcp_friendliness) {
>>                  u32 scale = beta_scale;
>>
>> -               delta = (cwnd * scale) >> 3;
> I would prefer not adding a test in the fast path to work around
> silly module parameters.
>
> beta_scale is computed once at module init, we can make sure it is >= 8
> there. tcp_snd_cwnd() is >= 1, so delta would be >= 1.


Agreed. beta_scale is 8 / alpha_cubic, so >= 8 just caps alpha_cubic
at 1


>
> With the integer divisions, beta_scale >= 8 iff beta >= 512,
> so the default beta (717 -> beta_scale = 15) is not affected.
>
>
>> +               delta = max((cwnd * scale) >> 3, 1U);
>>                  while (ca->ack_cnt > delta) {           /* update tcp cwnd */
>>                          ca->ack_cnt -= delta;
>>                          ca->tcp_cwnd++;
>> @@ -504,6 +504,11 @@ static int __init cubictcp_register(void)
>>
>>          BUILD_BUG_ON(sizeof(struct bictcp) > ICSK_CA_PRIV_SIZE);
>>
>> +       if (beta < 0 || beta >= BICTCP_BETA_SCALE || bic_scale <= 0) {
> bic_scale * 10 can overflow if bic_scale > INT_MAX / 10


Right, will add it.


>> +               pr_err("tcp_cubic: invalid beta %d or bic_scale %d\n", beta, bic_scale);
>> +               return -EINVAL;
>> +       }
>> +
> Something like this (untested) :
>
> if (beta < 0 || beta >= BICTCP_BETA_SCALE ||
>     bic_scale <= 0 || bic_scale > INT_MAX / 10) {
>      pr_err("tcp_cubic: invalid beta %d or bic_scale %d\n",
>        beta, bic_scale);
>      return -EINVAL;
> }
> /* Precompute a bunch of the scaling factors that are used per-packet
> * based on SRTT of 100ms
> */
> beta_scale = 8*(BICTCP_BETA_SCALE+beta) / 3
> / (BICTCP_BETA_SCALE - beta);
> /* bictcp_update() needs (cwnd * beta_scale) >> 3 to be >= 1 */
> beta_scale = max(beta_scale, 8U);
>
> Thanks.

  reply	other threads:[~2026-09-30 14:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 10:09 [PATCH net-next 0/3] tcp: fix a few divide-by-zero in congestion control modules Jiayuan Chen
2026-09-30 10:09 ` [PATCH net-next 1/3] tcp_bic: fix divide by zero on max_increment == 0 Jiayuan Chen
2026-09-30 11:22   ` Eric Dumazet
2026-09-30 10:09 ` [PATCH net-next 2/3] tcp_hybla: fix divide by zero on rtt0 " Jiayuan Chen
2026-09-30 11:23   ` Eric Dumazet
2026-09-30 10:09 ` [PATCH net-next 3/3] tcp_cubic: fix divide by zero and endless loop on bad module params Jiayuan Chen
2026-09-30 11:21   ` Eric Dumazet
2026-09-30 14:03     ` Jiayuan Chen [this message]
2026-09-30 10:14 ` [PATCH net-next 0/3] tcp: fix a few divide-by-zero in congestion control modules netdev-bot+sinfo

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=79fda08f-46e5-4f98-8051-92dbebb1de73@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stephen@networkplumber.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

all inboxes | Powered by JetHome®