Skip to content

Commit 8f363b7

Browse files
netoptimizerdavem330
authored andcommitted
net: fix divide by zero in tcp algorithm illinois
Reading TCP stats when using TCP Illinois congestion control algorithm can cause a divide by zero kernel oops. The division by zero occur in tcp_illinois_info() at: do_div(t, ca->cnt_rtt); where ca->cnt_rtt can become zero (when rtt_reset is called) Steps to Reproduce: 1. Register tcp_illinois: # sysctl -w net.ipv4.tcp_congestion_control=illinois 2. Monitor internal TCP information via command "ss -i" # watch -d ss -i 3. Establish new TCP conn to machine Either it fails at the initial conn, or else it needs to wait for a loss or a reset. This is only related to reading stats. The function avg_delay() also performs the same divide, but is guarded with a (ca->cnt_rtt > 0) at its calling point in update_params(). Thus, simply fix tcp_illinois_info(). Function tcp_illinois_info() / get_info() is called without socket lock. Thus, eliminate any race condition on ca->cnt_rtt by using a local stack variable. Simply reuse info.tcpv_rttcnt, as its already set to ca->cnt_rtt. Function avg_delay() is not affected by this race condition, as its called with the socket lock. Cc: Petr Matousek <[email protected]> Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Eric Dumazet <[email protected]> Acked-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d3e9a1d commit 8f363b7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

net/ipv4/tcp_illinois.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,13 @@ static void tcp_illinois_info(struct sock *sk, u32 ext,
313313
.tcpv_rttcnt = ca->cnt_rtt,
314314
.tcpv_minrtt = ca->base_rtt,
315315
};
316-
u64 t = ca->sum_rtt;
317316

318-
do_div(t, ca->cnt_rtt);
319-
info.tcpv_rtt = t;
317+
if (info.tcpv_rttcnt > 0) {
318+
u64 t = ca->sum_rtt;
320319

320+
do_div(t, info.tcpv_rttcnt);
321+
info.tcpv_rtt = t;
322+
}
321323
nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
322324
}
323325
}

0 commit comments

Comments
 (0)