af_unix: Annotate data-race of sk->sk_state in unix_stream_connect().
[ Upstream commit a9bf9c7dc6a5899c01cb8f6e773a66315a5cd4b7 ]
As small optimisation, unix_stream_connect() prefetches the client's
sk->sk_state without unix_state_lock() and checks if it's TCP_CLOSE.
Later, sk->sk_state is checked again under unix_state_lock().
Let's use READ_ONCE() for the first check and TCP_CLOSE directly for
the second check.
Fixes: 1da177e4c3
("Linux-2.6.12-rc2")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
484e036e1a
commit
3d25de6486
|
@ -1491,7 +1491,6 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
|
||||||
struct sk_buff *skb = NULL;
|
struct sk_buff *skb = NULL;
|
||||||
long timeo;
|
long timeo;
|
||||||
int err;
|
int err;
|
||||||
int st;
|
|
||||||
|
|
||||||
err = unix_validate_addr(sunaddr, addr_len);
|
err = unix_validate_addr(sunaddr, addr_len);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -1577,9 +1576,7 @@ restart:
|
||||||
|
|
||||||
Well, and we have to recheck the state after socket locked.
|
Well, and we have to recheck the state after socket locked.
|
||||||
*/
|
*/
|
||||||
st = sk->sk_state;
|
switch (READ_ONCE(sk->sk_state)) {
|
||||||
|
|
||||||
switch (st) {
|
|
||||||
case TCP_CLOSE:
|
case TCP_CLOSE:
|
||||||
/* This is ok... continue with connect */
|
/* This is ok... continue with connect */
|
||||||
break;
|
break;
|
||||||
|
@ -1594,7 +1591,7 @@ restart:
|
||||||
|
|
||||||
unix_state_lock_nested(sk, U_LOCK_SECOND);
|
unix_state_lock_nested(sk, U_LOCK_SECOND);
|
||||||
|
|
||||||
if (sk->sk_state != st) {
|
if (sk->sk_state != TCP_CLOSE) {
|
||||||
unix_state_unlock(sk);
|
unix_state_unlock(sk);
|
||||||
unix_state_unlock(other);
|
unix_state_unlock(other);
|
||||||
sock_put(other);
|
sock_put(other);
|
||||||
|
|
Loading…
Reference in New Issue