Skip to content

Commit 2861f09

Browse files
committed
Merge branch 'af_unix-data-races'
Kuniyuki Iwashima says: ==================== af_unix: Fix four data-races. While running syzkaller, KCSAN reported 3 data-races with systemd-coredump using AF_UNIX sockets. This series fixes the three and another one inspiered by one of the reports. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 718e6b5 + b192812 commit 2861f09

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

net/core/sock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,9 +2747,9 @@ static long sock_wait_for_wmem(struct sock *sk, long timeo)
27472747
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
27482748
if (refcount_read(&sk->sk_wmem_alloc) < READ_ONCE(sk->sk_sndbuf))
27492749
break;
2750-
if (sk->sk_shutdown & SEND_SHUTDOWN)
2750+
if (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN)
27512751
break;
2752-
if (sk->sk_err)
2752+
if (READ_ONCE(sk->sk_err))
27532753
break;
27542754
timeo = schedule_timeout(timeo);
27552755
}
@@ -2777,7 +2777,7 @@ struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
27772777
goto failure;
27782778

27792779
err = -EPIPE;
2780-
if (sk->sk_shutdown & SEND_SHUTDOWN)
2780+
if (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN)
27812781
goto failure;
27822782

27832783
if (sk_wmem_alloc_get(sk) < READ_ONCE(sk->sk_sndbuf))

net/unix/af_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
680680
* What the above comment does talk about? --ANK(980817)
681681
*/
682682

683-
if (unix_tot_inflight)
683+
if (READ_ONCE(unix_tot_inflight))
684684
unix_gc(); /* Garbage collect fds */
685685
}
686686

net/unix/scm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void unix_inflight(struct user_struct *user, struct file *fp)
6464
/* Paired with READ_ONCE() in wait_for_unix_gc() */
6565
WRITE_ONCE(unix_tot_inflight, unix_tot_inflight + 1);
6666
}
67-
user->unix_inflight++;
67+
WRITE_ONCE(user->unix_inflight, user->unix_inflight + 1);
6868
spin_unlock(&unix_gc_lock);
6969
}
7070

@@ -85,7 +85,7 @@ void unix_notinflight(struct user_struct *user, struct file *fp)
8585
/* Paired with READ_ONCE() in wait_for_unix_gc() */
8686
WRITE_ONCE(unix_tot_inflight, unix_tot_inflight - 1);
8787
}
88-
user->unix_inflight--;
88+
WRITE_ONCE(user->unix_inflight, user->unix_inflight - 1);
8989
spin_unlock(&unix_gc_lock);
9090
}
9191

@@ -99,7 +99,7 @@ static inline bool too_many_unix_fds(struct task_struct *p)
9999
{
100100
struct user_struct *user = current_user();
101101

102-
if (unlikely(user->unix_inflight > task_rlimit(p, RLIMIT_NOFILE)))
102+
if (unlikely(READ_ONCE(user->unix_inflight) > task_rlimit(p, RLIMIT_NOFILE)))
103103
return !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN);
104104
return false;
105105
}

0 commit comments

Comments
 (0)