Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6869056rwi; Mon, 24 Oct 2022 07:06:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4p3nPMQTXtlwGqmiPldAANpIGv1N+rJqHKtkISqkugCAMw1vu0M/w9NJxA4gBcqtzHoOHs X-Received: by 2002:a17:907:2cf1:b0:78d:c7a1:172d with SMTP id hz17-20020a1709072cf100b0078dc7a1172dmr27215394ejc.51.1666620397136; Mon, 24 Oct 2022 07:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666620397; cv=none; d=google.com; s=arc-20160816; b=o+fHugP39VXUXS8tiZC2VS5xLWn1zOi9BhCK/bAHfQp7fUpQBzCAf8lf84sn3ZysbN ImUmJyhs6YdtSQMH/OInKu4POZ8kZeJfN1Jlf13uB2vBEkmot5USjwhVvjqmgbG2MFqp wkRUlqy+PsNIb9OfxeeTXt8ASOY0/927n362DgJllQ+GmTPY998bv6/BigBBURBi2V9+ eGH7kfLOMIUJ+47KhZSCEjmYonT1YCr15B9Zu9e92FsOGP9Y9B9Jf57hbasD2wr7c3wZ sqxbQM+VH2rs338dzDYbrXq4VrigFRw8aX/yUE2eBWPmeLXf+aXX/Iv+4NeF134F61ho y1Lg== 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=uvEApS0wshbys1Rs6bUCZZy7+ucJ+fcPABWMcKcZKW0=; b=F5PiKhktE57GNMStk34ylCGpWyxzKt/k816bn0OeI2bStCLOWkeilDtjbilhauOPDP pO7z5V59C9XzXXEcidV9aSrFmW5sveXNkl+dqxweWy3UaCwsQCfYT7Tq1orQUKMDquU8 Uq9kswyuEyBj0dbWONS9b7QaP/3/m5hIzDe6Isxh91gvf7G/jf5zrydbsXQbrtKTdE6i FjKhguXrA4BLtrKJsXCBUIrYwraSinAkCreursbi3QepYHCl99vpq/KABU0TUzZ0upjp NZ6AtJgdZ/11O/uKLcZmw8qtrFKBLWuPWNSS1OP9AN9oVeqopVGJw6fmQb967/W6oSm6 XfKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=evQIM6SS; 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 sh37-20020a1709076ea500b0078d9d69ae0dsi29342104ejc.877.2022.10.24.07.06.11; Mon, 24 Oct 2022 07:06:37 -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=evQIM6SS; 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 S234137AbiJXMeJ (ORCPT + 99 others); Mon, 24 Oct 2022 08:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234173AbiJXM3c (ORCPT ); Mon, 24 Oct 2022 08:29:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D001987FBD; Mon, 24 Oct 2022 05:03:09 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 29C10612D7; Mon, 24 Oct 2022 11:54:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B570C433C1; Mon, 24 Oct 2022 11:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612441; bh=1uEidU8QdesxzO/5otIAs5DQ7Dws8bVQHAz3M3ORzmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=evQIM6SSs1whdlifhKMhQsS+SI4ObXY3BiVGy212LJjS+m3YA0aV2ULMISxy9zcx+ QwHclamxWF/YuqhlECZM9b6jFjsIpqYEn7jRjYz7P8IAH+bu3VJLcjnZ5T5mdpwHgJ r7ak5SYKc13j1dI6yIf4ipJryx/zsg3/wgp2qn7I= 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 4.14 170/210] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Mon, 24 Oct 2022 13:31:27 +0200 Message-Id: <20221024113002.473610446@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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 783d0cd4fcbd..3a5f5bcedb3b 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3318,12 +3318,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) @@ -3331,7 +3335,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); @@ -3347,7 +3352,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