Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp811178rwi; Wed, 19 Oct 2022 03:19:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5w8mGZ7vofjPthQheFcgdGshc6LRktNVufjYGuFpHLQKbPU6YBVppRzu66mWwHRk7//NdP X-Received: by 2002:a17:906:8479:b0:78d:cf17:2d70 with SMTP id hx25-20020a170906847900b0078dcf172d70mr5980626ejc.319.1666174759292; Wed, 19 Oct 2022 03:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666174759; cv=none; d=google.com; s=arc-20160816; b=DBbLBDVv+PB3KBr04eMQObOv1NqHHVcbViicYjWIw7C8LpvXzSP44EqShCm0eCAuIZ fWOamCWVDA8Oufw8Cg8rE5Xbl60MZDsPOtN/xUSLaTlEwG/lFz4zwc42a3pEoMZ4bcHf Tjnp8CS/ICQJEP63ZwuUsSnsnuxqQRhCZ7Sz/uC8TbcbmFG2AKzuvCkoLFHgO368aMG9 Qu/sHRk/UokJPXs9kBFYHAPHwDgge5ZBeuFbONeijgdSMBfMxbfh3pSWxHRH8WVF/H3L cv6l7sdDXCU9dxvVcMqaCuVqp8LoSewPkIUpbYjQajE49ZsHVnjbWjLPmcn4VW/ypOGx NcRQ== 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=6sGY368LlqREylzMH0NWWXArdZTalId9jynhcl5ezZo=; b=uiX/R8qFDjPyt6B5HAwaH/eCQOdKUd8catpSuNorwqA57p+vhcaExPC3Te9xYap//t yY2W9GVXyD+f2EzXkZVsGlQG/o1av9vM2MtnoL2zSGRfn2t4+feJf622gfInFn3odhSu HZg+BHCHOM+UCNSwZurYSWvb/vUiiLKtD3rYv9zQyEyuyQfkilm7MFSRyiobBm5uFV/v NBiO+/YVUX2g5z8Hk2FVhfg4pGFNp8Gs3nPYuow0I4c9Kb3f+8C5R1EMN3hfIgzlkH+r t5UuBUOvVm2nwv3NOCbWZARXbBxMKeHdFcP/cV7xEXkQ1c2Way7JQsgzNofLCSXXSIsL 0NTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xn1BQo7W; 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 wu13-20020a170906eecd00b0078daf101aa1si13326084ejb.813.2022.10.19.03.18.53; Wed, 19 Oct 2022 03:19:19 -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=xn1BQo7W; 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 S233252AbiJSJZL (ORCPT + 99 others); Wed, 19 Oct 2022 05:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233469AbiJSJXw (ORCPT ); Wed, 19 Oct 2022 05:23:52 -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 136698307D; Wed, 19 Oct 2022 02:10:40 -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 212376174B; Wed, 19 Oct 2022 09:08:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33653C433D7; Wed, 19 Oct 2022 09:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170520; bh=YJW838ei9dUw8KV2RE3LIsOoRby+bBUkYxhtb2Aj2+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xn1BQo7WV7bsioPuIUux4hiCjojjGL/kv9NFKwZQBaQKcaH3N1g4iDI/Ocrc/DHGK ObFsHK+2+cO/wjFCdE9gTreNd2/ll3loRpqvaQP1Ii9wHidmdqMNvk0LJdEbg69BJg cbx3fzeZFhSEQX/Dff1I4YDCaNqe7EjOAtURPWp8= 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 6.0 687/862] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Wed, 19 Oct 2022 10:32:54 +0200 Message-Id: <20221019083320.336216418@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@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.4 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 997a80ce1e13..5f1d84d901c7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4444,12 +4444,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) { @@ -4460,7 +4464,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); @@ -4476,7 +4481,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