From patchwork Tue Jul 12 00:15:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 12914404 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 609C0C43334 for ; Tue, 12 Jul 2022 00:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232207AbiGLAVs (ORCPT ); Mon, 11 Jul 2022 20:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbiGLAV1 (ORCPT ); Mon, 11 Jul 2022 20:21:27 -0400 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBE0E48CB0; Mon, 11 Jul 2022 17:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1657585230; x=1689121230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uYn04R1QKPzx8CqsEpbFD6fgLYV73ozT9ItEiZYtZN8=; b=HTOuKkdFGgGmfmYRrL4QbZKBelWPuJ1Yxi0FekIaDP7W2Ia3dsf4T2Xn HzqPgA/DOktfm2WPIsxPZ0+mOHGHzNnIBB6YArAepx9GTEO7H3fiB1MH4 VOWjOkBAfZd77DZkY/PNeKtQ7Twa4nCz0M9jYtDZ9WntZy40NUpEcOytl k=; X-IronPort-AV: E=Sophos;i="5.92,264,1650931200"; d="scan'208";a="220431765" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-7d0c7241.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP; 12 Jul 2022 00:20:28 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2c-7d0c7241.us-west-2.amazon.com (Postfix) with ESMTPS id 5A8BF43D40; Tue, 12 Jul 2022 00:20:26 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 12 Jul 2022 00:20:25 +0000 Received: from 88665a182662.ant.amazon.com.com (10.43.161.185) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.9; Tue, 12 Jul 2022 00:20:22 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Luis Chamberlain , Kees Cook , Iurii Zaikin CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , , Daniel Borkmann , Florian Westphal , =?utf-8?q?Mirja_K=C3=BChlewind?= , Brian Trammell Subject: [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_ecn_fallback. Date: Mon, 11 Jul 2022 17:15:31 -0700 Message-ID: <20220712001533.89927-14-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220712001533.89927-1-kuniyu@amazon.com> References: <20220712001533.89927-1-kuniyu@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.185] X-ClientProxiedBy: EX13D04UWB002.ant.amazon.com (10.43.161.133) To EX19D004ANA001.ant.amazon.com (10.37.240.138) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org While reading sysctl_tcp_ecn_fallback, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 492135557dc0 ("tcp: add rfc3168, section 6.1.1.1. fallback") Signed-off-by: Kuniyuki Iwashima --- CC: Daniel Borkmann CC: Florian Westphal CC: Mirja Kühlewind CC: Brian Trammell --- net/ipv4/sysctl_net_ipv4.c | 2 ++ net/ipv4/tcp_output.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 5e308c1715af..108fd86f2718 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -685,6 +685,8 @@ static struct ctl_table ipv4_net_table[] = { .maxlen = sizeof(u8), .mode = 0644, .proc_handler = proc_dou8vec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, }, { .procname = "ip_dynaddr", diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 3dc17551ce25..11aa0ab10bba 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -346,7 +346,7 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb) static void tcp_ecn_clear_syn(struct sock *sk, struct sk_buff *skb) { - if (sock_net(sk)->ipv4.sysctl_tcp_ecn_fallback) + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn_fallback)) /* tp->ecn_flags are cleared at a later point in time when * SYN ACK is ultimatively being received. */