Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp486364imn; Wed, 27 Jul 2022 11:32:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v8aEM5nv9vUbJjkLrEDKhd1VRH8YERneA6LQak5Q7L2NSbpuFjsox27xcggpBzxd1I8hJw X-Received: by 2002:a17:90a:1048:b0:1f3:e9b:2ab4 with SMTP id y8-20020a17090a104800b001f30e9b2ab4mr3872175pjd.106.1658946757531; Wed, 27 Jul 2022 11:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946757; cv=none; d=google.com; s=arc-20160816; b=NjNoNDHd2nhGA84NmYMA1FDvHtdKdW/ZWIQjxpQimDXLK7A75cwSSliyYonuAn8dm8 JcupvxhZv+Cn0a++FHnj6J0uEe6fzC0g1LPTsmtKFtUw4vVTGlu6azpKrm6xwqErqvF8 hzvZY67zslDNIE/XJk42p6wbJGK0xfq1BxgwZO8wXAwTz8QXasiFVumBng9uTgSf9jOp kiwmeSh/+NbZogb8GSXqGTY8LN8XwWOZFce5GPduB28O1t//sLsbGabZN+Ikyoy61UW6 MugUPGVh+GAUQSG/z0Wpr06TSybg3Ug1gujxF/CUsObEDd0dmQaXG+xmLAMzATOYQ9W6 w8Uw== 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=VtIhKloG+ZJTruUa/ue+/QouBPU7dGF6jtEyF5fUUTY=; b=QgVWPWRlyiMzzYk1msdMI7Qn71DD+n2JW4rgDnTv88n4my6q8oGpsYQ7mh7I3aXcNJ h57AO6DRZorFEZRd9KenHkuwetlwog7iOliTiz444jc3K+r9HZYr9rZGkpJ7zK2V+02r qGCZZqmLJ7k7GN9aDCoR5jWN0+PiUjwXKcEab0Xc6CVfH79ueUF8/ieOoJbN6GFNa7ay gC2bdQd6gGO6WoDQszxjBNsSUtVmoO45jO+3lXd/PVX+s03/ObTalTtzCeE8pEy1KnDt tRE5tRom0wlkKBNHPI0d5m72smtoKE7vMdIcKgoC/vdRFgmNS4cxHQ6jGTl3o/2BX2Jr Dupw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="G7SdClG/"; 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 me2-20020a17090b17c200b001ef7fc77664si3057382pjb.158.2022.07.27.11.32.20; Wed, 27 Jul 2022 11:32:37 -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="G7SdClG/"; 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 S234325AbiG0RLW (ORCPT + 99 others); Wed, 27 Jul 2022 13:11:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbiG0RJ4 (ORCPT ); Wed, 27 Jul 2022 13:09:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A682747A5; Wed, 27 Jul 2022 09:41:15 -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 842AFB8200C; Wed, 27 Jul 2022 16:41:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3913C43148; Wed, 27 Jul 2022 16:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940071; bh=1pglrrwycW2z8U297nLs5MoMbieH2foR75zOwcWSSas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G7SdClG//wN0irUM0ACqgy4dJz4AMBmgsAX2imKSXf2mtGD3Jw6kJi1fCTeRdghdZ jSZxF/b5/ojdKYL/rphueuptPXyGoHOOKKaOjv40lfZD8MEqlcTesYROeVCdxpFoAC hhbyyGORNADG1bwYXAxHafb8qOjzNRKRND2MfQ0k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 094/201] tcp: Fix data-races around sysctl_tcp_reordering. Date: Wed, 27 Jul 2022 18:09:58 +0200 Message-Id: <20220727161031.653048318@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@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 46778cd16e6a5ad1b2e3a91f6c057c907379418e ] While reading sysctl_tcp_reordering, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_input.c | 10 +++++++--- net/ipv4/tcp_metrics.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e22a61b2ba82..480fac19a074 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -447,7 +447,7 @@ void tcp_init_sock(struct sock *sk) tp->snd_cwnd_clamp = ~0; tp->mss_cache = TCP_MSS_DEFAULT; - tp->reordering = sock_net(sk)->ipv4.sysctl_tcp_reordering; + tp->reordering = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering); tcp_assign_congestion_control(sk); tp->tsoffset = 0; diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 134e36f46e91..06802295e170 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -2131,6 +2131,7 @@ void tcp_enter_loss(struct sock *sk) struct tcp_sock *tp = tcp_sk(sk); struct net *net = sock_net(sk); bool new_recovery = icsk->icsk_ca_state < TCP_CA_Recovery; + u8 reordering; tcp_timeout_mark_lost(sk); @@ -2151,10 +2152,12 @@ void tcp_enter_loss(struct sock *sk) /* Timeout in disordered state after receiving substantial DUPACKs * suggests that the degree of reordering is over-estimated. */ + reordering = READ_ONCE(net->ipv4.sysctl_tcp_reordering); if (icsk->icsk_ca_state <= TCP_CA_Disorder && - tp->sacked_out >= net->ipv4.sysctl_tcp_reordering) + tp->sacked_out >= reordering) tp->reordering = min_t(unsigned int, tp->reordering, - net->ipv4.sysctl_tcp_reordering); + reordering); + tcp_set_ca_state(sk, TCP_CA_Loss); tp->high_seq = tp->snd_nxt; tcp_ecn_queue_cwr(tp); @@ -3457,7 +3460,8 @@ static inline bool tcp_may_raise_cwnd(const struct sock *sk, const int flag) * new SACK or ECE mark may first advance cwnd here and later reduce * cwnd in tcp_fastretrans_alert() based on more states. */ - if (tcp_sk(sk)->reordering > sock_net(sk)->ipv4.sysctl_tcp_reordering) + if (tcp_sk(sk)->reordering > + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering)) return flag & FLAG_FORWARD_PROGRESS; return flag & FLAG_DATA_ACKED; diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 7029b0e98edb..a501150deaa3 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -428,7 +428,8 @@ void tcp_update_metrics(struct sock *sk) if (!tcp_metric_locked(tm, TCP_METRIC_REORDERING)) { val = tcp_metric_get(tm, TCP_METRIC_REORDERING); if (val < tp->reordering && - tp->reordering != net->ipv4.sysctl_tcp_reordering) + tp->reordering != + READ_ONCE(net->ipv4.sysctl_tcp_reordering)) tcp_metric_set(tm, TCP_METRIC_REORDERING, tp->reordering); } -- 2.35.1