From: mdshahid03@gmail.com
To: netdev@vger.kernel.org
Cc: edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, willemb@google.com,
Mohammad Shahid <mdshahid03@gmail.com>
Subject: [PATCH net v2] tcp: fix division by zero in tcp_cong_avoid_ai()
Date: Thu, 26 Nov 2026 22:11:50 +0530 [thread overview]
Message-ID: <20261126164150.8838-1-mdshahid03@gmail.com> (raw)
From: Mohammad Shahid <mdshahid03@gmail.com>
The tcp_cong_avoid_ai() function divides tp->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.
The function is also exposed as BPF kfunc through the bpf-tcp-cc
allowlist. The BPF verifier does not enforce a nonzero value for
this argument.
Return early when w is zero to prevent division by zero.
Fixes: e78aea8b2170 ("bpf: tcp: Put some tcp cong functions in allowlist for bpf-tcp-cc")
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-26 16:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 16:41 mdshahid03 [this message]
2026-11-26 16:43 ` [PATCH net v2] tcp: fix division by zero in tcp_cong_avoid_ai() netdev-bot+sinfo
2026-11-27 1:58 ` Jiayuan Chen
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=20261126164150.8838-1-mdshahid03@gmail.com \
--to=mdshahid03@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--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=willemb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.