From patchwork Mon Oct 24 11:31:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp641497wru; Mon, 24 Oct 2022 13:35:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OaDzNXw4BbOt5wNKg13mm0Yll0XBFXnNOxx7I1OqFmiWm7tGvBN0IuH8i5818rttlrH2N X-Received: by 2002:a17:902:b907:b0:178:2898:8084 with SMTP id bf7-20020a170902b90700b0017828988084mr34531664plb.140.1666643731455; Mon, 24 Oct 2022 13:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643731; cv=none; d=google.com; s=arc-20160816; b=cYLe4K2Da68J/Li8bqPzXtoRfxVP+cy4h816OFYGXFgLNfxQMq/yQ33aVRlRglols6 tM7OQ7TrWuGX0BXrzrg4g+Y20nAXR+GNwk+wz5VxAQspT+UVGmap3Alid44f0el9U0nE H6se6LgEeI2oFy2stplcY3YEq/7nayWoKH7TKaVi/jDGIffIdbJP12w/n4aszZGKGh3H IdLSDXtyiJAZvw5mzLDJESrQQ5//nUgpoBIz2GEBcn/CRt0P7145Xprggtdp5gJJr35a rWwo/iuslied8xG3AO3OBZhUT6w4QAyBvMRY3VdIvRlbSU9jp/x/HNYU5hqBLo91UM1W ScCw== 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=oOlb2+i1ip6EWjora7aO+9h21b9U++R2vB7ip3QyFdw=; b=TFSWMONpup8BESECLSO+TcHl/ZmXMFlgtJK2h7ewLoTenFz7YmJJek6RYp3QhxUKC3 CchtN781yHAzJpYEDQ07zcOMNi2IZfQUyb/x+Fb/LViMLxQTdb6un38Gp8X4uVdUwQ7j /s71MwmThsmp8iCO5wE7w33tEdt90ntvvk88I8kngZNW3wHZepfymOxS+AVuQgzCN8Ze GxYyOFwWMVjHkDh//BENslSoPPkKYPGOL8/cIidXWvET+GpGyqnQzxoHf/L9AQMdKM1u NcSmoza95V/lE6M7pqtR6JP3gJFRXeNA1Z9dSXRUPjRUNeLhivGF+zMnEkz26QlB8z4K IMCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XRKF8Q06; 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 o11-20020a170903210b00b0018537cc29f9si492029ple.15.2022.10.24.13.35.15; Mon, 24 Oct 2022 13:35:31 -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=XRKF8Q06; 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 S233604AbiJXUZX (ORCPT + 99 others); Mon, 24 Oct 2022 16:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbiJXUXY (ORCPT ); Mon, 24 Oct 2022 16:23:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E217413F48; Mon, 24 Oct 2022 11:38:52 -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 21F1AB810B2; Mon, 24 Oct 2022 12:14:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 733A1C433C1; Mon, 24 Oct 2022 12:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613671; bh=NMLKHiEK9NjSAgTP2LcnDOFgdc0G48TbfOyUUvIGw5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XRKF8Q06Lv++LwgwFal8wutGEFQP4JUAgBftMbCdaZdqZJCoDYUryystFnh75p6CU 6Wq4AaUJGpVyUIgxXJHfOpfuuuIM/TKLhugTssi054x94TJilQNtlrJV5avscacUQr inK8hIZKCDe51xvI9H3uDHpJx466DXNPxbnA4xZo= 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.4 195/255] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Mon, 24 Oct 2022 13:31:45 +0200 Message-Id: <20221024113009.475095136@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747602617169787258?= X-GMAIL-MSGID: =?utf-8?q?1747602617169787258?= 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 2da4f852fc58..aeeeaf2d6482 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3770,12 +3770,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) { @@ -3786,7 +3790,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); @@ -3802,7 +3807,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);