Skip to content

Commit ad9f4f5

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: avoid a possible divide by zero
sysctl_tcp_tso_win_divisor might be set to zero while one cpu runs in tcp_tso_should_defer(). Make sure we dont allow a divide by zero by reading sysctl_tcp_tso_win_divisor exactly once. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c7757fd commit ad9f4f5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎net/ipv4/tcp_output.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
15121512
struct tcp_sock *tp = tcp_sk(sk);
15131513
const struct inet_connection_sock *icsk = inet_csk(sk);
15141514
u32 send_win, cong_win, limit, in_flight;
1515+
int win_divisor;
15151516

15161517
if (TCP_SKB_CB(skb)->flags & TCPHDR_FIN)
15171518
goto send_now;
@@ -1543,13 +1544,14 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
15431544
if ((skb != tcp_write_queue_tail(sk)) && (limit >= skb->len))
15441545
goto send_now;
15451546

1546-
if (sysctl_tcp_tso_win_divisor) {
1547+
win_divisor = ACCESS_ONCE(sysctl_tcp_tso_win_divisor);
1548+
if (win_divisor) {
15471549
u32 chunk = min(tp->snd_wnd, tp->snd_cwnd * tp->mss_cache);
15481550

15491551
/* If at least some fraction of a window is available,
15501552
* just use it.
15511553
*/
1552-
chunk /= sysctl_tcp_tso_win_divisor;
1554+
chunk /= win_divisor;
15531555
if (limit >= chunk)
15541556
goto send_now;
15551557
} else {

0 commit comments

Comments
 (0)