From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C091C433FE for ; Sun, 9 Oct 2022 22:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233526AbiJIWuN (ORCPT ); Sun, 9 Oct 2022 18:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbiJIWs4 (ORCPT ); Sun, 9 Oct 2022 18:48:56 -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 BF3BC1F9E0; Sun, 9 Oct 2022 15:25:03 -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 66DCF60AF2; Sun, 9 Oct 2022 22:23:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF8ECC433C1; Sun, 9 Oct 2022 22:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665354197; bh=eB2krCByIRXlVoeM9tlYM3tU18tSgoudcwjHSWX9pPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u/tHZF1YRvCl+z+DdN4p7sUBIYqnSNJZhjn1nrDk0QP7yx2TG/EsrAfhbtZCs1HZc BnGhkONcx0df44q4T2KGIUgw01lQvJjUJHhtv+eVv1y1HsxHVAUSw3yutQ1YzwRUoG XQ1BmnT+EW59RfPALrEjcXehNRhR8fHsuMC0ScRW4xserSYmCCUGsaMiKX6T3pGqaw D67XdvH9MRPW38G59sx83tt6vCLZ5QWsr7qdv9ic6raJby/zuQQkXWv9W7Fe206n5x QFPFJXtJnWiw29mxLj60IHukF6aKnXI+twfWUDkhylgaC3L4zYR4RZIePQ3PIIhmal F/MiosPx0bdOQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , Abhishek Shah , "David S . Miller" , Sasha Levin , yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 06/29] tcp: annotate data-race around tcp_md5sig_pool_populated Date: Sun, 9 Oct 2022 18:22:41 -0400 Message-Id: <20221009222304.1218873-6-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009222304.1218873-1-sashal@kernel.org> References: <20221009222304.1218873-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 0a570d5d0b38..601bf5ee59bc 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3768,12 +3768,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) { @@ -3784,7 +3788,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); @@ -3800,7 +3805,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); -- 2.35.1