Skip to content

Commit 870e3a6

Browse files
q2vendavem330
authored andcommitted
tcp: Fix data-races around sysctl_tcp_reflect_tos.
While reading sysctl_tcp_reflect_tos, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: ac8f171 ("tcp: reflect tos value received in SYN to the socket") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Acked-by: Wei Wang <weiwan@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 79f5547 commit 870e3a6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
10061006
if (skb) {
10071007
__tcp_v4_send_check(skb, ireq->ir_loc_addr, ireq->ir_rmt_addr);
10081008

1009-
tos = sock_net(sk)->ipv4.sysctl_tcp_reflect_tos ?
1009+
tos = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
10101010
(tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
10111011
(inet_sk(sk)->tos & INET_ECN_MASK) :
10121012
inet_sk(sk)->tos;
@@ -1526,7 +1526,7 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
15261526
/* Set ToS of the new socket based upon the value of incoming SYN.
15271527
* ECT bits are set later in tcp_init_transfer().
15281528
*/
1529-
if (sock_net(sk)->ipv4.sysctl_tcp_reflect_tos)
1529+
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
15301530
newinet->tos = tcp_rsk(req)->syn_tos & ~INET_ECN_MASK;
15311531

15321532
if (!dst) {

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
546546
if (np->repflow && ireq->pktopts)
547547
fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
548548

549-
tclass = sock_net(sk)->ipv4.sysctl_tcp_reflect_tos ?
549+
tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
550550
(tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
551551
(np->tclass & INET_ECN_MASK) :
552552
np->tclass;
@@ -1314,7 +1314,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
13141314
/* Set ToS of the new socket based upon the value of incoming SYN.
13151315
* ECT bits are set later in tcp_init_transfer().
13161316
*/
1317-
if (sock_net(sk)->ipv4.sysctl_tcp_reflect_tos)
1317+
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
13181318
newnp->tclass = tcp_rsk(req)->syn_tos & ~INET_ECN_MASK;
13191319

13201320
/* Clone native IPv6 options from listening socket (if any)

0 commit comments

Comments
 (0)