Skip to content

Commit 8a34d4e

Browse files
q2venPaolo Abeni
authored andcommitted
af_unix: Annotate data-races around sk->sk_state in sendmsg() and recvmsg().
The following functions read sk->sk_state locklessly and proceed only if the state is TCP_ESTABLISHED. * unix_stream_sendmsg * unix_stream_read_generic * unix_seqpacket_sendmsg * unix_seqpacket_recvmsg Let's use READ_ONCE() there. Fixes: a05d2ad ("af_unix: Only allow recv on connected seqpacket sockets.") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 1b53694 commit 8a34d4e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/unix/af_unix.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
22262226
}
22272227

22282228
if (msg->msg_namelen) {
2229-
err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
2229+
err = READ_ONCE(sk->sk_state) == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
22302230
goto out_err;
22312231
} else {
22322232
err = -ENOTCONN;
@@ -2340,7 +2340,7 @@ static int unix_seqpacket_sendmsg(struct socket *sock, struct msghdr *msg,
23402340
if (err)
23412341
return err;
23422342

2343-
if (sk->sk_state != TCP_ESTABLISHED)
2343+
if (READ_ONCE(sk->sk_state) != TCP_ESTABLISHED)
23442344
return -ENOTCONN;
23452345

23462346
if (msg->msg_namelen)
@@ -2354,7 +2354,7 @@ static int unix_seqpacket_recvmsg(struct socket *sock, struct msghdr *msg,
23542354
{
23552355
struct sock *sk = sock->sk;
23562356

2357-
if (sk->sk_state != TCP_ESTABLISHED)
2357+
if (READ_ONCE(sk->sk_state) != TCP_ESTABLISHED)
23582358
return -ENOTCONN;
23592359

23602360
return unix_dgram_recvmsg(sock, msg, size, flags);
@@ -2683,7 +2683,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
26832683
size_t size = state->size;
26842684
unsigned int last_len;
26852685

2686-
if (unlikely(sk->sk_state != TCP_ESTABLISHED)) {
2686+
if (unlikely(READ_ONCE(sk->sk_state) != TCP_ESTABLISHED)) {
26872687
err = -EINVAL;
26882688
goto out;
26892689
}

0 commit comments

Comments
 (0)