lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEf4Bzb-Lwud0L-LKP+xcu47BH-D_BSTnduW1nArirf5yjF-Gw@mail.gmail.com>
Date:   Fri, 30 Jul 2021 12:45:29 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     John Fastabend <john.fastabend@...il.com>
Cc:     Jakub Sitnicki <jakub@...udflare.com>,
        Cong Wang <xiyou.wangcong@...il.com>,
        Networking <netdev@...r.kernel.org>,
        Cong Wang <cong.wang@...edance.com>,
        Eric Dumazet <eric.dumazet@...il.com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Lorenz Bauer <lmb@...udflare.com>
Subject: Re: [Patch bpf-next] unix_bpf: fix a potential deadlock in unix_dgram_bpf_recvmsg()

On Wed, Jul 28, 2021 at 11:53 AM John Fastabend
<john.fastabend@...il.com> wrote:
>
> Jakub Sitnicki wrote:
> > On Fri, Jul 23, 2021 at 08:36 PM CEST, Cong Wang wrote:
> > > From: Cong Wang <cong.wang@...edance.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@...il.com>
> > > Cc: John Fastabend <john.fastabend@...il.com>
> > > Cc: Daniel Borkmann <daniel@...earbox.net>
> > > Cc: Jakub Sitnicki <jakub@...udflare.com>
> > > Cc: Lorenz Bauer <lmb@...udflare.com>
> > > Signed-off-by: Cong Wang <cong.wang@...edance.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@...udflare.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@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ