Skip to content

Commit 04b96d8

Browse files
author
Guillaume Nault
committed
tcp: Fix data-races around sysctl_tcp_reflect_tos.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160073 Upstream Status: linux.git commit 870e3a6 Author: Kuniyuki Iwashima <kuniyu@amazon.com> Date: Fri Jul 22 11:22:04 2022 -0700 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> Signed-off-by: Guillaume Nault <gnault@redhat.com>
1 parent e1b28db commit 04b96d8

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
@@ -1000,7 +1000,7 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
10001000
if (skb) {
10011001
__tcp_v4_send_check(skb, ireq->ir_loc_addr, ireq->ir_rmt_addr);
10021002

1003-
tos = sock_net(sk)->ipv4.sysctl_tcp_reflect_tos ?
1003+
tos = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
10041004
(tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
10051005
(inet_sk(sk)->tos & INET_ECN_MASK) :
10061006
inet_sk(sk)->tos;
@@ -1514,7 +1514,7 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
15141514
/* Set ToS of the new socket based upon the value of incoming SYN.
15151515
* ECT bits are set later in tcp_init_transfer().
15161516
*/
1517-
if (sock_net(sk)->ipv4.sysctl_tcp_reflect_tos)
1517+
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
15181518
newinet->tos = tcp_rsk(req)->syn_tos & ~INET_ECN_MASK;
15191519

15201520
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;
@@ -1313,7 +1313,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
13131313
/* Set ToS of the new socket based upon the value of incoming SYN.
13141314
* ECT bits are set later in tcp_init_transfer().
13151315
*/
1316-
if (sock_net(sk)->ipv4.sysctl_tcp_reflect_tos)
1316+
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
13171317
newnp->tclass = tcp_rsk(req)->syn_tos & ~INET_ECN_MASK;
13181318

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

0 commit comments

Comments
 (0)