From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
Abhishek Shah <abhishek.shah@columbia.edu>,
"David S . Miller" <davem@davemloft.net>,
Sasha Levin <sashal@kernel.org>,
yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 04/25] tcp: annotate data-race around tcp_md5sig_pool_populated
Date: Sun, 9 Oct 2022 18:24:09 -0400 [thread overview]
Message-ID: <20221009222436.1219411-4-sashal@kernel.org> (raw)
In-Reply-To: <20221009222436.1219411-1-sashal@kernel.org>
From: Eric Dumazet <edumazet@google.com>
[ 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 <abhishek.shah@columbia.edu>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 768a7daab559..73745d9e6dda 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3690,12 +3690,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)
@@ -3703,7 +3707,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);
@@ -3719,7 +3724,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
next prev parent reply other threads:[~2022-10-10 0:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-09 22:24 [PATCH AUTOSEL 4.19 01/25] wifi: brcmfmac: fix invalid address access when enabling SCAN log level Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 02/25] openvswitch: Fix double reporting of drops in dropwatch Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 03/25] openvswitch: Fix overreporting " Sasha Levin
2022-10-09 22:24 ` Sasha Levin [this message]
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 05/25] wifi: ath9k: avoid uninit memory read in ath9k_htc_rx_msg() Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 06/25] xfrm: Update ipcomp_scratches with NULL when freed Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 07/25] net: xscale: Fix return type for implementation of ndo_start_xmit Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 08/25] net: lantiq_etop: " Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 09/25] net: ftmac100: fix endianness-related issues from 'sparse' Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 10/25] wifi: brcmfmac: fix use-after-free bug in brcmf_netdev_start_xmit() Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 11/25] Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create() Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 12/25] net: davicom: Fix return type of dm9000_start_xmit Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 13/25] net: ethernet: ti: davinci_emac: Fix return type of emac_dev_xmit Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 14/25] net: korina: Fix return type of korina_send_packet Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 15/25] Bluetooth: hci_sysfs: Fix attempting to call device_add multiple times Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 16/25] wifi: ath10k: reset pointer after memory free to avoid potential use-after-free Sasha Levin
2022-10-18 9:53 ` Pavel Machek
2022-10-18 11:10 ` Greg KH
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 17/25] can: bcm: check the result of can_send() in bcm_can_tx() Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 18/25] wifi: rt2x00: don't run Rt5592 IQ calibration on MT7620 Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 19/25] wifi: rt2x00: set correct TX_SW_CFG1 MAC register for MT7620 Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 20/25] wifi: rt2x00: set SoC wmac clock register Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 21/25] wifi: rt2x00: correctly set BBP register 86 for MT7620 Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 22/25] net: If sock is dead don't access sock's sk_wq in sk_stream_wait_memory Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 23/25] Bluetooth: L2CAP: Fix user-after-free Sasha Levin
2022-10-09 22:24 ` [PATCH AUTOSEL 4.19 25/25] r8152: Rate limit overflow messages Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221009222436.1219411-4-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=abhishek.shah@columbia.edu \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).