Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3962979rwi; Sat, 22 Oct 2022 03:00:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7HaqqTF9ym751Hrg3isSp4asnA/1j5UNuDn9U9yDG5T4QpkJSVj4UhrKQ+3OHclyuH72+J X-Received: by 2002:a17:90b:3141:b0:20d:49d6:30b with SMTP id ip1-20020a17090b314100b0020d49d6030bmr60124196pjb.223.1666432831590; Sat, 22 Oct 2022 03:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666432831; cv=none; d=google.com; s=arc-20160816; b=oUoVCqKsFxTYAvClXRooB+vJJBXm6lssf/kfcNaEslu6SdMp6g7TY0BWl/schWytzE mQpYs/qwANuPN1TpE3ZfC52PnXCmK9gegzSluG2b0wNLaNAiyTvhmJLol49aYmTkbfmG R3Vp0N032HsjUziDRZbmBOBZsREizGQI4Kk8dWRdXFTp0puxWoa8cGwTOTrN4ceg7j6S 8Vb7uX5NnY7CPmfkMBg+0iiavSnN6osQTtLpHaYMAYEXnMYJwSRSMfqmmEG89wy6zIKt myFgyoJF5bHJDHtGfnLQ2PvmiDMIxBgUoPkASGwQqZ6z1gKOL+8RuLy3NDCxOcK0LcTz Yf5A== 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=Mb4XyV3j8u0MA0oDkGxPazSMPRiK9t5u9gOkSb7G8tA=; b=mqsSent6tzynftsCNqfJbIvbWQBpFIvW5MJ/IcKPdp7WQdU8eSa/NNMQOjNptDuats e7Wv8OEYAldqx6Ad87lnwUlzLWxUVEnRoz7KREljDWymWjRypKsRox1z2UeBDjyxdkd+ AhfmzXHRDe7rxx3fRbecGIf4UUK5q0HQ4JU4gRfi3QVVhkKEeYxdoUIolENiu5ygDm39 V9P+QURrF3jUr/WlT9TXSEvZ+IOEzLDvLwCNzwqWnvya5vQgiSMEthE/oAoiiseczK+O HQIMGDcgk5rViijcQqipne+Cza8dGb0l6LvdvZzxsGiINtT8peNAcqfJX4BGmRBZgchA GBzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BzXLvuEH; 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 w18-20020aa79552000000b0056b8bbfe687si1002911pfq.171.2022.10.22.03.00.17; Sat, 22 Oct 2022 03:00:31 -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=BzXLvuEH; 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 S234056AbiJVIgN (ORCPT + 99 others); Sat, 22 Oct 2022 04:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234433AbiJVIav (ORCPT ); Sat, 22 Oct 2022 04:30:51 -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 229EE2D0803; Sat, 22 Oct 2022 01:02:37 -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 ED899B82E07; Sat, 22 Oct 2022 08:02:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49EEDC433C1; Sat, 22 Oct 2022 08:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425719; bh=IebTnLpoWf7M4ciH6d0K8DIBt9yynGumrjjHuoyIgc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BzXLvuEHbtz5nzxm8pXHompPxauEWwE2axXmXGDvuGRI6nYZGTiyXz6pfmBsTBEuK ccwaT+adQTqFzL9IawkuewIFszV4qvb1+JBwc63Z2eSNnkSxdikjNYB2AtxN+mwcBD jgwaX4uP7ZDZA4FOko9IOwx0ivkqCl04WT6CWnLU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Abhishek Shah , Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 5.19 563/717] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Sat, 22 Oct 2022 09:27:22 +0200 Message-Id: <20221022072523.281628549@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 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 f82cd6eb7088..83fa8886f868 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4349,12 +4349,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) { @@ -4365,7 +4369,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); @@ -4381,7 +4386,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