From patchwork Mon Oct 24 11:31:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp403349wru; Mon, 24 Oct 2022 04:51:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zQw8MH70zzgmRKB7e37frDanhDXFqxpre0tK6issBhpOumMJeYCxH8QosfsnDN255n/Lr X-Received: by 2002:a17:90b:60e:b0:212:d5cd:4e58 with SMTP id gb14-20020a17090b060e00b00212d5cd4e58mr18142476pjb.165.1666612316679; Mon, 24 Oct 2022 04:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612316; cv=none; d=google.com; s=arc-20160816; b=J8M9ACdGca4Z1WipVvvc3v7vFGU5xiM4LKv+/nh2QQlkUsHOl3INPEfx72uM3BIHgW 1vi/X4S1vPExxXUIZkk5KLU6X83u+WsQw3bES2XPcNriP9vmAr88gpkoDU8gUcLF5rna CZZmeF3g6/adgDpSlRggxNIlEppL0lUU+II0tJPCYScdYPeafM9uiuYiGD7ZPKNupGdV xn/Cpo8CiVzsPJEcY9V+J1jklg1Z/pTN7e2f5OQxHfdavfrYNQfXdzarjD6Lk/5u/MVn MPCePHNpvvYPMz6YmF/JN/hFI3QsUVoI64oWmHUj20UGD6PAWu2hx4FjUPeUnwvElTfu XG0Q== 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=/PTfo8uAFwIoD1qBHALEl45HRdvuseUEm2tYnYct2Yw=; b=WHQYuhUUiWK47X4FIh8aiA5/yzLsMUE1imBHD2NAvj5GWvZiLsyTKecIatUzXZgdaX G7kyg7isNaRVoUqHHafFfo7hdF5r3BuMz+EIJ9H0TIJsDhDjdZ8hHC5d4RJj3tYQ/01N r+P664bhYke3UKU1/nauHf/S7gg4MgmaCqVg8cDzWKiHjbNQHGBJT5MDGzyXQLtkZ1Fv nZUCSePiD0lASO839baOolXE8SxfJZ2L9PZ5rX9naXrl0nc4fHsVJp4lpYWodthjJQBA +nPo+psuU9a1uA2nLLBWWo0nerFEtRT6OVmBPJ7mQGLH4Uezz6BE4tpjZcaLtpdhv15m N3KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r7IWoNAQ; 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 g1-20020a635641000000b0042b57d7bc14si33765886pgm.763.2022.10.24.04.51.43; Mon, 24 Oct 2022 04:51:56 -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=r7IWoNAQ; 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 S231940AbiJXLvO (ORCPT + 99 others); Mon, 24 Oct 2022 07:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231951AbiJXLtR (ORCPT ); Mon, 24 Oct 2022 07:49:17 -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 299591EEED; Mon, 24 Oct 2022 04:43:56 -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 2FB70B8117A; Mon, 24 Oct 2022 11:43:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82E6EC433D6; Mon, 24 Oct 2022 11:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611833; bh=RwSqqccq5jb87gtkM0ArHecFwhThQMrjqBPPfIKVlKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r7IWoNAQdI61cGbmY6MQbQPtX3z65BstWvaU5qM3UG2ZNS0ActKCh/9fo3xXNqOF8 eFZllitCGzfbnlkV5Ib/h4YElpqFhurgB1Muw8wgVgl43mCPeH6RbRd9+umEDnYeCv ib0ITE+HdRQYH7a5g/D98Nv8X/yr0n/DiFj1CtMk= 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.9 129/159] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Mon, 24 Oct 2022 13:31:23 +0200 Message-Id: <20221024112954.216222112@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569676099243356?= X-GMAIL-MSGID: =?utf-8?q?1747569676099243356?= 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 7a75eb177878..4252aa0b5143 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3131,12 +3131,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) @@ -3144,7 +3148,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); @@ -3160,7 +3165,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);