summaryrefslogtreecommitdiff
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-12-22 23:47:14 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-12-22 23:49:37 -0500
commit3d02c2fdf870288589fe08d29e1255584f0d796e (patch)
tree45f52f6da4efb4c6a4c7a9cae5597d4bd83a0929 /net/unix/af_unix.c
parentc86373faa01918197f4996eb155e188a0ab5b58b (diff)
af_unix: convert to lock_cmp_fnlockdep_cmp_fn
It turns out there's a deadlock in this code that lockdep couldn't detect because of incorrect use of nested locking. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 1587cfe0f881..1a0d273799c1 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -997,6 +997,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,
u->path.dentry = NULL;
u->path.mnt = NULL;
spin_lock_init(&u->lock);
+ lock_set_cmp_fn_ptr_order(&u->lock);
atomic_long_set(&u->inflight, 0);
INIT_LIST_HEAD(&u->link);
mutex_init(&u->iolock); /* single task reading lock */
@@ -1340,17 +1341,11 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
static void unix_state_double_lock(struct sock *sk1, struct sock *sk2)
{
- if (unlikely(sk1 == sk2) || !sk2) {
- unix_state_lock(sk1);
- return;
- }
- if (sk1 < sk2) {
+ if (sk1 > sk2)
+ swap(sk1, sk2);
+ if (sk1 && sk1 != sk2)
unix_state_lock(sk1);
- unix_state_lock_nested(sk2);
- } else {
- unix_state_lock(sk2);
- unix_state_lock_nested(sk1);
- }
+ unix_state_lock(sk2);
}
static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2)
@@ -1591,7 +1586,7 @@ restart:
goto out_unlock;
}
- unix_state_lock_nested(sk);
+ unix_state_lock(sk);
if (sk->sk_state != st) {
unix_state_unlock(sk);