Netdev List
 help / color / mirror / Atom feed
* [PATCH] tcp: fix division by zero in tcp_cong_avoid_ai()
@ 2026-11-20 12:23 mdshahid03
  2026-11-20 12:27 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: mdshahid03 @ 2026-11-20 12:23 UTC (permalink / raw)
  To: edumazet, ncardwell, kuniyu, davem, kuba, pabeni
  Cc: horms, netdev, Mohammad Shahid

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


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

end of thread, other threads:[~2026-11-20 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 12:23 [PATCH] tcp: fix division by zero in tcp_cong_avoid_ai() mdshahid03
2026-11-20 12:27 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox