Skip to content

Commit b0632e5

Browse files
q2venPaolo Abeni
authored andcommitted
af_unix: Annotate data-races around sk->sk_sndbuf.
sk_setsockopt() changes sk->sk_sndbuf under lock_sock(), but it's not used in af_unix.c. Let's use READ_ONCE() to read sk->sk_sndbuf in unix_writable(), unix_dgram_sendmsg(), and unix_stream_sendmsg(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 0aa3be7 commit b0632e5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/unix/af_unix.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static int unix_dgram_peer_wake_me(struct sock *sk, struct sock *other)
533533
static int unix_writable(const struct sock *sk, unsigned char state)
534534
{
535535
return state != TCP_LISTEN &&
536-
(refcount_read(&sk->sk_wmem_alloc) << 2) <= sk->sk_sndbuf;
536+
(refcount_read(&sk->sk_wmem_alloc) << 2) <= READ_ONCE(sk->sk_sndbuf);
537537
}
538538

539539
static void unix_write_space(struct sock *sk)
@@ -1967,7 +1967,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
19671967
}
19681968

19691969
err = -EMSGSIZE;
1970-
if (len > sk->sk_sndbuf - 32)
1970+
if (len > READ_ONCE(sk->sk_sndbuf) - 32)
19711971
goto out;
19721972

19731973
if (len > SKB_MAX_ALLOC) {
@@ -2247,7 +2247,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
22472247
&err, 0);
22482248
} else {
22492249
/* Keep two messages in the pipe so it schedules better */
2250-
size = min_t(int, size, (sk->sk_sndbuf >> 1) - 64);
2250+
size = min_t(int, size, (READ_ONCE(sk->sk_sndbuf) >> 1) - 64);
22512251

22522252
/* allow fallback to order-0 allocations */
22532253
size = min_t(int, size, SKB_MAX_HEAD(0) + UNIX_SKB_FRAGS_SZ);

0 commit comments

Comments
 (0)