Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7387966rwi; Mon, 24 Oct 2022 14:00:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4iLb6H1hB+Vbv8PBcaTAWEspwcuWHW4gQfyeV0jtbs1RCDC1FlJW0W7zAtH+njJXph3oU5 X-Received: by 2002:a17:907:2e0d:b0:78e:1d21:8001 with SMTP id ig13-20020a1709072e0d00b0078e1d218001mr28715435ejc.246.1666645225118; Mon, 24 Oct 2022 14:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666645225; cv=none; d=google.com; s=arc-20160816; b=YnTNDgPsaHiReEhy4ID5Tp/mN5QISeF9FH3/VVtS4TmWlgvCuyugdsszb5AaJ+/deF 1m1zay1dX5JzTMYX/WYT89pwUyt1fCxS90C3hGZp4wwKmZnHAZkh3ch1QjwbpbAa5W0e vZ1Q2ELeQUpETFgj5yvzjEChe/1XyImrQhatT5GbTOnamlHQzDc0qJ3Jl+khsaDdz8mc 1Gxc+8UI/eVCR7p6jG+9iDwBZcU6KgLL31NXJ6FXltELIAVC/gaRpaIDutj5tiy22SIN k0VGEnMxm4tiz8xh2fyfSrwUpR8La+ZSmad1iHhxpZktH1Sd751rScVvLJ7A0wVzev4C LMfg== 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=GTCCdl+IiIwoaZDgbHExUMbCgxDkii9JTjoDNblr2CU=; b=x+YJXioxEa0gD7kpOZHShL6Zqj5jnOwRQeXTi/x0VlvuO8okeR19Ea9p2t28ma0sXv Epy9mCWO2W+Bxyv1MNsodL0EL1uwy5jfEhoQ40Op5L45HCrDFLoSKqYBhS4W8W4jaI04 5SZ4zrFsSDviDT6RP2zipT1SFLV337eMiqcl66x3GiqE/OFTuU6mWdSgORYeCC+roTxF x4p4t+FeC10JyUlRRE8wlF6r/Z9tyAS7VsybHLcdG7MuewFI2PArZMTuqarWQ3110EJ/ zV1fR1ZYkfTieTcaHHT3WQwJQ8GT4TRerc19AGzwA/PphMHF8kZz0OGxJ4BnOH48qtC3 g0Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ucnbaAmf; 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 s19-20020a056402015300b00459060fce1bsi652532edu.574.2022.10.24.13.59.59; Mon, 24 Oct 2022 14:00:25 -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=ucnbaAmf; 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 S233524AbiJXUb2 (ORCPT + 99 others); Mon, 24 Oct 2022 16:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbiJXUa6 (ORCPT ); Mon, 24 Oct 2022 16:30:58 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47281115428; Mon, 24 Oct 2022 11:42:36 -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 sin.source.kernel.org (Postfix) with ESMTPS id 819BDCE16E4; Mon, 24 Oct 2022 12:51:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92CC6C433D6; Mon, 24 Oct 2022 12:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615888; bh=mZqX+tluggld9fSL1i9YkMGAMPOcimbKnVay6bhf3mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ucnbaAmfdd3QKIoesUigwToxvUb+rKTB1hlWN44CChdVfJ+RmIAsAbDyy8D5IJGAg KR8gUNmboMMPbmKjBKpqZIRuhn/UdkOfpUWJzjDnB2qpslLjTyIwAPmvUVKNfBaJAc NKJ4MaOyMi1x8vikX+ErfxCAyLRXg3DWMzC9XCcA= 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.15 421/530] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Mon, 24 Oct 2022 13:32:45 +0200 Message-Id: <20221024113104.149722363@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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.6 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 b604c7664350..5b4e170b6a34 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4331,12 +4331,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) { @@ -4347,7 +4351,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); @@ -4363,7 +4368,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