All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net/packet: annotate data race in packet_sendmsg()
@ 2021-06-10 16:00 Eric Dumazet
  2021-06-10 21:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2021-06-10 16:00 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski; +Cc: netdev, Eric Dumazet, Eric Dumazet

From: Eric Dumazet <edumazet@google.com>

There is a known race in packet_sendmsg(), addressed
in commit 32d3182cd2cd ("net/packet: fix race in tpacket_snd()")

Now we have data_race(), we can use it to avoid a future KCSAN warning,
as syzbot loves stressing af_packet sockets :)

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/packet/af_packet.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index ae906eb4b269e858434828a383491e8d4c33c422..74e6e45a8e8435a556ce813c410a1f4146dd05b6 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3034,10 +3034,13 @@ static int packet_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 	struct sock *sk = sock->sk;
 	struct packet_sock *po = pkt_sk(sk);
 
-	if (po->tx_ring.pg_vec)
+	/* Reading tx_ring.pg_vec without holding pg_vec_lock is racy.
+	 * tpacket_snd() will redo the check safely.
+	 */
+	if (data_race(po->tx_ring.pg_vec))
 		return tpacket_snd(po, msg);
-	else
-		return packet_snd(sock, msg, len);
+
+	return packet_snd(sock, msg, len);
 }
 
 /*
-- 
2.32.0.rc1.229.g3e70b5a671-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net/packet: annotate data race in packet_sendmsg()
  2021-06-10 16:00 [PATCH net] net/packet: annotate data race in packet_sendmsg() Eric Dumazet
@ 2021-06-10 21:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-10 21:50 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, netdev, edumazet

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Thu, 10 Jun 2021 09:00:12 -0700 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> There is a known race in packet_sendmsg(), addressed
> in commit 32d3182cd2cd ("net/packet: fix race in tpacket_snd()")
> 
> Now we have data_race(), we can use it to avoid a future KCSAN warning,
> as syzbot loves stressing af_packet sockets :)
> 
> [...]

Here is the summary with links:
  - [net] net/packet: annotate data race in packet_sendmsg()
    https://git.kernel.org/netdev/net/c/d1b5bee4c8be

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-10 21:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 16:00 [PATCH net] net/packet: annotate data race in packet_sendmsg() Eric Dumazet
2021-06-10 21:50 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.