Skip to content

Commit 0307a0b

Browse files
edumazetdavem330
authored andcommitted
tcp: annotate data-races on tp->segs_in and tp->data_segs_in
tcp_segs_in() can be called from BH, while socket spinlock is held but socket owned by user, eventually reading these fields from tcp_get_info() Found by code inspection, no need to backport this patch to older kernels. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d2489c7 commit 0307a0b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/net/tcp.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,9 +2172,13 @@ static inline void tcp_segs_in(struct tcp_sock *tp, const struct sk_buff *skb)
21722172
u16 segs_in;
21732173

21742174
segs_in = max_t(u16, 1, skb_shinfo(skb)->gso_segs);
2175-
tp->segs_in += segs_in;
2175+
2176+
/* We update these fields while other threads might
2177+
* read them from tcp_get_info()
2178+
*/
2179+
WRITE_ONCE(tp->segs_in, tp->segs_in + segs_in);
21762180
if (skb->len > tcp_hdrlen(skb))
2177-
tp->data_segs_in += segs_in;
2181+
WRITE_ONCE(tp->data_segs_in, tp->data_segs_in + segs_in);
21782182
}
21792183

21802184
/*

net/ipv4/tcp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,10 +3769,12 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
37693769
tcp_get_info_chrono_stats(tp, info);
37703770

37713771
info->tcpi_segs_out = tp->segs_out;
3772-
info->tcpi_segs_in = tp->segs_in;
3772+
3773+
/* segs_in and data_segs_in can be updated from tcp_segs_in() from BH */
3774+
info->tcpi_segs_in = READ_ONCE(tp->segs_in);
3775+
info->tcpi_data_segs_in = READ_ONCE(tp->data_segs_in);
37733776

37743777
info->tcpi_min_rtt = tcp_min_rtt(tp);
3775-
info->tcpi_data_segs_in = tp->data_segs_in;
37763778
info->tcpi_data_segs_out = tp->data_segs_out;
37773779

37783780
info->tcpi_delivery_rate_app_limited = tp->rate_app_limited ? 1 : 0;

0 commit comments

Comments
 (0)