From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Networking <netdev@vger.kernel.org>,
Cong Wang <cong.wang@bytedance.com>,
Eric Dumazet <eric.dumazet@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Lorenz Bauer <lmb@cloudflare.com>
Subject: Re: [Patch bpf-next] unix_bpf: fix a potential deadlock in unix_dgram_bpf_recvmsg()
Date: Fri, 30 Jul 2021 12:45:29 -0700 [thread overview]
Message-ID: <CAEf4Bzb-Lwud0L-LKP+xcu47BH-D_BSTnduW1nArirf5yjF-Gw@mail.gmail.com> (raw)
In-Reply-To: <6101a77ca9c1_1e1ff620822@john-XPS-13-9370.notmuch>
On Wed, Jul 28, 2021 at 11:53 AM John Fastabend
<john.fastabend@gmail.com> wrote:
>
> Jakub Sitnicki wrote:
> > On Fri, Jul 23, 2021 at 08:36 PM CEST, Cong Wang wrote:
> > > From: Cong Wang <cong.wang@bytedance.com>
> > >
> > > As Eric noticed, __unix_dgram_recvmsg() may acquire u->iolock
> > > too, so we have to release it before calling this function.
> > >
> > > Fixes: 9825d866ce0d ("af_unix: Implement unix_dgram_bpf_recvmsg()")
> > > Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
> > > Cc: John Fastabend <john.fastabend@gmail.com>
> > > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > > Cc: Jakub Sitnicki <jakub@cloudflare.com>
> > > Cc: Lorenz Bauer <lmb@cloudflare.com>
> > > Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> > > ---
> > > net/unix/unix_bpf.c | 11 ++++++-----
> > > 1 file changed, 6 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
> > > index db0cda29fb2f..b07cb30e87b1 100644
> > > --- a/net/unix/unix_bpf.c
> > > +++ b/net/unix/unix_bpf.c
> > > @@ -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:
> > > @@ -68,13 +69,13 @@ 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;
> >
> > Nit: Can be just `return copied`. `ret` became useless.
> >
> > Acked-by: Jakub Sitnicki <jakub@cloudflare.com>
>
> Worth doing the small cleanup pointed out by Jakub but feel free to add
> my ack.
>
I cleaned it up while applying. Applied to bpf-next, thanks.
> Acked-by: John Fastabend <john.fastabend@gmail.com>
prev parent reply other threads:[~2021-07-30 19:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-23 18:36 [Patch bpf-next] unix_bpf: fix a potential deadlock in unix_dgram_bpf_recvmsg() Cong Wang
2021-07-27 16:12 ` John Fastabend
2021-07-28 3:06 ` Cong Wang
2021-07-28 10:12 ` Jakub Sitnicki
2021-07-28 18:52 ` John Fastabend
2021-07-30 19:45 ` Andrii Nakryiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAEf4Bzb-Lwud0L-LKP+xcu47BH-D_BSTnduW1nArirf5yjF-Gw@mail.gmail.com \
--to=andrii.nakryiko@gmail.com \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=eric.dumazet@gmail.com \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).