Skip to content

Commit 8383936

Browse files
q2venSasha Levin
authored andcommitted
af_unix: Annotate data-races around sk->sk_state in sendmsg() and recvmsg().
[ Upstream commit 8a34d4e ] 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: 1da177e ("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>
1 parent 8a35fc7 commit 8383936

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
@@ -2190,7 +2190,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
21902190
}
21912191

21922192
if (msg->msg_namelen) {
2193-
err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
2193+
err = READ_ONCE(sk->sk_state) == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
21942194
goto out_err;
21952195
} else {
21962196
err = -ENOTCONN;
@@ -2402,7 +2402,7 @@ static int unix_seqpacket_sendmsg(struct socket *sock, struct msghdr *msg,
24022402
if (err)
24032403
return err;
24042404

2405-
if (sk->sk_state != TCP_ESTABLISHED)
2405+
if (READ_ONCE(sk->sk_state) != TCP_ESTABLISHED)
24062406
return -ENOTCONN;
24072407

24082408
if (msg->msg_namelen)
@@ -2416,7 +2416,7 @@ static int unix_seqpacket_recvmsg(struct socket *sock, struct msghdr *msg,
24162416
{
24172417
struct sock *sk = sock->sk;
24182418

2419-
if (sk->sk_state != TCP_ESTABLISHED)
2419+
if (READ_ONCE(sk->sk_state) != TCP_ESTABLISHED)
24202420
return -ENOTCONN;
24212421

24222422
return unix_dgram_recvmsg(sock, msg, size, flags);
@@ -2740,7 +2740,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
27402740
size_t size = state->size;
27412741
unsigned int last_len;
27422742

2743-
if (unlikely(sk->sk_state != TCP_ESTABLISHED)) {
2743+
if (unlikely(READ_ONCE(sk->sk_state) != TCP_ESTABLISHED)) {
27442744
err = -EINVAL;
27452745
goto out;
27462746
}

0 commit comments

Comments
 (0)