Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1942538imn; Mon, 1 Aug 2022 05:53:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vqBuMvpc88mH1A7TSAfDqDpzMJc9Lj3sXd656Pxm/TtrsS2/y3yNLTEoGvXYft5YQx7Ne9 X-Received: by 2002:a63:190b:0:b0:41b:6d0b:e55d with SMTP id z11-20020a63190b000000b0041b6d0be55dmr12969818pgl.601.1659358392406; Mon, 01 Aug 2022 05:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659358392; cv=none; d=google.com; s=arc-20160816; b=Qx4C7MAN1T9AI20Bbu8c98WV5Wt2YX0kU3yfaOYgDXiAmjkF7e2v3LWKUIHH+Ha4rz TgE+uvH1pR1aggalTvfvXQeZ/O6NsRafJBcGnxgVSCGKWkfstYA6w0Xi4TUWL7AV+n3x LC2j72Lyd9ZJ4dDNKWTP58cbs1xNpXd+9FLRvAGACsM4lBk5hi58wd+O7JQe4zrTEkg+ D2nvfSYVTl1R/sFIaeA6wmrwi6jtbDc81XzHFJrHJ0D75DyrQwLa6Y2pwNzzI5qA5n0d SqLVpANlc88mATl9eQEkeybnsexlQZrFDeOEiBQFN8SurpDq0Wyyl459Dhck28xRKTqL ZKWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BKnAvrR/q7LI+HdLVLA406HNxNfhGX+mkWZHf70v8Jk=; b=JwgNXWNa2hbNwT/f8vk4sAsIYRUL0JqRSAB/eYIYctIIxq+x6ZzeeN8sDvrh47be+V ACq7x/RUTXpWOkTn/97t6VBFUIZ8CY31JnBV+mJEubGutDnMGpgm0s6PAThDIWO4VBgd i/vn1hxKEsrz/2+lHWf/KSatX5n3xEV1w6lqiB8KXAwXXn7HLEkEMHFH4LZHggLEfMh0 vXITqFjen6pwnsXXD+vz3fns3FU9rG9ZucV0uE78801+gWmlGUX9Y4IyHzo3tE9XNxGy Wi2dsvXjH2E2LFO1YJmmrSxHEpIOEKqE8xpDIVVJVvVFNxnfiYa1qNaviGsCNgcFpYOA W7QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SLsQGX2F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x10-20020a170902ec8a00b0016ee3e3bcfasi980284plg.23.2022.08.01.05.52.57; Mon, 01 Aug 2022 05:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SLsQGX2F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232918AbiHAMAN (ORCPT + 99 others); Mon, 1 Aug 2022 08:00:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232891AbiHAL66 (ORCPT ); Mon, 1 Aug 2022 07:58:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41BE94A80D; Mon, 1 Aug 2022 04:52:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9C6BDB81173; Mon, 1 Aug 2022 11:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F02C5C43140; Mon, 1 Aug 2022 11:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354746; bh=/aiidocJnBedxF7hINvURb2iXWFTCt5ZfPgv11oB8As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLsQGX2FdKb6UPoJhK4PIuZSc3vR6zaH6oTSMbcvJhuEMY+/QVScaQwvXKXU845hA glaPHgG/p2NLCEvF9T2NE0Sf6n+Nasoxd3prg8DyGWEXntH38AY9w6QdR0wShgQFCp RYsEmoBN329N0IjR2cYUxF4udEzCzEWsrlTBmefY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Wei Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 39/65] tcp: Fix data-races around sysctl_tcp_reflect_tos. Date: Mon, 1 Aug 2022 13:46:56 +0200 Message-Id: <20220801114135.345687804@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114133.641770326@linuxfoundation.org> References: <20220801114133.641770326@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima [ Upstream commit 870e3a634b6a6cb1543b359007aca73fe6a03ac5 ] 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 Acked-by: Wei Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 d5f13ff7d900..0d165ce2d80a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -983,7 +983,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; @@ -1558,7 +1558,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 303b54414a6c..8d91f36cb11b 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -542,7 +542,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; @@ -1344,7 +1344,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.35.1