Message ID | 20210610142737.1350210-1-eric.dumazet@gmail.com |
---|---|
State | New |
Headers | show |
Series | [net] net: annotate data race in sock_error() | expand |
Hello: This patch was applied to netdev/net.git (refs/heads/master): On Thu, 10 Jun 2021 07:27:37 -0700 you wrote: > From: Eric Dumazet <edumazet@google.com> > > sock_error() is known to be racy. The code avoids > an atomic operation is sk_err is zero, and this field > could be changed under us, this is fine. > > Sysbot reported: > > [...] Here is the summary with links: - [net] net: annotate data race in sock_error() https://git.kernel.org/netdev/net/c/f13ef10059cc You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
diff --git a/include/net/sock.h b/include/net/sock.h index 0e962d8bc73b1ce5a38ca1f64c6489f94ab587e4..2fc513aa114c0f4bd7554ca08655d0daf63f4544 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2266,8 +2266,13 @@ struct sk_buff *sock_dequeue_err_skb(struct sock *sk); static inline int sock_error(struct sock *sk) { int err; - if (likely(!sk->sk_err)) + + /* Avoid an atomic operation for the common case. + * This is racy since another cpu/thread can change sk_err under us. + */ + if (likely(data_race(!sk->sk_err))) return 0; + err = xchg(&sk->sk_err, 0); return -err; }