[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEA6p_DwfgkLheTK1QvSyZPbotvmadn7cubtqf1UFAHWfdDY=Q@mail.gmail.com>
Date: Fri, 22 Jul 2022 11:58:49 -0700
From: Wei Wang <weiwan@...gle.com>
To: Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
David Ahern <dsahern@...nel.org>,
Kuniyuki Iwashima <kuni1840@...il.com>, netdev@...r.kernel.org
Subject: Re: [PATCH v1 net 6/7] tcp: Fix data-races around sysctl_tcp_reflect_tos.
On Fri, Jul 22, 2022 at 11:24 AM Kuniyuki Iwashima <kuniyu@...zon.com> wrote:
>
> While reading sysctl_tcp_reflect_tos, it can be changed concurrently.
> Thus, we need to add READ_ONCE() to its readers.
>
> Fixes: ac8f1710c12b ("tcp: reflect tos value received in SYN to the socket")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
> ---
Acked-by: Wei Wang <weiwan@...gle.com>
> CC: Wei Wang <weiwan@...gle.com>
> ---
> net/ipv4/tcp_ipv4.c | 4 ++--
> net/ipv6/tcp_ipv6.c | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index d16e6e40f47b..586c102ce152 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1006,7 +1006,7 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
> if (skb) {
> __tcp_v4_send_check(skb, ireq->ir_loc_addr, ireq->ir_rmt_addr);
>
> - tos = sock_net(sk)->ipv4.sysctl_tcp_reflect_tos ?
> + tos = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
> (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
> (inet_sk(sk)->tos & INET_ECN_MASK) :
> inet_sk(sk)->tos;
> @@ -1526,7 +1526,7 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
> /* Set ToS of the new socket based upon the value of incoming SYN.
> * ECT bits are set later in tcp_init_transfer().
> */
> - if (sock_net(sk)->ipv4.sysctl_tcp_reflect_tos)
> + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
> newinet->tos = tcp_rsk(req)->syn_tos & ~INET_ECN_MASK;
>
> if (!dst) {
> diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> index 9d3ede293258..be09941fe6d9 100644
> --- a/net/ipv6/tcp_ipv6.c
> +++ b/net/ipv6/tcp_ipv6.c
> @@ -546,7 +546,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
> if (np->repflow && ireq->pktopts)
> fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
>
> - tclass = sock_net(sk)->ipv4.sysctl_tcp_reflect_tos ?
> + tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
> (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
> (np->tclass & INET_ECN_MASK) :
> np->tclass;
> @@ -1314,7 +1314,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
> /* Set ToS of the new socket based upon the value of incoming SYN.
> * ECT bits are set later in tcp_init_transfer().
> */
> - if (sock_net(sk)->ipv4.sysctl_tcp_reflect_tos)
> + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
> newnp->tclass = tcp_rsk(req)->syn_tos & ~INET_ECN_MASK;
>
> /* Clone native IPv6 options from listening socket (if any)
> --
> 2.30.2
>
Powered by blists - more mailing lists