Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3986678rwb; Sun, 9 Oct 2022 15:20:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43kV3ocl6GwRzjj2CzwuEhEv1jB1OUq8wM/RaGcUzkwhFvoZkrBuUH1qK05QuU6is0BJtl X-Received: by 2002:a17:906:794c:b0:783:ce42:4d2 with SMTP id l12-20020a170906794c00b00783ce4204d2mr12365642ejo.517.1665354054458; Sun, 09 Oct 2022 15:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665354054; cv=none; d=google.com; s=arc-20160816; b=aUW5fS5UfmSIbYuv84K1a3AApI36kI04M5pe5w8GaFzUFI+h2utoA2cvtKIUFnip3X pJ6zKzHTdi63XBsLn2LdgMHhdUUtpdNmXSlQPauHUKKbGzRDi6jDh2Em55Hxv7hgs5/E itV4e5H8A2cG67iDRiu2fwBejcwbwdQIwQKZm6Y1Pa8Zmzlko8WjteHS66VzJc8g2jYf AuRTziufjlOgRunSipV4RgwnFTvsqgXVtN6m0g2uxfS7TE1QfR4QqtAXgiTudBtrR4np PZYALhJ7fmj+a/n66pV4ZObGcCK/1CJetskDi4aXIj8+lKu7+LGCKIjPNctf49Vv+WnG mzFg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g5RAqSh0hHbFCP1b4XhGgUMRNXm2PmquKIVwyMbwfUE=; b=rM7X6VOuMBTH3vIJT8Hqk+q5MoQPrU9Jye10loq/g57QnzCQS8fqOHorc5bGnxf6vP hvQ5xv171tx4rDNUi4e6p2op1bSuCWrxX9RQfysM3bi72NsL5TegsyVBPrSVUTXeXCb5 Q+KacX9W5aE3HCGv8GjnHZ7i8Q++MCFYUcEYbhU2XRAnt5Afy34eDsV9ObYTXv7EqElW V2H4qtr5i1QJ1uAste8rjFsmP9unQE6h20e0ePCBjeisCl8XDevtZsQZaTgMlVmRAe9r tUIKV6QRIJ3JkOOf3pCjX6x96RkAkQPXgB+n3QN0U29a9/swyMmnETys9jAu+0OdRvJd 1nYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mK+pcnmW; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a17090640cc00b007825337afeesi7758549ejk.273.2022.10.09.15.20.29; Sun, 09 Oct 2022 15:20:54 -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=@kernel.org header.s=k20201202 header.b=mK+pcnmW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbiJIWJp (ORCPT + 99 others); Sun, 9 Oct 2022 18:09:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbiJIWI5 (ORCPT ); Sun, 9 Oct 2022 18:08:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE102C643; Sun, 9 Oct 2022 15:08:43 -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 75053B80DD0; Sun, 9 Oct 2022 22:08:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 258C4C43145; Sun, 9 Oct 2022 22:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353310; bh=xMxSlghfk4u+HEWCqT2HDtLZahf6WcYBU4+V5Q9BAuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mK+pcnmWFJMi2EvAmVtXQTrqbKmuYz1YrrxnnmiTtBcqBJLM5cX4hBIruahdy7xG2 5uVXdo7y8FVHN0ju52/TlFJNFGCSw41+ynzhBIZugWOPdN0sMFxqLNAs+G6GBmefsB ZW4sCtuJt4JEMnMAgiS0VWSmnC5eIR2eJqstscxP0iNhnKbSBMdS+kj9xVIR2w7kVq mKtUK3nuQRnxPcxruFJr0zbl9k9maMVXray+sa8gT8AWKm7M9WXi5douhNbIUWp5go N0BJKJnTHrDLHxhRdah6ott5sxPpHlx52mPbsIhTgqDkkuuWn/DNdtNvygkcTdhRsO MJtIXPm/Ufeyg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , Abhishek Shah , "David S . Miller" , Sasha Levin , yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 13/77] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Sun, 9 Oct 2022 18:06:50 -0400 Message-Id: <20221009220754.1214186-13-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009220754.1214186-1-sashal@kernel.org> References: <20221009220754.1214186-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Eric Dumazet [ Upstream commit aacd467c0a576e5e44d2de4205855dc0fe43f6fb ] tcp_md5sig_pool_populated can be read while another thread changes its value. The race has no consequence because allocations are protected with tcp_md5sig_mutex. This patch adds READ_ONCE() and WRITE_ONCE() to document the race and silence KCSAN. Reported-by: Abhishek Shah Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e373dde1f46f..3733742cebf8 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4442,12 +4442,16 @@ static void __tcp_alloc_md5sig_pool(void) * to memory. See smp_rmb() in tcp_get_md5sig_pool() */ smp_wmb(); - tcp_md5sig_pool_populated = true; + /* Paired with READ_ONCE() from tcp_alloc_md5sig_pool() + * and tcp_get_md5sig_pool(). + */ + WRITE_ONCE(tcp_md5sig_pool_populated, true); } bool tcp_alloc_md5sig_pool(void) { - if (unlikely(!tcp_md5sig_pool_populated)) { + /* Paired with WRITE_ONCE() from __tcp_alloc_md5sig_pool() */ + if (unlikely(!READ_ONCE(tcp_md5sig_pool_populated))) { mutex_lock(&tcp_md5sig_mutex); if (!tcp_md5sig_pool_populated) { @@ -4458,7 +4462,8 @@ bool tcp_alloc_md5sig_pool(void) mutex_unlock(&tcp_md5sig_mutex); } - return tcp_md5sig_pool_populated; + /* Paired with WRITE_ONCE() from __tcp_alloc_md5sig_pool() */ + return READ_ONCE(tcp_md5sig_pool_populated); } EXPORT_SYMBOL(tcp_alloc_md5sig_pool); @@ -4474,7 +4479,8 @@ struct tcp_md5sig_pool *tcp_get_md5sig_pool(void) { local_bh_disable(); - if (tcp_md5sig_pool_populated) { + /* Paired with WRITE_ONCE() from __tcp_alloc_md5sig_pool() */ + if (READ_ONCE(tcp_md5sig_pool_populated)) { /* coupled with smp_wmb() in __tcp_alloc_md5sig_pool() */ smp_rmb(); return this_cpu_ptr(&tcp_md5sig_pool); -- 2.35.1