From patchwork Mon Oct 24 11:31:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp458339wru; Mon, 24 Oct 2022 06:37:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7QGlbw3cnBJxftHvinhGzSjQDzClCFkksA5/Jslzg6utcbe2cj+1gcrJhUL8uGl/ABdnqb X-Received: by 2002:a17:907:7e87:b0:78e:1a4:130 with SMTP id qb7-20020a1709077e8700b0078e01a40130mr28257312ejc.101.1666618643572; Mon, 24 Oct 2022 06:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618643; cv=none; d=google.com; s=arc-20160816; b=rFT6/5IMGMdC0nS5yyNtzg3iaKFjqB9M/3Gh8yNuJ62SpssD/BA3jx2lvJzHky2t6p qdJaF0dokNYKzb2r+9Rz1xi/1HToA8uc4YgnAmU+ji7WM7yaA0aGLIk2JK6ILo3VSiLT p1aEWkERe5DcwPyaVU+hG9lkMEXuKaNSNuoJGug8gUFbMuj/+WXxDjZF3wgkfrsMvWuV GCvaDox395AVchjvyA+2WubErDSoOvSKtwuBtCrxA7zMPRVnY2ZNrhyLbGAhL9e5/7Fu 1JgZ1IWi20QzC27YhqAycTqLDCLZMr/L9m5O8isU3fWT8CUGNgQUIFjrlJrGjmMtz6H2 2wDQ== 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=yTHx9IWBwOVSNXxyy5nl/5Y11eXhiJPeCUw3lOyhiKs=; b=wSNGRSfw8OGxDzjydVcC+9C7FqII6xiRHrjVjs1dVbtdLCNsCClqGAVCcbXx9oOkAG 5mVxPKIzD0elkE/dhOaYQK8ZDTQ6teqGk/LZDs1FsOBDREzQAUYlLTbif5tgzSODqryR beeYxrEDG5jiXOZaBaRJDN3ao1gZun7LNxJjK+O1p3dMSjI1vi+rPezJlKQtwK9h8OaV WhAZwKtl8eFWU9JAwtZN8XKtCAKcE1flFMJckSH2phZoYatlXSL5UAD2fnI50Oy/PSFo zNKpU6EEP6LfTsiIob16pdc0n2A+s8EEhdVvwmKKzDq2f/vHDyJLoqpcFTGyL3wGyNl6 CjgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=unhsNdqC; 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 e26-20020a170906c01a00b007826cb6f57csi24365242ejz.407.2022.10.24.06.36.49; Mon, 24 Oct 2022 06:37:23 -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=unhsNdqC; 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 S232540AbiJXN1G (ORCPT + 99 others); Mon, 24 Oct 2022 09:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236126AbiJXNY3 (ORCPT ); Mon, 24 Oct 2022 09:24:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E6078E449; Mon, 24 Oct 2022 05:30: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 CE609612C4; Mon, 24 Oct 2022 12:29:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFFEBC433D6; Mon, 24 Oct 2022 12:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614565; bh=WHQd8DRSzLmK/d2fpQEoWkzVxb3qPP9gECYJoEJorIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=unhsNdqCb6sB26lql9XK5rTxXpm4G/qrgrJHzYDmquKYrkSfAGD4gc82pY66ro1Oz VYaxcKfJq5YQ6t82OhYq3iZgsT2iy3taxYwrl+v3dk/4joi8JgqvGT63CHK6R6qstA fOpcEX57wxUAX3IY+kPrE/IUOeqFKAdqcqkd2kFQ= 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.10 309/390] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Mon, 24 Oct 2022 13:31:46 +0200 Message-Id: <20221024113036.150412531@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576311208961783?= X-GMAIL-MSGID: =?utf-8?q?1747576311208961783?= 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 24328ad00278..b0aa7cc69d51 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4043,12 +4043,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) { @@ -4059,7 +4063,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); @@ -4075,7 +4080,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);