Skip to content

Commit 918a1be

Browse files
edumazetgregkh
authored andcommitted
tcp: annotate data-races around tp->notsent_lowat
[ Upstream commit 1aeb87b ] tp->notsent_lowat can be read locklessly from do_tcp_getsockopt() and tcp_poll(). Fixes: c9bee3b ("tcp: TCP_NOTSENT_LOWAT socket option") Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent b02f8fc commit 918a1be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/net/tcp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,11 @@ void __tcp_v4_send_check(struct sk_buff *skb, __be32 saddr, __be32 daddr);
20592059
static inline u32 tcp_notsent_lowat(const struct tcp_sock *tp)
20602060
{
20612061
struct net *net = sock_net((struct sock *)tp);
2062-
return tp->notsent_lowat ?: READ_ONCE(net->ipv4.sysctl_tcp_notsent_lowat);
2062+
u32 val;
2063+
2064+
val = READ_ONCE(tp->notsent_lowat);
2065+
2066+
return val ?: READ_ONCE(net->ipv4.sysctl_tcp_notsent_lowat);
20632067
}
20642068

20652069
bool tcp_stream_memory_free(const struct sock *sk, int wake);

net/ipv4/tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,7 +3770,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
37703770
err = tcp_repair_set_window(tp, optval, optlen);
37713771
break;
37723772
case TCP_NOTSENT_LOWAT:
3773-
tp->notsent_lowat = val;
3773+
WRITE_ONCE(tp->notsent_lowat, val);
37743774
sk->sk_write_space(sk);
37753775
break;
37763776
case TCP_INQ:
@@ -4266,7 +4266,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
42664266
val = tcp_time_stamp_raw() + READ_ONCE(tp->tsoffset);
42674267
break;
42684268
case TCP_NOTSENT_LOWAT:
4269-
val = tp->notsent_lowat;
4269+
val = READ_ONCE(tp->notsent_lowat);
42704270
break;
42714271
case TCP_INQ:
42724272
val = tp->recvmsg_inq;

0 commit comments

Comments
 (0)