From: mdshahid03@gmail.com
To: edumazet@google.com, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com
Cc: horms@kernel.org, netdev@vger.kernel.org,
Mohammad Shahid <mdshahid03@gmail.com>
Subject: [PATCH] tcp: fix division by zero in tcp_cong_avoid_ai()
Date: Fri, 20 Nov 2026 17:53:48 +0530 [thread overview]
Message-ID: <20261120122348.207708-1-mdshahid03@gmail.com> (raw)
From: Mohammad Shahid <mdshahid03@gmail.com>
The tcp_cong_avoid_ai() function divides snd_cwnd_cnt by the
argument w without checking whether w is zero.
Since w is an unsigned value, the condition tp->snd_cwnd_cnt
>=w does not prevent division by zero when w is zero.
This function is also exposed as BPF kfunc, and the BPF
verifier does not enforce a nonzero value for this argunement
Return early when w is zero to avoid divison by zero.
Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
net/ipv4/tcp_cong.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 8e83ef81fc18..f70f49b4b1e7 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -469,6 +469,9 @@ EXPORT_SYMBOL_GPL(tcp_slow_start);
*/
__bpf_kfunc void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked)
{
+ if (unlikely(!w))
+ return;
+
/* If credits accumulated at a higher w, apply them gently now. */
if (tp->snd_cwnd_cnt >= w) {
tp->snd_cwnd_cnt = 0;
--
2.43.0
next reply other threads:[~2026-11-20 12:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 12:23 mdshahid03 [this message]
2026-11-20 12:27 ` [PATCH] tcp: fix division by zero in tcp_cong_avoid_ai() 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=20261120122348.207708-1-mdshahid03@gmail.com \
--to=mdshahid03@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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