From patchwork Mon Oct 24 11:31:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430664wru; Mon, 24 Oct 2022 05:42:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7M4FmUYlK0ckfKVrK2n3cRmBo8CXTvvQCcueaWT34avMk1Kse0NY3LlfCaJub0iscn+2mJ X-Received: by 2002:a63:c5d:0:b0:460:17cc:73a6 with SMTP id 29-20020a630c5d000000b0046017cc73a6mr27920302pgm.332.1666615324403; Mon, 24 Oct 2022 05:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615324; cv=none; d=google.com; s=arc-20160816; b=vMStJdZTiiXiNH0DoMPHxBigVKefRza1fegF0MePxeLOARGFhm08dLv2tfCvxVQTxo tXa67jtG0RF5lZmLWDYbz0h9R0D2U0BeiMhZIihlcWJJSX8506VbDR3YqMyEEad2ho8w Y5jeaEgi3wDR3zihqv2s+gG9d79o7x6aYZrcMFCA/pMQMht/EQuONiVchqdLLfB4dtga uirnYrj7wj0ut0exCipO1FdiW4YGvDzD5kOwuij82qxWzuRdgWEsNlNs4Wn9czooflya u7QSSrPwxYO+bnhTQJMeelx8f9Yv5Pqce5Cl4IZzFRuJRWcK/Goj17uaWERqGGaEwJWX ik/Q== 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=AElZRAF/mqrmbPkJ6h8YQogxyWe59RB1iZ38D/idbhA=; b=phahKvQRjRS87y/HrRhdXFhGDPRppHDl/2lhrGwB41skZ0WnH91THt+c+tqQt5nxvw AxrB4YiQerLXh3ddAhAP5MV+F9moBuOebSomFesQYlY9eXJqGZQGNDNQ0iU3xTrqfSnf VWZElxetptMHPhzyExiIYlC2FnfTMWu/qwsXtnoUu3jR1HCQkNTU4tJUzWRcuxByXlj3 EEwQnsgjVzRPiUsrcFHhIs3+Mop4fBTlPD7S6frILB5q3O3kqy4hqKGKAV1Kj+CQAu0R jGZl7R7ke6ehQKlYaUscHMkBdeeowcyzj+Rj8qs3CkicqKdrYuL+6Cn3TYU4OgkIGPry pTNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mUKyclbA; 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 bu3-20020a056a00410300b0056c0a9e09f0si223466pfb.292.2022.10.24.05.41.47; Mon, 24 Oct 2022 05:42:04 -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=mUKyclbA; 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 S234028AbiJXMce (ORCPT + 99 others); Mon, 24 Oct 2022 08:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233985AbiJXM3J (ORCPT ); Mon, 24 Oct 2022 08:29:09 -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 81A15876A3; Mon, 24 Oct 2022 05:02:45 -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 27626612BF; Mon, 24 Oct 2022 12:02:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EB35C433C1; Mon, 24 Oct 2022 12:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612948; bh=pLN/sFfYUW0NXqW4PeXLNd8RRvah68DsucHrBUN4/EM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mUKyclbA/OQvrja5k3lezGCiXoweJgL3ex0+q3NrIyd4V+zqmwl4mwFD645fL2u9z bWDzOjGuOuTltJq/07dRZ2/nW1hBcsGUNWAf7OKqAlXC97A9wViaFXVVgz+cJ3siZa bE0zvV1wpktRWaZc01GVhPuecW/VvnvwHRTuuSC4= 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.19 179/229] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Mon, 24 Oct 2022 13:31:38 +0200 Message-Id: <20221024113004.886317136@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747572830600863396?= X-GMAIL-MSGID: =?utf-8?q?1747572830600863396?= 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 e25130812cc8..1a6c55441627 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3692,12 +3692,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) @@ -3705,7 +3709,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); @@ -3721,7 +3726,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);