Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp477985imn; Wed, 27 Jul 2022 11:18:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ubE6fHfb3VMBLg/uiNE9d5dk2O3nzS79qY8hy3kV5UGeX2RTUQXFyPyr6P2OWq95QLnZDn X-Received: by 2002:aa7:d8d4:0:b0:43b:bc29:de65 with SMTP id k20-20020aa7d8d4000000b0043bbc29de65mr23357299eds.82.1658945923931; Wed, 27 Jul 2022 11:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658945923; cv=none; d=google.com; s=arc-20160816; b=lhjIuhsGxSxKsFQRRkebRFufCwjwE/IvjzPUBJRnlhRA/gOzjcBSOSb2IaSqUdS4ez +T0WTJf46ENZaRJz/xlcKlYOyRaAZVn0fd31HCbaqUYe2oxB0xrQC2G1kczuDtmwm5Ux SiVz2u3KCp4KOMzNkilKUVyu0FSZ28sCdtdwAZVb1QfgAhR8JU1+gNPh2iwSI5oKKbtV xvDDgCNCyXeiNvWrrnQfauNXlk+fwEGGmF2o9NH9JAJjia8DJUySVsSYgLAkpzGCaUfQ p1NzJek26Xh1JWyg1adUJd23c94Qe7d8NSSvpgxtWoD0/RtgtswFsHBFNhcS+WH780ce MNlg== 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=Y8XL30t+0kKnMGygKrmLtMnfOP2DJ2rDiTWA9McCO7U=; b=VRsp+BW/Mv694wDLIr4HkIv6TYWEbF+X2+fNLc6zp+P+h1cAswtLyzLnURQKlCJM9y h7hRESKY0IsEkIuKI2IK61VieQkb3gggt6pbhwK+B57s4TlU2+oN9gjQsR8LnJyQasx+ AFLvhfx18QS6/P+NLRoJUxL7ZSaJIBT/wmjI91577R9IOFsnugPof4kaJgYvY2LIX0h9 gBZGCgFn6UZ5i+9PJ0aMQSGmwbeAJkB77DQiEfxGK5u7ec3+V1twDbIvET4yXYPE4BIw YQjZtcgLN0GDWEMUGFXvVOGdR3piGLDS/2+ZE2tBZXbEaVBZQji4O/GNghfJYUdUne61 ZPcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z4JBFjGq; 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 qa19-20020a170907869300b006feb3a01b16si18793522ejc.683.2022.07.27.11.18.17; Wed, 27 Jul 2022 11:18:43 -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=z4JBFjGq; 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 S238751AbiG0Qgf (ORCPT + 99 others); Wed, 27 Jul 2022 12:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239108AbiG0Qew (ORCPT ); Wed, 27 Jul 2022 12:34:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 441352BB14; Wed, 27 Jul 2022 09:27:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2F08D61662; Wed, 27 Jul 2022 16:26:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCD50C433D7; Wed, 27 Jul 2022 16:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939218; bh=bHWOYzOT2Xrewl7+mdQEPqZaXcMv9WJSN1IRkhw5VDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z4JBFjGqQtnd+aol6GhBheIzomySszI73XCwcImk+yX3H5zYCeTDL9WNiO4uTZk7j EV8rqdukFahPpzMunE0cpF1OiwUvDgvw6cp0T7Fk4ZJRVOERY/p1LnGicTZEmP1ikn 7c+dkDD0hD7CY0pmC6QfwXXIf54VdsXqJezMs/CQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Yuchung Cheng , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 23/62] tcp: Fix data-races around sysctl_tcp_fastopen. Date: Wed, 27 Jul 2022 18:10:32 +0200 Message-Id: <20220727161005.109101571@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161004.175638564@linuxfoundation.org> References: <20220727161004.175638564@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 5a54213318c43f4009ae158347aa6016e3b9b55a ] While reading sysctl_tcp_fastopen, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 2100c8d2d9db ("net-tcp: Fast Open base") Signed-off-by: Kuniyuki Iwashima Acked-by: Yuchung Cheng Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/af_inet.c | 2 +- net/ipv4/tcp.c | 6 ++++-- net/ipv4/tcp_fastopen.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index dadd42a07c07..229519001cc3 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -218,7 +218,7 @@ int inet_listen(struct socket *sock, int backlog) * because the socket was in TCP_LISTEN state previously but * was shutdown() rather than close(). */ - tcp_fastopen = sock_net(sk)->ipv4.sysctl_tcp_fastopen; + tcp_fastopen = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen); if ((tcp_fastopen & TFO_SERVER_WO_SOCKOPT1) && (tcp_fastopen & TFO_SERVER_ENABLE) && !inet_csk(sk)->icsk_accept_queue.fastopenq.max_qlen) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 0f89d0f2c21f..7acc0d07f148 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1160,7 +1160,8 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, struct sockaddr *uaddr = msg->msg_name; int err, flags; - if (!(sock_net(sk)->ipv4.sysctl_tcp_fastopen & TFO_CLIENT_ENABLE) || + if (!(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & + TFO_CLIENT_ENABLE) || (uaddr && msg->msg_namelen >= sizeof(uaddr->sa_family) && uaddr->sa_family == AF_UNSPEC)) return -EOPNOTSUPP; @@ -3056,7 +3057,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level, case TCP_FASTOPEN_CONNECT: if (val > 1 || val < 0) { err = -EINVAL; - } else if (net->ipv4.sysctl_tcp_fastopen & TFO_CLIENT_ENABLE) { + } else if (READ_ONCE(net->ipv4.sysctl_tcp_fastopen) & + TFO_CLIENT_ENABLE) { if (sk->sk_state == TCP_CLOSE) tp->fastopen_connect = val; else diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 119d2c2f3b04..f726591de7c7 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -313,7 +313,7 @@ static bool tcp_fastopen_no_cookie(const struct sock *sk, const struct dst_entry *dst, int flag) { - return (sock_net(sk)->ipv4.sysctl_tcp_fastopen & flag) || + return (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & flag) || tcp_sk(sk)->fastopen_no_cookie || (dst && dst_metric(dst, RTAX_FASTOPEN_NO_COOKIE)); } @@ -328,7 +328,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, const struct dst_entry *dst) { bool syn_data = TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq + 1; - int tcp_fastopen = sock_net(sk)->ipv4.sysctl_tcp_fastopen; + int tcp_fastopen = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen); struct tcp_fastopen_cookie valid_foc = { .len = -1 }; struct sock *child; -- 2.35.1