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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM6JnLe=ZoHrpX8_i=_s5P-Q4h=mZxU=RN5pQuHbxq8pdZhYRQ@mail.gmail.com>
Date:   Tue, 4 May 2021 19:01:01 +0300
From:   Or Cohen <orcohen@...oaltonetworks.com>
To:     Leon Romanovsky <leon@...nel.org>
Cc:     netdev@...r.kernel.org, davem@...emloft.net, kuba@...nel.org,
        Xiaoming Ni <nixiaoming@...wei.com>,
        matthieu.baerts@...sares.net, mkl@...gutronix.de,
        Nadav Markus <nmarkus@...oaltonetworks.com>
Subject: Re: [PATCH] net/nfc: fix use-after-free llcp_sock_bind/connect

Hi, can you please elaborate?

We don't understand why using kref_get_unless_zero will solve the problem.

On Tue, May 4, 2021 at 11:12 AM Leon Romanovsky <leon@...nel.org> wrote:
>
> On Tue, May 04, 2021 at 10:15:25AM +0300, Or Cohen wrote:
> > Commits 8a4cd82d ("nfc: fix refcount leak in llcp_sock_connect()")
> > and c33b1cc62 ("nfc: fix refcount leak in llcp_sock_bind()")
> > fixed a refcount leak bug in bind/connect but introduced a
> > use-after-free if the same local is assigned to 2 different sockets.
> >
> > This can be triggered by the following simple program:
> >     int sock1 = socket( AF_NFC, SOCK_STREAM, NFC_SOCKPROTO_LLCP );
> >     int sock2 = socket( AF_NFC, SOCK_STREAM, NFC_SOCKPROTO_LLCP );
> >     memset( &addr, 0, sizeof(struct sockaddr_nfc_llcp) );
> >     addr.sa_family = AF_NFC;
> >     addr.nfc_protocol = NFC_PROTO_NFC_DEP;
> >     bind( sock1, (struct sockaddr*) &addr, sizeof(struct sockaddr_nfc_llcp) )
> >     bind( sock2, (struct sockaddr*) &addr, sizeof(struct sockaddr_nfc_llcp) )
> >     close(sock1);
> >     close(sock2);
> >
> > Fix this by assigning NULL to llcp_sock->local after calling
> > nfc_llcp_local_put.
> >
> > This addresses CVE-2021-23134.
> >
> > Reported-by: Or Cohen <orcohen@...oaltonetworks.com>
> > Reported-by: Nadav Markus <nmarkus@...oaltonetworks.com>
> > Fixes: c33b1cc62 ("nfc: fix refcount leak in llcp_sock_bind()")
> > Signed-off-by: Or Cohen <orcohen@...oaltonetworks.com>
> > ---
> >
> >  net/nfc/llcp_sock.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
> > index a3b46f888803..53dbe733f998 100644
> > --- a/net/nfc/llcp_sock.c
> > +++ b/net/nfc/llcp_sock.c
> > @@ -109,12 +109,14 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
> >                                         GFP_KERNEL);
> >       if (!llcp_sock->service_name) {
> >               nfc_llcp_local_put(llcp_sock->local);
> > +             llcp_sock->local = NULL;
>
> This "_put() -> set to NULL" pattern can't be correct.
>
> You need to fix nfc_llcp_local_get() to use kref_get_unless_zero()
> and prevent any direct use of llcp_sock->local without taking kref
> first. The nfc_llcp_local_put() isn't right either.
>
> Thanks

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ