From patchwork Sat Oct 22 07:27:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1106790wrr; Sat, 22 Oct 2022 01:39:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qQyhrX2wgFOwk6tJLA+eCTVSqJRX5oZ9091ERnvuaJgT0hT8Vjy8zxIvm2KXwFM3RJ0Jh X-Received: by 2002:a17:907:a042:b0:7a0:3323:2883 with SMTP id gz2-20020a170907a04200b007a033232883mr2670669ejc.37.1666427942911; Sat, 22 Oct 2022 01:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427942; cv=none; d=google.com; s=arc-20160816; b=fneJiq1ijUCTaKfhU/pBbE6pMjTOpM1F7gTqoZiaPf2AfNOJLHJQzbVpVsXg7EJ1TK xXHUWNtzynm1N7kgxMpqRdQ+j0RiBs4uXTipOm/xf5BJmlNabfJulugPfN97ZxEnwSAi ehbBOW8/EfT2sfjnd3u9xUTexXK1LdfCAkM1miW/J85XzkHKUz3K49GklPLNjEow1XXL yqxI80bvEuD5nO4W2CLyHi9nH2vEPsVkRfdH7y4fwooHe7kOcMKfhuz4xQ6H2W9VVqh7 BHJwQEouqEvln+nAZgBiDCgJlYL/D7c4rfozCKSxWR0nZsgi9KdKgEImB35yAU1ZUKPq 5DqQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a056402440100b004585ac2edd4si27463770eda.348.2022.10.22.01.38.34; Sat, 22 Oct 2022 01:39:02 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376346491324605?= X-GMAIL-MSGID: =?utf-8?q?1747376346491324605?= 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);