Skip to content

Commit

Permalink
unix_bpf: Fix a potential deadlock in unix_dgram_bpf_recvmsg()
Browse files Browse the repository at this point in the history
As Eric noticed, __unix_dgram_recvmsg() may acquire u->iolock
too, so we have to release it before calling this function.

Fixes: 9825d86 ("af_unix: Implement unix_dgram_bpf_recvmsg()")
Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
  • Loading branch information
Cong Wang authored and Andrii Nakryiko committed Jul 30, 2021
1 parent a710eed commit 0b84644
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions net/unix/unix_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int unix_dgram_bpf_recvmsg(struct sock *sk, struct msghdr *msg,
{
struct unix_sock *u = unix_sk(sk);
struct sk_psock *psock;
int copied, ret;
int copied;

psock = sk_psock_get(sk);
if (unlikely(!psock))
Expand All @@ -53,8 +53,9 @@ static int unix_dgram_bpf_recvmsg(struct sock *sk, struct msghdr *msg,
mutex_lock(&u->iolock);
if (!skb_queue_empty(&sk->sk_receive_queue) &&
sk_psock_queue_empty(psock)) {
ret = __unix_dgram_recvmsg(sk, msg, len, flags);
goto out;
mutex_unlock(&u->iolock);
sk_psock_put(sk, psock);
return __unix_dgram_recvmsg(sk, msg, len, flags);
}

msg_bytes_ready:
Expand All @@ -68,16 +69,15 @@ static int unix_dgram_bpf_recvmsg(struct sock *sk, struct msghdr *msg,
if (data) {
if (!sk_psock_queue_empty(psock))
goto msg_bytes_ready;
ret = __unix_dgram_recvmsg(sk, msg, len, flags);
goto out;
mutex_unlock(&u->iolock);
sk_psock_put(sk, psock);
return __unix_dgram_recvmsg(sk, msg, len, flags);
}
copied = -EAGAIN;
}
ret = copied;
out:
mutex_unlock(&u->iolock);
sk_psock_put(sk, psock);
return ret;
return copied;
}

static struct proto *unix_prot_saved __read_mostly;
Expand Down

0 comments on commit 0b84644

Please sign in to comment.