Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4050097rwb; Sun, 9 Oct 2022 16:51:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM58OjSHw2Gjm1n33/0C9eQ603WVl2lVAWY4Kf+p5AhxUafREtgl2FkiNzm19HzjbdybXNlS X-Received: by 2002:a17:907:3e87:b0:78d:bb06:9066 with SMTP id hs7-20020a1709073e8700b0078dbb069066mr715700ejc.387.1665359471020; Sun, 09 Oct 2022 16:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665359471; cv=none; d=google.com; s=arc-20160816; b=K/IOCUVwqk2zbgD67tsZUQblicyDse/63Fp+d1l9jSQcqHaZSLynO5iWpEbOxl1rpt RiBPjbeqFbZ0ZYv0INwmODMEUHsT0iuubLpdVeLUIWtrxy4m6GOaUTzX6qGpi9rmuPxy FJWvaOVVr3A/eR8bNWafqGkxaqm4E2SvlarRsKWQusiuP1KolJmjXJTHUMPNx4fctuqs 9G08U1y6BxK3WPzBg/M9ktGWaYSmal0/hJA/Z96AJCFWXKtXU3U/+avXj3L1FPY0ULBd rCeNB8GlqvpdXFPdOUKwBDJePrBv3NR+EaD+nWtff7JadcKQpn8KfemEwizjwXLON/MD jC9Q== 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=2/Kq1LjQyiMbyOtjj4Zk6FWevd6LKY+Y8O4VA7zJBOs=; b=y6+ElrPi+5qLIufe07+H9E5enCH2Tp8k9wXTkEZlizlE5AAILJOPtETuOjmPfEs3XD PsDzqFPsNmImup+5RnQsvSaGxBiSGKslfg5Ul8p73uXnfhqF84w8fD45UFbWEfRV1wtO G/1U9YwmN0BYV8RGUP8WFGdB736vVGZHhMuG9Pf8JY4NYI1GVJgnvwXq15kQkMA4u9ot gikZK7j5KPkJ9x3kIqTpf5c0UPcBXDOdtgVtmUkhs4fQheTKlP2INH/THSXIBWEKWD7o 1GoxRjqdR4yNe/svS90YOlXuRy6jHC8hkLXnj6JYkUZ5LM4V8Dmd0GOVEttQL1WMUiGL eAHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SjG+uAbb; 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 s16-20020a170906285000b00787d0dfe70csi8030963ejc.981.2022.10.09.16.50.45; Sun, 09 Oct 2022 16:51:11 -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=SjG+uAbb; 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 S231927AbiJIW1l (ORCPT + 99 others); Sun, 9 Oct 2022 18:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231901AbiJIWZx (ORCPT ); Sun, 9 Oct 2022 18:25:53 -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 E2A7A3DBD8; Sun, 9 Oct 2022 15:18:18 -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 404B7B80DEE; Sun, 9 Oct 2022 22:15:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB656C433D6; Sun, 9 Oct 2022 22:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353746; bh=sbE5YGdrypbIwwpqsXVVFkuKfbOiCASFIUzuzOIw/5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SjG+uAbbz1ajcfSfA0G85mACDNyQww2gfnbNLVhJnrxIK4kH+SfPo+ki3UO6zYWjz wZxZPReJmhNn6QOdJ+9L4td0bL8eQyml8A0yvME8bBE7UiYjpZKSJnclBrvbLzHX7m Y0Bn9hYBNlMKR22DiUKZW5bgWLeiX63GJ0Yb0cXOvHgw7J/1JHMwqFo62rIsKt+Tm9 UD2rCPuBeeL+K1etLOqfaoihfN/hQkw6hybkvZb4jZVQo5D1s1fiXGXSNQnvMFxI9y bty5piGy9XgP3kBuYgCYEuSUAIBQxWIky6MTwnz+HSVaphWV0yqFhppeX+jV0Jv1JT dt+/0j3SSuZ8A== 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 5.19 12/73] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Sun, 9 Oct 2022 18:13:50 -0400 Message-Id: <20221009221453.1216158-12-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009221453.1216158-1-sashal@kernel.org> References: <20221009221453.1216158-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 ab03977b6578..6426d5e01cb6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4347,12 +4347,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) { @@ -4363,7 +4367,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); @@ -4379,7 +4384,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